aboutsummaryrefslogtreecommitdiff
path: root/drivers/staging
diff options
context:
space:
mode:
authorRashika Kheria <rashika.kheria@gmail.com>2013-10-30 18:36:32 +0530
committerAlex Shi <alex.shi@linaro.org>2015-05-11 17:36:38 +0800
commit3c073fe1e7f533e087a8e2faaff31f8b02e6aed9 (patch)
treedf730e8fd4444990a870f42fef1c531a92a40ed5 /drivers/staging
parent922959916229ecc5f143b0fe66a9a8bbf4b55169 (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> (cherry picked from commit 46a51c80216cb891f271ad021f59009f34677499) Signed-off-by: Alex Shi <alex.shi@linaro.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/zram/zram_drv.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index a125cfae6942..206f59d9a7a8 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,
zram = dev_to_zram(dev);
bdev = bdget_disk(zram->disk, 0);
+ if (!bdev)
+ return -ENOMEM;
+
/* Do not reset an active device! */
if (bdev->bd_holders)
return -EBUSY;
@@ -660,8 +663,7 @@ static ssize_t reset_store(struct device *dev,
return -EINVAL;
/* Make sure all pending I/O is finished */
- if (bdev)
- fsync_bdev(bdev);
+ fsync_bdev(bdev);
zram_reset_device(zram, true);
return len;