mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Xichao Zhao <zhao.xichao@vivo.com>
Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com,
	kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf core: Replace offsetof() with struct_size()
Date: Tue, 2 Sep 2025 09:25:50 +0200	[thread overview]
Message-ID: <20250902072550.GJ3245006@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20250902034349.601692-1-zhao.xichao@vivo.com>

On Tue, Sep 02, 2025 at 11:43:49AM +0800, Xichao Zhao wrote:
> When dealing with structures containing flexible arrays, struct_size()
> provides additional compile-time checks compared to offsetof(). This
> enhances code robustness and reduces the risk of potential errors.
> 
> Signed-off-by: Xichao Zhao <zhao.xichao@vivo.com>
> ---
>  kernel/events/callchain.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
> index 6c83ad674d01..0f88e44af664 100644
> --- a/kernel/events/callchain.c
> +++ b/kernel/events/callchain.c
> @@ -80,7 +80,7 @@ static int alloc_callchain_buffers(void)
>  	 * accessed from NMI. Use a temporary manual per cpu allocation
>  	 * until that gets sorted out.
>  	 */
> -	size = offsetof(struct callchain_cpus_entries, cpu_entries[nr_cpu_ids]);
> +	size = struct_size(entries, cpu_entries, nr_cpu_ids);

None of this code is needed anymore; that issue with NMI not being able
to access vmalloc memory should be long fixed.

      reply	other threads:[~2025-09-02  7:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02  3:43 Xichao Zhao
2025-09-02  7:25 ` Peter Zijlstra [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=20250902072550.GJ3245006@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=zhao.xichao@vivo.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

all inboxes | Powered by JetHome®