Skip to content

Commit

Permalink
percpu: initialize best_upa variable
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dennisszhou committed Jun 14, 2021
1 parent faf65dd commit 4829c79
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mm/percpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,7 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
* Related to atom_size, which could be much larger than the unit_size.
*/
last_allocs = INT_MAX;
best_upa = 0;
for (upa = max_upa; upa; upa--) {
int allocs = 0, wasted = 0;

Expand All @@ -2914,6 +2915,7 @@ static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
last_allocs = allocs;
best_upa = upa;
}
BUG_ON(!best_upa);
upa = best_upa;

/* allocate and fill alloc_info */
Expand Down

0 comments on commit 4829c79

Please sign in to comment.