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@xxxxxxxxxx> --- 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