aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2012-08-10 13:12:07 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-17 08:51:18 -0800
commita871375b5548cbcd28c9b97040da7f6470a96a72 (patch)
treed023d8a3ce7956c9fb0ae7b35d056881437e720f /drivers
parent2c130889f540f0bc6bc866d436b2ec3a23ea8f2b (diff)
rbd: drop dev reference on error in rbd_open()
If a read-only rbd device is opened for writing in rbd_open(), it returns without dropping the just-acquired device reference. Fix this by moving the read-only check before getting the reference. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Yehuda Sadeh <yehuda@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com> (cherry picked from commit 340c7a2b2c9a2da640af28a8c196356484ac8b50) Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/rbd.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 52e295defb9..c05a4ab47e5 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -250,13 +250,12 @@ static int rbd_open(struct block_device *bdev, fmode_t mode)
{
struct rbd_device *rbd_dev = bdev->bd_disk->private_data;
- rbd_get_dev(rbd_dev);
-
- set_device_ro(bdev, rbd_dev->read_only);
-
if ((mode & FMODE_WRITE) && rbd_dev->read_only)
return -EROFS;
+ rbd_get_dev(rbd_dev);
+ set_device_ro(bdev, rbd_dev->read_only);
+
return 0;
}