From: Jan Kara <jack@suse.cz>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Jan Kara <jack@suse.cz>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Theodore Ts'o <tytso@mit.edu>, Jan Kara <jack@suse.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] jbd2: Avoid dozens of -Wflex-array-member-not-at-end warnings
Date: Fri, 1 Nov 2024 11:15:12 +0100 [thread overview]
Message-ID: <20241101101512.eee2nkaqgffsoxe3@quack3> (raw)
In-Reply-To: <ca7be9f4-3f33-48ba-b61a-0a40ea1f17a6@embeddedor.com>
On Thu 31-10-24 17:31:34, Gustavo A. R. Silva wrote:
> On 31/10/24 15:32, Jan Kara wrote:
> >
> > > `sizeof(ctx) == 4` when `char ctx[JBD_MAX_CHECKSUM_SIZE];`
> > >
> > > To maintain the same size, we tell `DEFINE_RAW_FLEX()` to allocate `1`
> > > element for the flex array, as in 32-bit `sizeof(void *) == 4`.
> >
> > So I agree we end up allocating enough space on stack but it is pretty
> > subtle and if JBD_MAX_CHECKSUM_SIZE definition changes, we have a problem.
> > I think we need something like (JBD_MAX_CHECKSUM_SIZE + sizeof(*desc->__ctx)
> > - 1) / sizeof(*desc->__ctx))?
>
> I see. Well, in that case it'd be something more like:
>
> - struct {
> - struct shash_desc shash;
> - char ctx[JBD_MAX_CHECKSUM_SIZE];
> - } desc;
> + DEFINE_RAW_FLEX(struct shash_desc, desc, __ctx,
> + (JBD_MAX_CHECKSUM_SIZE +
> + sizeof(*((struct shash_desc *)0)->__ctx)) /
> + sizeof(*((struct shash_desc *)0)->__ctx));
>
> Notice that `desc` is created inside `DEFINE_RAW_FLEX()`
Right. Thanks for fixing this. The cleanest option then probably is:
DEFINE_RAW_FLEX(struct shash_desc, desc, __ctx,
DIV_ROUND_UP(JBD_MAX_CHECKSUM_SIZE,
sizeof(*((struct shash_desc *)0)->__ctx)))
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-11-01 10:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-25 19:32 [PATCH][next] jbd2: Avoid dozens of -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2024-10-31 12:33 ` Jan Kara
2024-10-31 15:54 ` Gustavo A. R. Silva
2024-10-31 21:32 ` Jan Kara
2024-10-31 23:31 ` Gustavo A. R. Silva
2024-11-01 10:15 ` Jan Kara [this message]
2024-11-01 20:46 ` Gustavo A. R. Silva
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=20241101101512.eee2nkaqgffsoxe3@quack3 \
--to=jack@suse.cz \
--cc=gustavo@embeddedor.com \
--cc=gustavoars@kernel.org \
--cc=jack@suse.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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