mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf core: Replace offsetof() with struct_size()
@ 2025-09-02  3:43 Xichao Zhao
  2025-09-02  7:25 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Xichao Zhao @ 2025-09-02  3:43 UTC (permalink / raw)
  To: peterz, mingo, acme, namhyung
  Cc: mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter,
	kan.liang, linux-perf-users, linux-kernel, Xichao Zhao

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);
 
 	entries = kzalloc(size, GFP_KERNEL);
 	if (!entries)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-02  7:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-02  3:43 [PATCH] perf core: Replace offsetof() with struct_size() Xichao Zhao
2025-09-02  7:25 ` Peter Zijlstra

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®