Skip to content

Commit

Permalink
perf/x86/rapl: Annotate 'struct rapl_pmus' with __counted_by
Browse files Browse the repository at this point in the history
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS=y (for
array indexing) and CONFIG_FORTIFY_SOURCE=y (for strcpy/memcpy-family
functions).

Found with Coccinelle:

  https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]

Add __counted_by for 'struct rapl_pmus'.

No change in functionality intended.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/r/20231006201754.work.473-kees@kernel.org
  • Loading branch information
kees authored and Ingo Molnar committed Oct 8, 2023
1 parent e6814ec commit a56d555
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/x86/events/rapl.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct rapl_pmu {
struct rapl_pmus {
struct pmu pmu;
unsigned int maxdie;
struct rapl_pmu *pmus[];
struct rapl_pmu *pmus[] __counted_by(maxdie);
};

enum rapl_unit_quirk {
Expand Down

0 comments on commit a56d555

Please sign in to comment.