From: NeilBrown <neilb@suse.de>
To: Ben Hutchings <bhutchings@solarflare.com>
Cc: majianpeng <majianpeng@gmail.com>, linux-raid@vger.kernel.org
Subject: Re: md/raid5: Use conf->device_lock protect changing of multi-thread resources.
Date: Mon, 25 Nov 2013 11:16:48 +1100 [thread overview]
Message-ID: <20131125111648.7bdedb61@notabene.brown> (raw)
In-Reply-To: <1385136649.1586.27.camel@bwh-desktop.uk.level5networks.com>
[-- Attachment #1: Type: text/plain, Size: 2561 bytes --]
On Fri, 22 Nov 2013 16:10:49 +0000 Ben Hutchings <bhutchings@solarflare.com>
wrote:
> Coverity reported a new defect after this change (commit 60aaf9338545) -
> passing a singleton pointer as the worker_groups parameter to
> alloc_thread_groups() which expects an array pointer. But actually it
> looks like it should still be a singleton pointer and
> alloc_thread_groups() is broken:
>
> - conf->worker_groups = kzalloc(sizeof(struct r5worker_group) *
> - conf->group_cnt, GFP_NOIO);
> - if (!conf->worker_groups || !workers) {
> + workers = kzalloc(size * *group_cnt, GFP_NOIO);
> + *worker_groups = kzalloc(sizeof(struct r5worker_group) *
> + *group_cnt, GFP_NOIO);
> + if (!*worker_groups || !workers) {
> kfree(workers);
> - kfree(conf->worker_groups);
> - conf->worker_groups = NULL;
> + kfree(*worker_groups);
> return -ENOMEM;
> }
>
> - for (i = 0; i < conf->group_cnt; i++) {
> + for (i = 0; i < *group_cnt; i++) {
> struct r5worker_group *group;
>
> - group = &conf->worker_groups[i];
> + group = worker_groups[i];
>
> This assignment should, I think, be:
>
> group = &(*worker_groups)[i];
>
> or equivalently:
>
> group = *worker_groups + i;
>
> Ben.
>
Thanks Ben! I completely agree with the analysis.
Following patch queue for submission later in the week.
NeilBrown
From: NeilBrown <neilb@suse.de>
Date: Mon, 25 Nov 2013 11:12:43 +1100
Subject: [PATCH] md/raid5: fix new memory-reference bug in alloc_thread_groups.
In alloc_thread_groups, worker_groups is a pointer to an array,
not an array of pointers.
So
worker_groups[i]
is wrong. It should be
&(*worker_groups)[i]
Found-by: coverity
Fixes: 60aaf9338545
Reported-by: Ben Hutchings <bhutchings@solarflare.com>
Cc: majianpeng <majianpeng@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 47da0af6322b..676d8b7c5117 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -5471,7 +5471,7 @@ static int alloc_thread_groups(struct r5conf *conf, int cnt,
for (i = 0; i < *group_cnt; i++) {
struct r5worker_group *group;
- group = worker_groups[i];
+ group = &(*worker_groups)[i];
INIT_LIST_HEAD(&group->handle_list);
group->conf = conf;
group->workers = workers + i * cnt;
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
prev parent reply other threads:[~2013-11-25 0:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-22 16:10 md/raid5: Use conf->device_lock protect changing of multi-thread resources Ben Hutchings
2013-11-25 0:16 ` NeilBrown [this message]
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=20131125111648.7bdedb61@notabene.brown \
--to=neilb@suse.de \
--cc=bhutchings@solarflare.com \
--cc=linux-raid@vger.kernel.org \
--cc=majianpeng@gmail.com \
/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).