lkml.org 
[lkml]   [2020]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] drivers/block/zram/zram_drv.c: avoid needless checks in backing_dev_store() failure path
Date
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
\
 
 \ /
  Last update: 2020-02-27 09:14    [W:0.038 / U:1.636 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site