[PATCH] kernel/smp: Variable nr_cpus is uninitialized if get_option() returns 0

From: Yizhuo
Date: Thu Aug 29 2019 - 20:29:20 EST


Inside function nrcpus(), variable nr_cpus is uninitialized if
get_option() returns 0. However, the value will be used in the
if statement, which is potentially unsafe.

Signed-off-by: Yizhuo <yzhai003@xxxxxxx>
---
kernel/smp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/smp.c b/kernel/smp.c
index c94dd85c8d41..4bf24d4dc041 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -527,7 +527,7 @@ early_param("nosmp", nosmp);
/* this is hard limit */
static int __init nrcpus(char *str)
{
- int nr_cpus;
+ int nr_cpus = 0;

get_option(&str, &nr_cpus);
if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
--
2.17.1