Commit 76af546
workqueue: validate cpumask_first() result in llc_populate_cpu_shard_id()
On uniprocessor (UP) configs such as nios2, NR_CPUS is 1, so
cpu_shard_id[] is a single-element array (int[1]). In
llc_populate_cpu_shard_id(), cpumask_first(sibling_cpus) returns an
unsigned int that the compiler cannot prove is always 0, triggering
a -Warray-bounds warning when the result is used to index
cpu_shard_id[]:
kernel/workqueue.c:8321:55: warning: array subscript 1 is above
array bounds of 'int[1]' [-Warray-bounds]
8321 | cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)];
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is a false positive: sibling_cpus can never be empty here because
'c' itself is always set in it, so cpumask_first() will always return a
valid CPU. However, the compiler cannot prove this statically, and the
warning only manifests on UP configs where the array size is 1.
Add a bounds check with WARN_ON_ONCE to silence the warning, and store
the result in a local variable to make the code clearer and avoid calling
cpumask_first() twice.
Fixes: 5920d04 ("workqueue: add WQ_AFFN_CACHE_SHARD affinity scope")
Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Signed-off-by: Breno Leitao <[email protected]>
Signed-off-by: Tejun Heo <[email protected]>1 parent 034db4d commit 76af546
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8266 | 8266 | | |
8267 | 8267 | | |
8268 | 8268 | | |
| 8269 | + | |
8269 | 8270 | | |
8270 | 8271 | | |
8271 | 8272 | | |
| |||
8286 | 8287 | | |
8287 | 8288 | | |
8288 | 8289 | | |
8289 | | - | |
| 8290 | + | |
| 8291 | + | |
| 8292 | + | |
| 8293 | + | |
| 8294 | + | |
| 8295 | + | |
| 8296 | + | |
| 8297 | + | |
| 8298 | + | |
| 8299 | + | |
| 8300 | + | |
8290 | 8301 | | |
8291 | 8302 | | |
8292 | 8303 | | |
| |||
0 commit comments