diff options
author | Dennis Zhou <dennis@kernel.org> | 2021-06-14 17:42:05 +0300 |
---|---|---|
committer | Dennis Zhou <dennis@kernel.org> | 2021-06-14 17:42:05 +0300 |
commit | 4829c791b22f98f95339248a428caf08b5f1e3e5 (patch) | |
tree | ccd014d07bde7da164bf24375d263f1952c6eb49 /mm/percpu.c | |
parent | faf65dde844affa9e360ccaa4bd231c2a04b87ea (diff) | |
download | linux-4829c791b22f98f95339248a428caf08b5f1e3e5.tar.xz |
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/20210515180817.1751084-1-trix@redhat.com/
Reported-by: Tom Rix <trix@redhat.com>
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Diffstat (limited to 'mm/percpu.c')
-rw-r--r-- | mm/percpu.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/mm/percpu.c b/mm/percpu.c index e7b9ca82e9aa..6667dfa0fcec 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -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; @@ -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 */ |