aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2016-12-05 00:40:50 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-12 05:39:35 -0500
commit5cc85ef4ffe6c3f1d35b75975c5731248c5af4a7 (patch)
treef3af49785da96504d22cedc42688cdaecdbc53af /drivers/md
parent60a931c20d1a401b79ff742142225c300d545af0 (diff)
md: fix refcount problem on mddev when stopping array.
commit e2342ca832726a840ca6bd196dd2cc073815b08a 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 af8d8e6f0. 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: Marc Smith <marc.smith@mcc.edu> Fixes: af8d8e6f0315 ("md: changes for MD_STILL_CLOSED flag") Signed-off-by: NeilBrown <neilb@suse.com> Acked-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/md.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 1a9131b6594c..24925f2aa235 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7092,7 +7092,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
7092 7092
7093 if (test_bit(MD_CLOSING, &mddev->flags)) { 7093 if (test_bit(MD_CLOSING, &mddev->flags)) {
7094 mutex_unlock(&mddev->open_mutex); 7094 mutex_unlock(&mddev->open_mutex);
7095 return -ENODEV; 7095 err = -ENODEV;
7096 goto out;
7096 } 7097 }
7097 7098
7098 err = 0; 7099 err = 0;
@@ -7101,6 +7102,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
7101 7102
7102 check_disk_change(bdev); 7103 check_disk_change(bdev);
7103 out: 7104 out:
7105 if (err)
7106 mddev_put(mddev);
7104 return err; 7107 return err;
7105} 7108}
7106 7109