[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250902034349.601692-1-zhao.xichao@vivo.com>
Date: Tue, 2 Sep 2025 11:43:49 +0800
From: Xichao Zhao <zhao.xichao@...o.com>
To: peterz@...radead.org,
mingo@...hat.com,
acme@...nel.org,
namhyung@...nel.org
Cc: 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,
Xichao Zhao <zhao.xichao@...o.com>
Subject: [PATCH] perf core: Replace offsetof() with struct_size()
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);
entries = kzalloc(size, GFP_KERNEL);
if (!entries)
--
2.34.1
Powered by blists - more mailing lists