All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path
@ 2020-02-27  8:12 Yue Hu
  2020-02-27  8:18 ` Sergey Senozhatsky
  0 siblings, 1 reply; 2+ messages in thread
From: Yue Hu @ 2020-02-27  8:12 UTC (permalink / raw)
  To: minchan, ngupta, sergey.senozhatsky.work, axboe
  Cc: linux-kernel, huyue2, zbestahu

From: Yue Hu <huyue2@yulong.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@yulong.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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path
  2020-02-27  8:12 [PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path Yue Hu
@ 2020-02-27  8:18 ` Sergey Senozhatsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2020-02-27  8:18 UTC (permalink / raw)
  To: Yue Hu
  Cc: minchan, ngupta, sergey.senozhatsky.work, axboe, linux-kernel,
	huyue2, zbestahu

On (20/02/27 16:12), Yue Hu wrote:
> 
> 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.
> 

Dunno. Numerous error-out labels to jump to (instead of a single one)
don't really look like an improvement to me.

	-ss

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-27  8:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27  8:12 [PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path Yue Hu
2020-02-27  8:18 ` Sergey Senozhatsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.