summaryrefslogtreecommitdiff
path: root/fs/block_dev.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-11-27 18:45:27 +0300
committerJens Axboe <axboe@kernel.dk>2020-12-02 00:53:39 +0300
commit3a4174e68684e43ecdcb59126a441b29d5e94f7f (patch)
treea6538a19c9bb3a47297434f2c17da51492ad3565 /fs/block_dev.c
parent612c6aa7817f1c89b6a92fc724331aa7c9d77f6e (diff)
downloadlinux-3a4174e68684e43ecdcb59126a441b29d5e94f7f.tar.xz
block: switch bdgrab to use igrab
All of the current callers already have a reference, but to prepare for additional users ensure bdgrab returns NULL if the block device is being freed. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Jan Kara <jack@suse.cz> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r--fs/block_dev.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c
index d707ab376da8..962fabe8a67b 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -894,10 +894,14 @@ static struct block_device *bdget(dev_t dev)
/**
* bdgrab -- Grab a reference to an already referenced block device
* @bdev: Block device to grab a reference to.
+ *
+ * Returns the block_device with an additional reference when successful,
+ * or NULL if the inode is already beeing freed.
*/
struct block_device *bdgrab(struct block_device *bdev)
{
- ihold(bdev->bd_inode);
+ if (!igrab(bdev->bd_inode))
+ return NULL;
return bdev;
}
EXPORT_SYMBOL(bdgrab);