]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
md: fix refcount problem on mddev when stopping array.
authorNeilBrown <neilb@suse.com>
Mon, 5 Dec 2016 05:40:50 +0000 (16:40 +1100)
committerShaohua Li <shli@fb.com>
Tue, 6 Dec 2016 01:11:03 +0000 (17:11 -0800)
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>
drivers/md/md.c

index c7894fbbd8e5e0e984c7a9e7d0c07866ecfe8c33..84dc8913d13b96704fcd234573fcb8bdb578a5f3 100644 (file)
@@ -7112,7 +7112,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
        if (test_bit(MD_CLOSING, &mddev->flags)) {
                mutex_unlock(&mddev->open_mutex);
-               return -ENODEV;
+               err = -ENODEV;
+               goto out;
        }
 
        err = 0;
@@ -7121,6 +7122,8 @@ static int md_open(struct block_device *bdev, fmode_t mode)
 
        check_disk_change(bdev);
  out:
+       if (err)
+               mddev_put(mddev);
        return err;
 }