[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250902072550.GJ3245006@noisy.programming.kicks-ass.net>
Date: Tue, 2 Sep 2025 09:25:50 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Xichao Zhao <zhao.xichao@...o.com>
Cc: mingo@...hat.com, acme@...nel.org, namhyung@...nel.org,
mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
kan.liang@...ux.intel.com, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf core: Replace offsetof() with struct_size()
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@...o.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.
Powered by blists - more mailing lists