In previous patch a new put_gendisk() call was introduced, which puts the
disk and the disk owner module references.

This new call should help not to forget about required module_put() after
receiving a disk pointer using get_disk() or get_gendisk() calls.

In this patch disk_put(),module_put() sequences are replaced with a single
put_gendisk() call.

Signed-off-by: Roman Pen <[email protected]>
Cc: Gi-Oh Kim <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
 block/blk-cgroup.c | 15 +++------------
 fs/block_dev.c     | 24 +++++++-----------------
 2 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 66e6f1a..2ed9636 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -788,7 +788,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct 
blkcg_policy *pol,
 {
        struct gendisk *disk;
        struct blkcg_gq *blkg;
-       struct module *owner;
        unsigned int major, minor;
        int key_len, part, ret;
        char *body;
@@ -805,9 +804,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct 
blkcg_policy *pol,
        if (!disk)
                return -ENODEV;
        if (part) {
-               owner = disk->fops->owner;
-               put_disk(disk);
-               module_put(owner);
+               put_gendisk(disk);
                return -ENODEV;
        }
 
@@ -823,9 +820,7 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct 
blkcg_policy *pol,
                ret = PTR_ERR(blkg);
                rcu_read_unlock();
                spin_unlock_irq(disk->queue->queue_lock);
-               owner = disk->fops->owner;
-               put_disk(disk);
-               module_put(owner);
+               put_gendisk(disk);
                /*
                 * If queue was bypassing, we should retry.  Do so after a
                 * short msleep().  It isn't strictly necessary but queue
@@ -856,13 +851,9 @@ EXPORT_SYMBOL_GPL(blkg_conf_prep);
 void blkg_conf_finish(struct blkg_conf_ctx *ctx)
        __releases(ctx->disk->queue->queue_lock) __releases(rcu)
 {
-       struct module *owner;
-
        spin_unlock_irq(ctx->disk->queue->queue_lock);
        rcu_read_unlock();
-       owner = ctx->disk->fops->owner;
-       put_disk(ctx->disk);
-       module_put(owner);
+       put_gendisk(ctx->disk);
 }
 EXPORT_SYMBOL_GPL(blkg_conf_finish);
 
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 7b9cd49..dc2ea76 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -15,7 +15,6 @@
 #include <linux/highmem.h>
 #include <linux/blkdev.h>
 #include <linux/backing-dev.h>
-#include <linux/module.h>
 #include <linux/blkpg.h>
 #include <linux/magic.h>
 #include <linux/buffer_head.h>
@@ -870,8 +869,7 @@ static struct block_device *bd_start_claiming(struct 
block_device *bdev,
        else
                whole = bdgrab(bdev);
 
-       module_put(disk->fops->owner);
-       put_disk(disk);
+       put_gendisk(disk);
        if (!whole)
                return ERR_PTR(-ENOMEM);
 
@@ -1167,7 +1165,6 @@ static void __blkdev_put(struct block_device *bdev, 
fmode_t mode, int for_part);
 static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 {
        struct gendisk *disk;
-       struct module *owner;
        int ret;
        int partno;
        int perm = 0;
@@ -1193,7 +1190,6 @@ static int __blkdev_get(struct block_device *bdev, 
fmode_t mode, int for_part)
        disk = get_gendisk(bdev->bd_dev, &partno);
        if (!disk)
                goto out;
-       owner = disk->fops->owner;
 
        disk_block_events(disk);
        mutex_lock_nested(&bdev->bd_mutex, for_part);
@@ -1222,8 +1218,7 @@ static int __blkdev_get(struct block_device *bdev, 
fmode_t mode, int for_part)
                                        bdev->bd_queue = NULL;
                                        mutex_unlock(&bdev->bd_mutex);
                                        disk_unblock_events(disk);
-                                       put_disk(disk);
-                                       module_put(owner);
+                                       put_gendisk(disk);
                                        goto restart;
                                }
                        }
@@ -1285,9 +1280,8 @@ static int __blkdev_get(struct block_device *bdev, 
fmode_t mode, int for_part)
                        if (ret)
                                goto out_unlock_bdev;
                }
-               /* only one opener holds refs to the module and disk */
-               put_disk(disk);
-               module_put(owner);
+               /* only one opener holds refs to the disk */
+               put_gendisk(disk);
        }
        bdev->bd_openers++;
        if (for_part)
@@ -1307,8 +1301,7 @@ static int __blkdev_get(struct block_device *bdev, 
fmode_t mode, int for_part)
  out_unlock_bdev:
        mutex_unlock(&bdev->bd_mutex);
        disk_unblock_events(disk);
-       put_disk(disk);
-       module_put(owner);
+       put_gendisk(disk);
  out:
        bdput(bdev);
 
@@ -1525,7 +1518,7 @@ static void __blkdev_put(struct block_device *bdev, 
fmode_t mode, int for_part)
                /*
                 * Detaching bdev inode from its wb in __destroy_inode()
                 * is too late: the queue which embeds its bdi (along with
-                * root wb) can be gone as soon as we put_disk() below.
+                * root wb) can be gone as soon as we put_gendisk() below.
                 */
                inode_detach_wb(bdev->bd_inode);
        }
@@ -1534,8 +1527,6 @@ static void __blkdev_put(struct block_device *bdev, 
fmode_t mode, int for_part)
                        disk->fops->release(disk, mode);
        }
        if (!bdev->bd_openers) {
-               struct module *owner = disk->fops->owner;
-
                disk_put_part(bdev->bd_part);
                bdev->bd_part = NULL;
                bdev->bd_disk = NULL;
@@ -1543,8 +1534,7 @@ static void __blkdev_put(struct block_device *bdev, 
fmode_t mode, int for_part)
                        victim = bdev->bd_contains;
                bdev->bd_contains = NULL;
 
-               put_disk(disk);
-               module_put(owner);
+               put_gendisk(disk);
        }
        mutex_unlock(&bdev->bd_mutex);
        bdput(bdev);
-- 
2.6.2

Reply via email to