Skip to content

Commit 5893435

Browse files
Muchun SongPeter Zijlstra
authored andcommitted
smp: Fix a potential usage of stale nr_cpus
The get_option() maybe return 0, it means that the nr_cpus is not initialized. Then we will use the stale nr_cpus to initialize the nr_cpu_ids. So fix it. Signed-off-by: Muchun Song <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 3edecfe commit 5893435

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/smp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,7 @@ static int __init nrcpus(char *str)
634634
{
635635
int nr_cpus;
636636

637-
get_option(&str, &nr_cpus);
638-
if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
637+
if (get_option(&str, &nr_cpus) && nr_cpus > 0 && nr_cpus < nr_cpu_ids)
639638
nr_cpu_ids = nr_cpus;
640639

641640
return 0;

0 commit comments

Comments
 (0)