diff options
author | Rashika Kheria <rashika.kheria@gmail.com> | 2013-10-30 09:06:32 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-30 12:36:53 -0400 |
commit | 46a51c80216cb891f271ad021f59009f34677499 (patch) | |
tree | ad2a3d08f22a598477780baaad4eb6f7ebc38480 /drivers/staging | |
parent | 59d3fe540454dd8fc48d4eda44e200f9c98bef10 (diff) |
Staging: zram: Fix access of NULL pointer
This patch fixes the bug in reset_store caused by accessing NULL pointer.
The bdev gets its value from bdget_disk() which could fail when memory
pressure is severe and hence can return NULL because allocation of
inode in bdget could fail.
Hence, this patch introduces a check for bdev to prevent reference to a
NULL pointer in the later part of the code. It also removes unnecessary
check of bdev for fsync_bdev().
Cc: stable <stable@vger.kernel.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r-- | drivers/staging/zram/zram_drv.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c index b704d06943f5..79ce363b2ea9 100644 --- a/drivers/staging/zram/zram_drv.c +++ b/drivers/staging/zram/zram_drv.c | |||
@@ -648,6 +648,9 @@ static ssize_t reset_store(struct device *dev, | |||
648 | zram = dev_to_zram(dev); | 648 | zram = dev_to_zram(dev); |
649 | bdev = bdget_disk(zram->disk, 0); | 649 | bdev = bdget_disk(zram->disk, 0); |
650 | 650 | ||
651 | if (!bdev) | ||
652 | return -ENOMEM; | ||
653 | |||
651 | /* Do not reset an active device! */ | 654 | /* Do not reset an active device! */ |
652 | if (bdev->bd_holders) | 655 | if (bdev->bd_holders) |
653 | return -EBUSY; | 656 | return -EBUSY; |
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev, | |||
660 | return -EINVAL; | 663 | return -EINVAL; |
661 | 664 | ||
662 | /* Make sure all pending I/O is finished */ | 665 | /* Make sure all pending I/O is finished */ |
663 | if (bdev) | 666 | fsync_bdev(bdev); |
664 | fsync_bdev(bdev); | ||
665 | 667 | ||
666 | zram_reset_device(zram, true); | 668 | zram_reset_device(zram, true); |
667 | return len; | 669 | return len; |