Skip to content

Commit c6d777a

Browse files
keesrostedt
authored andcommitted
tracing/perf: Avoid -Warray-bounds warning for __rel_loc macro
As done for trace_events.h, also fix the __rel_loc macro in perf.h, which silences the -Warray-bounds warning: In file included from ./include/linux/string.h:253, from ./include/linux/bitmap.h:11, from ./include/linux/cpumask.h:12, from ./include/linux/mm_types_task.h:14, from ./include/linux/mm_types.h:5, from ./include/linux/buildid.h:5, from ./include/linux/module.h:14, from samples/trace_events/trace-events-sample.c:2: In function '__fortify_strcpy', inlined from 'perf_trace_foo_rel_loc' at samples/trace_events/./trace-events-sample.h:519:1: ./include/linux/fortify-string.h:47:33: warning: '__builtin_strcpy' offset 12 is out of the bounds [ 0, 4] [-Warray-bounds] 47 | #define __underlying_strcpy __builtin_strcpy | ^ ./include/linux/fortify-string.h:445:24: note: in expansion of macro '__underlying_strcpy' 445 | return __underlying_strcpy(p, q); | ^~~~~~~~~~~~~~~~~~~ Also make __data struct member a proper flexible array to avoid future problems. Link: https://lkml.kernel.org/r/[email protected] Cc: Steven Rostedt <[email protected]> Cc: Masami Hiramatsu <[email protected]> Fixes: 55de2c0 ("tracing: Add '__rel_loc' using trace event macros") Reported-by: Stephen Rothwell <[email protected]> Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 58c5724 commit c6d777a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

include/trace/perf.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424
#undef __get_rel_dynamic_array
2525
#define __get_rel_dynamic_array(field) \
26-
((void *)(&__entry->__rel_loc_##field) + \
27-
sizeof(__entry->__rel_loc_##field) + \
26+
((void *)__entry + \
27+
offsetof(typeof(*__entry), __rel_loc_##field) + \
28+
sizeof(__entry->__rel_loc_##field) + \
2829
(__entry->__rel_loc_##field & 0xffff))
2930

3031
#undef __get_rel_dynamic_array_len

include/trace/trace_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TRACE_MAKE_SYSTEM_STR();
128128
struct trace_event_raw_##name { \
129129
struct trace_entry ent; \
130130
tstruct \
131-
char __data[0]; \
131+
char __data[]; \
132132
}; \
133133
\
134134
static struct trace_event_class event_class_##name;

0 commit comments

Comments
 (0)