[PATCH 44/54] md/raid10: Return directly after a failed kzalloc() in setup_conf()

From: SF Markus Elfring
Date: Thu Oct 06 2016 - 05:45:02 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 5 Oct 2016 17:46:02 +0200

* Return directly after a call of the function "kzalloc" failed
at the beginning.

* Delete a repeated check for the local variable "conf"
which became unnecessary with this refactoring.

* Reorder calls for the functions "kfree" and "safe_put_page"
at the end.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/md/raid10.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 8326e68..abe75c2 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -3501,7 +3501,7 @@ static struct r10conf *setup_conf(struct mddev *mddev)
err = -ENOMEM;
conf = kzalloc(sizeof(*conf), GFP_KERNEL);
if (!conf)
- goto out;
+ return ERR_PTR(-ENOMEM);

/* FIXME calc properly */
conf->mirrors = kcalloc(mddev->raid_disks + max(0, -mddev->delta_disks),
@@ -3554,12 +3554,10 @@ static struct r10conf *setup_conf(struct mddev *mddev)
return conf;

out:
- if (conf) {
- mempool_destroy(conf->r10bio_pool);
- kfree(conf->mirrors);
- safe_put_page(conf->tmppage);
- kfree(conf);
- }
+ mempool_destroy(conf->r10bio_pool);
+ safe_put_page(conf->tmppage);
+ kfree(conf->mirrors);
+ kfree(conf);
return ERR_PTR(err);
}

--
2.10.1