aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRashika Kheria <rashika.kheria@gmail.com>2013-11-10 11:43:53 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-25 12:14:29 -0500
commit1b672224d128ec2570eb37572ff803cfe452b4f7 (patch)
treecf4923cb1f19856ee8e70f0b1ce9ed0abcaa30c4
parent9df682927c2e3a92f43803d6b52095992e3b2ab8 (diff)
Staging: zram: Fix memory leak by refcount mismatch
As suggested by Minchan Kim and Jerome Marchand "The code in reset_store get the block device (bdget_disk()) but it does not put it (bdput()) when it's done using it. The usage count is therefore incremented but never decremented." This patch also puts bdput() for all error cases. Acked-by: Minchan Kim <minchan@kernel.org> Acked-by: Jerome Marchand <jmarchan@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Rashika Kheria <rashika.kheria@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/zram/zram_drv.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index 79ce363b2ea9..3277d9838f4e 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -652,21 +652,30 @@ static ssize_t reset_store(struct device *dev,
652 return -ENOMEM; 652 return -ENOMEM;
653 653
654 /* Do not reset an active device! */ 654 /* Do not reset an active device! */
655 if (bdev->bd_holders) 655 if (bdev->bd_holders) {
656 return -EBUSY; 656 ret = -EBUSY;
657 goto out;
658 }
657 659
658 ret = kstrtou16(buf, 10, &do_reset); 660 ret = kstrtou16(buf, 10, &do_reset);
659 if (ret) 661 if (ret)
660 return ret; 662 goto out;
661 663
662 if (!do_reset) 664 if (!do_reset) {
663 return -EINVAL; 665 ret = -EINVAL;
666 goto out;
667 }
664 668
665 /* Make sure all pending I/O is finished */ 669 /* Make sure all pending I/O is finished */
666 fsync_bdev(bdev); 670 fsync_bdev(bdev);
671 bdput(bdev);
667 672
668 zram_reset_device(zram, true); 673 zram_reset_device(zram, true);
669 return len; 674 return len;
675
676out:
677 bdput(bdev);
678 return ret;
670} 679}
671 680
672static void __zram_make_request(struct zram *zram, struct bio *bio, int rw) 681static void __zram_make_request(struct zram *zram, struct bio *bio, int rw)