diff options
author | Christoph Hellwig <hch@lst.de> | 2021-08-23 09:33:59 +0200 |
---|---|---|
committer | Miquel Raynal <miquel.raynal@bootlin.com> | 2021-08-23 10:01:16 +0200 |
commit | ee28b42006c37aaeb68c83300fe5608db662082f (patch) | |
tree | 49c4d2b61e35efb59e6e85a4b2431bfd4f511e4b /drivers/mtd/mtd_blkdevs.c | |
parent | 37b143d12b5f099bb4375162303ff1df1692cc5e (diff) | |
download | linux-ee28b42006c37aaeb68c83300fe5608db662082f.tar.gz linux-ee28b42006c37aaeb68c83300fe5608db662082f.tar.bz2 linux-ee28b42006c37aaeb68c83300fe5608db662082f.zip |
mtd_blkdevs: simplify the refcounting in blktrans_{open, release}
Always grab a reference to the mtd_blktrans_dev in ->open instead of
just on the first open, and do away with the additional temporary
references in ->open and ->release.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210823073359.705281-9-hch@lst.de
Diffstat (limited to 'drivers/mtd/mtd_blkdevs.c')
-rw-r--r-- | drivers/mtd/mtd_blkdevs.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index e8eb4d801b15..12c1803284c7 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -36,14 +36,6 @@ static void blktrans_dev_release(struct kref *kref) kfree(dev); } -static struct mtd_blktrans_dev *blktrans_dev_get(struct gendisk *disk) -{ - struct mtd_blktrans_dev *dev = disk->private_data; - - kref_get(&dev->ref); - return dev; -} - static void blktrans_dev_put(struct mtd_blktrans_dev *dev) { kref_put(&dev->ref, blktrans_dev_release); @@ -191,15 +183,16 @@ static blk_status_t mtd_queue_rq(struct blk_mq_hw_ctx *hctx, static int blktrans_open(struct block_device *bdev, fmode_t mode) { - struct mtd_blktrans_dev *dev = blktrans_dev_get(bdev->bd_disk); + struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data; int ret = 0; + kref_get(&dev->ref); + mutex_lock(&dev->lock); if (dev->open) goto unlock; - kref_get(&dev->ref); __module_get(dev->tr->owner); if (!dev->mtd) @@ -219,7 +212,6 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) unlock: dev->open++; mutex_unlock(&dev->lock); - blktrans_dev_put(dev); return ret; error_release: @@ -227,7 +219,6 @@ error_release: dev->tr->release(dev); error_put: module_put(dev->tr->owner); - kref_put(&dev->ref, blktrans_dev_release); mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; @@ -235,14 +226,13 @@ error_put: static void blktrans_release(struct gendisk *disk, fmode_t mode) { - struct mtd_blktrans_dev *dev = blktrans_dev_get(disk); + struct mtd_blktrans_dev *dev = disk->private_data; mutex_lock(&dev->lock); if (--dev->open) goto unlock; - kref_put(&dev->ref, blktrans_dev_release); module_put(dev->tr->owner); if (dev->mtd) { |