Commit 5cc85ef4 authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman

md: fix refcount problem on mddev when stopping array.

commit e2342ca8 upstream.

md_open() gets a counted reference on an mddev using mddev_find().
If it ends up returning an error, it must drop this reference.

There are two error paths where the reference is not dropped.
One only happens if the process is signalled and an awkward time,
which is quite unlikely.
The other was introduced recently in commit af8d8e6f.

Change the code to ensure the drop the reference when returning an error,
and make it harded to re-introduce this sort of bug in the future.
Reported-by: default avatarMarc Smith <marc.smith@mcc.edu>
Fixes: af8d8e6f ("md: changes for MD_STILL_CLOSED flag")
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Acked-by: default avatarGuoqing Jiang <gqjiang@suse.com>
Signed-off-by: default avatarShaohua Li <shli@fb.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 60a931c2
...@@ -7092,7 +7092,8 @@ static int md_open(struct block_device *bdev, fmode_t mode) ...@@ -7092,7 +7092,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
if (test_bit(MD_CLOSING, &mddev->flags)) { if (test_bit(MD_CLOSING, &mddev->flags)) {
mutex_unlock(&mddev->open_mutex); mutex_unlock(&mddev->open_mutex);
return -ENODEV; err = -ENODEV;
goto out;
} }
err = 0; err = 0;
...@@ -7101,6 +7102,8 @@ static int md_open(struct block_device *bdev, fmode_t mode) ...@@ -7101,6 +7102,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
check_disk_change(bdev); check_disk_change(bdev);
out: out:
if (err)
mddev_put(mddev);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment