Skip to contentSkip to conversation

md: check the return of mddev_find()

PATCH In review Yuanhan Liu 2 participants 2 messages May 15, 2012 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 md: check the return of mddev_find()

Check the return of mddev_find(), since it may fail due to out of memeory or out of usable minor number.

The reason I chose -ENODEV instead of -ENOMEM or something else is md_alloc() function chose that ;)

---
 drivers/md/md.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/md/md.c +3 -0
index 477eb2e..0bd44e3 100644
@@ -6371,6 +6371,9 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 	struct mddev *mddev = mddev_find(bdev->bd_dev);
 	int err;
 
+	if (!mddev)
+		return -ENODEV;
+
 	if (mddev->gendisk != bdev->bd_disk) {
 		/* we are racing with mddev_put which is discarding this
 		 * bd_disk.
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 16 lines · On Tue, 15 May 2012 14:26:40 +0800 Yuanhan Liu <[email protected]>…

Check the return of mddev_find(), since it may fail due to out of memeory or out of usable minor number.

The reason I chose -ENODEV instead of -ENOMEM or something else is md_alloc() function chose that ;)

---
 drivers/md/md.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/md/md.c +0 -0
index 477eb2e..0bd44e3 100644

drivers/md/md.c static int md_open(struct block_device *bdev, fmode_t mode) · line 6379

Quoted 9 lines
drivers/md/md.c +3 -0
@@ -6371,6 +6371,9 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 	struct mddev *mddev = mddev_find(bdev->bd_dev);
 	int err;
 
+	if (!mddev)
+		return -ENODEV;
+
 	if (mddev->gendisk != bdev->bd_disk) {
 		/* we are racing with mddev_put which is discarding this
 		 * bd_disk.

Hi,
thanks for the patch.

I'm fairly sure that we won't actually get to md_open unless md_probe has succeeded and called add_disk, in which case there *must* be a matching mddev.

However it doesn't hurt and looks safer so I have applied it.

Thanks,
NeilBrown