From: "Gustavo A. R. Silva" <gustavoars@kernel.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>,
Christoph Lameter <cl@linux.com>, Linux-MM <linux-mm@kvack.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [GIT PULL] percpu fix for v5.9-rc6
Date: Fri, 18 Sep 2020 11:23:05 -0500 [thread overview]
Message-ID: <20200918162305.GB25599@embeddedor> (raw)
In-Reply-To: <CAHk-=whXpv0KJvpL153dhUaRgSjzT8H4dD85hRw-fAwXvXnKAA@mail.gmail.com>
On Thu, Sep 17, 2020 at 06:05:13PM -0700, Linus Torvalds wrote:
> On Thu, Sep 17, 2020 at 1:45 PM Dennis Zhou <dennis@kernel.org> wrote:
> >
> >
> > diff --git a/mm/percpu.c b/mm/percpu.c
> > index f4709629e6de..1ed1a349eab8 100644
> > --- a/mm/percpu.c
> > +++ b/mm/percpu.c
> > @@ -1316,7 +1316,7 @@ static struct pcpu_chunk * __init pcpu_alloc_first_chunk(unsigned long tmp_addr,
> >
> > /* allocate chunk */
> > alloc_size = sizeof(struct pcpu_chunk) +
> > - BITS_TO_LONGS(region_size >> PAGE_SHIFT);
> > + BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(unsigned long);
>
> Hmm.
>
> Wouldn't this be cleaner as
>
> alloc_size =struct_size(chunk, populated,
> BITS_TO_LONGS(region_size >> PAGE_SHIFT) );
Yeah; the above is much better. Please, use that helper.
> and looking at this, I realize that I thought we enabled warnings for
> 'sizeof()' of flexible array structures to avoid these kinds of
> mistakes, but that must clearly have happened only in a dream of mine.
If you were to try to apply the sizeof() operator to the flexible-array member
alone: sizeof(chunk->populated); you would get a warning because such arrays
have incomplete type, see below:
mm/percpu.c: In function ‘pcpu_alloc_first_chunk’:
mm/percpu.c:1320:52: error: invalid application of ‘sizeof’ to incomplete type ‘long unsigned int[]’
1320 | BITS_TO_LONGS(region_size >> PAGE_SHIFT) * sizeof(chunk->populated);
| ^
However, in this case, sizeof() is being applied to the object type, which doesn't
cause a warning, but still is an error-prone coding practice. For instance, this
is the bugfix[1], for a 4-year old bug introduced by the combination of weak code
and this commit[2]. This bug could have been prevented by either adopting better
coding practices or through the use[3] of the recent struct_size() helper.
So please, whenever you can use it, do so. :)
Thanks
--
Gustavo
[1] https://git.kernel.org/linus/cffaaf0c816238c45cd2d06913476c83eb50f682
[2] https://git.kernel.org/linus/57384592c43375d2c9a14d82aebbdc95fdda9e9d
[3] https://git.kernel.org/linus/553d66cb1e8667aadb57e3804775c5ce1724a49b
next prev parent reply other threads:[~2020-09-18 16:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 20:45 [GIT PULL] percpu fix for v5.9-rc6 Dennis Zhou
2020-09-18 1:05 ` Linus Torvalds
2020-09-18 16:23 ` Gustavo A. R. Silva [this message]
2020-09-18 17:23 ` Linus Torvalds
2020-09-18 19:34 ` Gustavo A. R. Silva
2020-09-18 19:37 ` Linus Torvalds
2020-09-18 20:02 ` Matthew Wilcox
2020-09-18 20:14 ` Linus Torvalds
2020-09-18 20:29 ` Arvind Sankar
2020-09-18 20:40 ` Linus Torvalds
2020-09-18 21:00 ` Arvind Sankar
2020-09-18 21:18 ` Linus Torvalds
2020-09-18 22:39 ` Arvind Sankar
2020-09-19 1:28 ` Linus Torvalds
2020-09-19 2:53 ` Arvind Sankar
2020-09-19 3:02 ` Matthew Wilcox
2020-09-19 3:04 ` Linus Torvalds
2020-09-19 2:45 ` Matthew Wilcox
2020-09-19 3:37 ` Arvind Sankar
2020-09-19 15:15 ` David Laight
2020-09-18 20:03 ` Gustavo A. R. Silva
2020-09-18 1:10 ` pr-tracker-bot
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=20200918162305.GB25599@embeddedor \
--to=gustavoars@kernel.org \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.