[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200227081219.13144-1-zbestahu@gmail.com>
Date: Thu, 27 Feb 2020 16:12:19 +0800
From: Yue Hu <zbestahu@...il.com>
To: minchan@...nel.org, ngupta@...are.org,
sergey.senozhatsky.work@...il.com, axboe@...nel.dk
Cc: linux-kernel@...r.kernel.org, huyue2@...ong.com, zbestahu@....com
Subject: [PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path
From: Yue Hu <huyue2@...ong.com>
There are null pointer checks in out block if backing_dev_store() fails.
That is needless, we can avoid them by setting different jumping label.
Signed-off-by: Yue Hu <huyue2@...ong.com>
---
drivers/block/zram/zram_drv.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 61b10ab..a896f5c 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -465,7 +465,7 @@ static ssize_t backing_dev_store(struct device *dev,
if (init_done(zram)) {
pr_info("Can't setup backing device for initialized device\n");
err = -EBUSY;
- goto out;
+ goto out_unlock;
}
strlcpy(file_name, buf, PATH_MAX);
@@ -478,7 +478,7 @@ static ssize_t backing_dev_store(struct device *dev,
if (IS_ERR(backing_dev)) {
err = PTR_ERR(backing_dev);
backing_dev = NULL;
- goto out;
+ goto out_unlock;
}
mapping = backing_dev->f_mapping;
@@ -487,14 +487,14 @@ static ssize_t backing_dev_store(struct device *dev,
/* Support only block device in this moment */
if (!S_ISBLK(inode->i_mode)) {
err = -ENOTBLK;
- goto out;
+ goto out_fclose;
}
bdev = bdgrab(I_BDEV(inode));
err = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram);
if (err < 0) {
bdev = NULL;
- goto out;
+ goto out_fclose;
}
nr_pages = i_size_read(inode) >> PAGE_SHIFT;
@@ -502,13 +502,13 @@ static ssize_t backing_dev_store(struct device *dev,
bitmap = kvzalloc(bitmap_sz, GFP_KERNEL);
if (!bitmap) {
err = -ENOMEM;
- goto out;
+ goto out_blkdev_put;
}
old_block_size = block_size(bdev);
err = set_blocksize(bdev, PAGE_SIZE);
if (err)
- goto out;
+ goto out_free_bitmap;
reset_bdev(zram);
@@ -535,16 +535,14 @@ static ssize_t backing_dev_store(struct device *dev,
kfree(file_name);
return len;
-out:
- if (bitmap)
- kvfree(bitmap);
-
- if (bdev)
- blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
-
- if (backing_dev)
- filp_close(backing_dev, NULL);
+out_free_bitmap:
+ kvfree(bitmap);
+out_blkdev_put:
+ blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL);
+out_fclose:
+ filp_close(backing_dev, NULL);
+out_unlock:
up_write(&zram->init_lock);
kfree(file_name);
--
1.9.1
Powered by blists - more mailing lists