From 3a4174e68684e43ecdcb59126a441b29d5e94f7f Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Fri, 27 Nov 2020 16:45:27 +0100 Subject: 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 Reviewed-by: Jan Kara Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn Signed-off-by: Jens Axboe --- fs/block_dev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'fs/block_dev.c') 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); -- cgit v1.2.3