From: Logan Gunthorpe <logang@deltatee.com>
To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
Song Liu <song@kernel.org>
Cc: Guoqing Jiang <guoqing.jiang@linux.dev>,
Logan Gunthorpe <logang@deltatee.com>
Subject: [PATCH v1 1/7] md/raid5: Cleanup setup_conf() error returns
Date: Thu, 7 Apr 2022 10:57:07 -0600 [thread overview]
Message-ID: <20220407165713.9243-2-logang@deltatee.com> (raw)
In-Reply-To: <20220407165713.9243-1-logang@deltatee.com>
Be more careful about the error returns. Most errors in this function
are actually ENOMEM, but it forcibly returns EIO if conf has been
allocated.
Instead return ret and ensure it is set appropriately before each goto
abort.
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
---
drivers/md/raid5.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 351d341a1ffa..c0e373a02d3a 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -7166,7 +7166,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
int i;
int group_cnt;
struct r5worker_group *new_group;
- int ret;
+ int ret = -ENOMEM;
if (mddev->new_level != 5
&& mddev->new_level != 4
@@ -7225,6 +7225,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
spin_lock_init(&conf->device_lock);
seqcount_spinlock_init(&conf->gen_lock, &conf->device_lock);
mutex_init(&conf->cache_size_mutex);
+
init_waitqueue_head(&conf->wait_for_quiescent);
init_waitqueue_head(&conf->wait_for_stripe);
init_waitqueue_head(&conf->wait_for_overlap);
@@ -7302,11 +7303,13 @@ static struct r5conf *setup_conf(struct mddev *mddev)
conf->level = mddev->new_level;
conf->chunk_sectors = mddev->new_chunk_sectors;
- if (raid5_alloc_percpu(conf) != 0)
+ ret = raid5_alloc_percpu(conf);
+ if (ret)
goto abort;
pr_debug("raid456: run(%s) called.\n", mdname(mddev));
+ ret = -EIO;
rdev_for_each(rdev, mddev) {
raid_disk = rdev->raid_disk;
if (raid_disk >= max_disks
@@ -7370,6 +7373,7 @@ static struct r5conf *setup_conf(struct mddev *mddev)
if (grow_stripes(conf, conf->min_nr_stripes)) {
pr_warn("md/raid:%s: couldn't allocate %dkB for buffers\n",
mdname(mddev), memory);
+ ret = -ENOMEM;
goto abort;
} else
pr_debug("md/raid:%s: allocated %dkB\n", mdname(mddev), memory);
@@ -7383,7 +7387,8 @@ static struct r5conf *setup_conf(struct mddev *mddev)
conf->shrinker.count_objects = raid5_cache_count;
conf->shrinker.batch = 128;
conf->shrinker.flags = 0;
- if (register_shrinker(&conf->shrinker)) {
+ ret = register_shrinker(&conf->shrinker);
+ if (ret) {
pr_warn("md/raid:%s: couldn't register shrinker.\n",
mdname(mddev));
goto abort;
@@ -7394,17 +7399,16 @@ static struct r5conf *setup_conf(struct mddev *mddev)
if (!conf->thread) {
pr_warn("md/raid:%s: couldn't allocate thread.\n",
mdname(mddev));
+ ret = -ENOMEM;
goto abort;
}
return conf;
abort:
- if (conf) {
+ if (conf)
free_conf(conf);
- return ERR_PTR(-EIO);
- } else
- return ERR_PTR(-ENOMEM);
+ return ERR_PTR(ret);
}
static int only_parity(int raid_disk, int algo, int raid_disks, int max_degraded)
--
2.30.2
next prev parent reply other threads:[~2022-04-07 17:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-07 16:57 [PATCH v1 0/7] Minor Raid5 Fixes and Cleanup Logan Gunthorpe
2022-04-07 16:57 ` Logan Gunthorpe [this message]
2022-04-08 6:06 ` [PATCH v1 1/7] md/raid5: Cleanup setup_conf() error returns Christoph Hellwig
2022-04-07 16:57 ` [PATCH v1 2/7] md/raid5: Un-nest struct raid5_percpu definition Logan Gunthorpe
2022-04-08 6:06 ` Christoph Hellwig
2022-04-07 16:57 ` [PATCH v1 3/7] md/raid5: Add __rcu annotation to struct disk_info Logan Gunthorpe
2022-04-08 6:06 ` Christoph Hellwig
2022-04-07 16:57 ` [PATCH v1 4/7] md/raid5: Annotate rdev/replacement accesses when nr_pending is elevated Logan Gunthorpe
2022-04-08 6:07 ` Christoph Hellwig
2022-04-07 16:57 ` [PATCH v1 5/7] md/raid5: Annotate rdev/replacement access when mddev_lock is held Logan Gunthorpe
2022-04-08 6:07 ` Christoph Hellwig
2022-04-07 16:57 ` [PATCH v1 6/7] md/raid5-ppl: Annotate with rcu_dereference_protected() Logan Gunthorpe
2022-04-08 6:08 ` Christoph Hellwig
2022-04-07 16:57 ` [PATCH v1 7/7] md/raid5: Annotate functions that hold device_lock with __must_hold Logan Gunthorpe
2022-04-08 6:08 ` Christoph Hellwig
2022-04-08 17:18 ` [PATCH v1 0/7] Minor Raid5 Fixes and Cleanup Song Liu
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=20220407165713.9243-2-logang@deltatee.com \
--to=logang@deltatee.com \
--cc=guoqing.jiang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--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
all inboxes | Powered by JetHome®