From: Thorsten Blum <thorsten.blum@linux.dev>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
x86@kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [tip: perf/core] perf/x86: Annotate struct bts_buffer with __counted_by()
Date: Wed, 5 Mar 2025 11:47:58 +0100 [thread overview]
Message-ID: <04A79410-77DA-40F9-8904-44DC2DE1E810@linux.dev> (raw)
In-Reply-To: <Z8gW1rihV0aIp8Oo@gmail.com>
On 5. Mar 2025, at 10:18, Ingo Molnar wrote:
> Actually, on a second thought:
>
>> - buf = kzalloc_node(offsetof(struct bts_buffer, buf[nbuf]), GFP_KERNEL, node);
>> + buf = kzalloc_node(struct_size(buf, buf, nbuf), GFP_KERNEL, node);
>
> Firstly, in what world is 'buf, buf' more readable? One is a member of
> a structure, the other is the name of the structure - and they match,
> which shows that this function's naming conventions are a mess.
>
> Which should be fixed first ...
Yes, I noticed this too, but since buf->buf[] is used all over the place
(also in other functions), I didn't rename it in this patch.
We could just keep offsetof(struct bts_buffer, buf[nbuf]), or use
struct_size_t(struct bts_buffer, buf, nbuf) and still benefit from
additional compile-time checks, or rename the local variable to struct
bts_buffer *bts and use struct_size(bts, buf, nbuf), for example. Any
preferences or other ideas?
> I'm also not sure the code is correct ...
Which part of it?
Thanks,
Thorsten
next prev parent reply other threads:[~2025-03-05 10:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 18:30 [PATCH] perf/x86: Annotate struct bts_buffer with __counted_by() Thorsten Blum
2025-03-04 19:12 ` [tip: perf/core] " tip-bot2 for Thorsten Blum
2025-03-05 9:18 ` Ingo Molnar
2025-03-05 10:47 ` Thorsten Blum [this message]
2025-03-05 11:02 ` Ingo Molnar
2025-03-05 12:24 ` Thorsten Blum
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=04A79410-77DA-40F9-8904-44DC2DE1E810@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=x86@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