Commit f9a90501 authored by Matteo Croce's avatar Matteo Croce Committed by Linus Torvalds

reboot: refactor and comment the cpu selection code

Small improvements to the code, without changing the way it works:

 - use a local variable, to avoid a small time lapse where reboot_cpu
   can have an invalid value

 - comment the code which is not easy to understand at a glance

 - merge two identical code blocks into one

 - replace pointer arithmetics with equivalent array syntax

Link: https://lkml.kernel.org/r/20201103214025.116799-4-mcroce@linux.microsoft.comSigned-off-by: default avatarMatteo Croce <mcroce@microsoft.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Fabian Frederick <fabf@skynet.be>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Robin Holt <robinmholt@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d3c22797
...@@ -553,20 +553,24 @@ static int __init reboot_setup(char *str) ...@@ -553,20 +553,24 @@ static int __init reboot_setup(char *str)
break; break;
case 's': case 's':
if (isdigit(*(str+1))) /*
reboot_cpu = simple_strtoul(str+1, NULL, 0); * reboot_cpu is s[mp]#### with #### being the processor
else if (str[1] == 'm' && str[2] == 'p' && * to be used for rebooting. Skip 's' or 'smp' prefix.
isdigit(*(str+3))) */
reboot_cpu = simple_strtoul(str+3, NULL, 0); str += str[1] == 'm' && str[2] == 'p' ? 3 : 1;
else
if (isdigit(str[0])) {
int cpu = simple_strtoul(str, NULL, 0);
if (cpu >= num_possible_cpus()) {
pr_err("Ignoring the CPU number in reboot= option. "
"CPU %d exceeds possible cpu number %d\n",
cpu, num_possible_cpus());
break;
}
reboot_cpu = cpu;
} else
*mode = REBOOT_SOFT; *mode = REBOOT_SOFT;
if (reboot_cpu >= num_possible_cpus()) {
pr_err("Ignoring the CPU number in reboot= option. "
"CPU %d exceeds possible cpu number %d\n",
reboot_cpu, num_possible_cpus());
reboot_cpu = 0;
break;
}
break; break;
case 'g': case 'g':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment