diff mbox series

[v2] dm raid: fix mddev unlocking in raid_ctr() error paths

Message ID 20210906041616.22812-1-dinghao.liu@zju.edu.cn (mailing list archive)
State New, archived
Headers show
Series [v2] dm raid: fix mddev unlocking in raid_ctr() error paths | expand

Commit Message

Dinghao Liu Sept. 6, 2021, 4:16 a.m. UTC
mddev_unlock() is called on all paths after we call mddev_lock_nointr(),
except for three error handling paths, which may cause a deadlock.

Fixes: 9dbd1aa3a81c ("dm raid: add reshaping support to the target")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
---

Changelog:

v2: - Simplify the error handling paths.
---
 drivers/md/dm-raid.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Heinz Mauelshagen Sept. 6, 2021, 12:43 p.m. UTC | #1
Thanks for the updated patch, acked.

-- lvmguy

On Mon, Sep 6, 2021 at 6:17 AM Dinghao Liu <dinghao.liu@zju.edu.cn> wrote:

> mddev_unlock() is called on all paths after we call mddev_lock_nointr(),
> except for three error handling paths, which may cause a deadlock.
>
> Fixes: 9dbd1aa3a81c ("dm raid: add reshaping support to the target")
> Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
> Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
> ---
>
> Changelog:
>
> v2: - Simplify the error handling paths.
> ---
>  drivers/md/dm-raid.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
> index d9ef52159a22..741bab00e922 100644
> --- a/drivers/md/dm-raid.c
> +++ b/drivers/md/dm-raid.c
> @@ -3249,14 +3249,12 @@ static int raid_ctr(struct dm_target *ti, unsigned
> int argc, char **argv)
>         rs->md.in_sync = 0; /* Assume already marked dirty */
>         if (r) {
>                 ti->error = "Failed to run raid array";
> -               mddev_unlock(&rs->md);
> -               goto bad;
> +               goto bad_unlock;
>         }
>
>         r = md_start(&rs->md);
>         if (r) {
>                 ti->error = "Failed to start raid array";
> -               mddev_unlock(&rs->md);
>                 goto bad_md_start;
>         }
>
> @@ -3265,7 +3263,6 @@ static int raid_ctr(struct dm_target *ti, unsigned
> int argc, char **argv)
>                 r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode);
>                 if (r) {
>                         ti->error = "Failed to set raid4/5/6 journal mode";
> -                       mddev_unlock(&rs->md);
>                         goto bad_journal_mode_set;
>                 }
>         }
> @@ -3304,10 +3301,12 @@ static int raid_ctr(struct dm_target *ti, unsigned
> int argc, char **argv)
>         mddev_unlock(&rs->md);
>         return 0;
>
> +bad_unlock:
>  bad_md_start:
>  bad_journal_mode_set:
>  bad_stripe_cache:
>  bad_check_reshape:
> +       mddev_unlock(&rs->md);
>         md_stop(&rs->md);
>  bad:
>         raid_set_free(rs);
> --
> 2.17.1
>
>
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index d9ef52159a22..741bab00e922 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -3249,14 +3249,12 @@  static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	rs->md.in_sync = 0; /* Assume already marked dirty */
 	if (r) {
 		ti->error = "Failed to run raid array";
-		mddev_unlock(&rs->md);
-		goto bad;
+		goto bad_unlock;
 	}
 
 	r = md_start(&rs->md);
 	if (r) {
 		ti->error = "Failed to start raid array";
-		mddev_unlock(&rs->md);
 		goto bad_md_start;
 	}
 
@@ -3265,7 +3263,6 @@  static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		r = r5c_journal_mode_set(&rs->md, rs->journal_dev.mode);
 		if (r) {
 			ti->error = "Failed to set raid4/5/6 journal mode";
-			mddev_unlock(&rs->md);
 			goto bad_journal_mode_set;
 		}
 	}
@@ -3304,10 +3301,12 @@  static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	mddev_unlock(&rs->md);
 	return 0;
 
+bad_unlock:
 bad_md_start:
 bad_journal_mode_set:
 bad_stripe_cache:
 bad_check_reshape:
+	mddev_unlock(&rs->md);
 	md_stop(&rs->md);
 bad:
 	raid_set_free(rs);