Skip to content

Commit 4829c79

Browse files
committed
percpu: initialize best_upa variable
Tom reported this finding from clang 10's static analysis [1]. Due to the way the code is written, it will always see a successful loop iteration. Instead of setting an initial value, check that it was set instead with BUG_ON() because 0 units per allocation is bogus. [1] https://lore.kernel.org/lkml/[email protected]/ Reported-by: Tom Rix <[email protected]> Signed-off-by: Dennis Zhou <[email protected]>
1 parent faf65dd commit 4829c79

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mm/percpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,7 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
28882888
* Related to atom_size, which could be much larger than the unit_size.
28892889
*/
28902890
last_allocs = INT_MAX;
2891+
best_upa = 0;
28912892
for (upa = max_upa; upa; upa--) {
28922893
int allocs = 0, wasted = 0;
28932894

@@ -2914,6 +2915,7 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
29142915
last_allocs = allocs;
29152916
best_upa = upa;
29162917
}
2918+
BUG_ON(!best_upa);
29172919
upa = best_upa;
29182920

29192921
/* allocate and fill alloc_info */

0 commit comments

Comments
 (0)