ANDROID: cpufreq: times: convert freq_table to flexible array member

Since commit df8fc4e934 ("kbuild: Enable -fstrict-flex-arrays=3")
we get a runtime 'UBSAN array index out of bounds' error, because the
code here is now trying to access an array past its 0 number of
elements.

Replace old-style 0-element array "freq_table" in struct cpu_freqs with
modern C99 flexible array.

While at it, convert to using struct_size() instead of manually
calculating array sizes.

Test: TH
Bug: 292213903
Change-Id: I66ee3f733bc5da4c86a0684858cb2767840657d7
Signed-off-by: André Draszik <draszik@google.com>
This commit is contained in:
André Draszik authored and Greg Kroah-Hartman committed 2023-07-25 09:37:59 +00:00
1 parent 31aa9d206a
commit 636fc5c54b
1 file changed
+2 -3
+2 -3
View File
@@ -35,7 +35,7 @@ struct cpu_freqs {
unsigned int offset;
unsigned int max_state;
unsigned int last_index;
unsigned int freq_table[0];
unsigned int freq_table[];
};
static struct cpu_freqs *all_freqs[NR_CPUS];
@@ -176,8 +176,7 @@ void cpufreq_times_create_policy(struct cpufreq_policy *policy)
cpufreq_for_each_valid_entry(pos, table)
count++;
tmp = kzalloc(sizeof(*freqs) + sizeof(freqs->freq_table[0]) * count,
GFP_KERNEL);
tmp = kzalloc(struct_size(freqs, freq_table, count), GFP_KERNEL);
if (!tmp)
return;