From: Xiao Ni <xni@redhat.com>
To: song@kernel.org
Cc: guoqing.jiang@linux.dev, ncroxon@redhat.com, linux-raid@vger.kernel.org
Subject: [PATCH V2 1/2] md/raid0: Free r0conf memory when register integrity failed
Date: Fri, 10 Dec 2021 17:31:15 +0800 [thread overview]
Message-ID: <20211210093116.7847-2-xni@redhat.com> (raw)
In-Reply-To: <20211210093116.7847-1-xni@redhat.com>
It doesn't free memory when register integrity failed. And it will
add acct_bioset_exit in raid0_free. So split free r0conf codes
into a single function to make error handling more clear.
Signed-off-by: Xiao Ni <xni@redhat.com>
---
V2: set mddev->private to NULL and move free_conf/raid0_free
above to avoid the extra declaration
---
drivers/md/raid0.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 62c8b6adac70..88424d7a6ebd 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -356,7 +356,20 @@ static sector_t raid0_size(struct mddev *mddev, sector_t sectors, int raid_disks
return array_sectors;
}
-static void raid0_free(struct mddev *mddev, void *priv);
+static void free_conf(struct mddev *mddev, struct r0conf *conf)
+{
+ kfree(conf->strip_zone);
+ kfree(conf->devlist);
+ kfree(conf);
+ mddev->private = NULL;
+}
+
+static void raid0_free(struct mddev *mddev, void *priv)
+{
+ struct r0conf *conf = priv;
+
+ free_conf(mddev, conf);
+}
static int raid0_run(struct mddev *mddev)
{
@@ -413,17 +426,14 @@ static int raid0_run(struct mddev *mddev)
dump_zones(mddev);
ret = md_integrity_register(mddev);
+ if (ret)
+ goto free;
return ret;
-}
-
-static void raid0_free(struct mddev *mddev, void *priv)
-{
- struct r0conf *conf = priv;
- kfree(conf->strip_zone);
- kfree(conf->devlist);
- kfree(conf);
+free:
+ free_conf(mddev, conf);
+ return ret;
}
static void raid0_handle_discard(struct mddev *mddev, struct bio *bio)
--
2.31.1
next prev parent reply other threads:[~2021-12-10 9:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 9:31 [PATCH 0/2] md: it panice after reshape from raid1 to raid5 Xiao Ni
2021-12-10 9:31 ` Xiao Ni [this message]
2021-12-10 9:31 ` [PATCH 2/2] md: Move alloc/free acct bioset in to personality Xiao Ni
2022-01-04 23:30 ` [PATCH 0/2] md: it panice after reshape from raid1 to raid5 Xiao Ni
2022-01-05 18:59 ` Song Liu
2022-01-06 1:53 ` Xiao Ni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211210093116.7847-2-xni@redhat.com \
--to=xni@redhat.com \
--cc=guoqing.jiang@linux.dev \
--cc=linux-raid@vger.kernel.org \
--cc=ncroxon@redhat.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).