From: Yue Hu <zbestahu@gmail.com>
To: minchan@kernel.org, ngupta@vflare.org,
sergey.senozhatsky.work@gmail.com, axboe@kernel.dk
Cc: linux-kernel@vger.kernel.org, huyue2@yulong.com, zbestahu@163.com
Subject: [PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path
Date: Thu, 27 Feb 2020 16:12:19 +0800 [thread overview]
Message-ID: <20200227081219.13144-1-zbestahu@gmail.com> (raw)
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
next reply other threads:[~2020-02-27 8:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-27 8:12 Yue Hu [this message]
2020-02-27 8:18 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200227081219.13144-1-zbestahu@gmail.com \
--to=zbestahu@gmail.com \
--cc=axboe@kernel.dk \
--cc=huyue2@yulong.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=zbestahu@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®