The patch titled Subject: reboot: refactor and comment the cpu selection code has been added to the -mm tree. Its filename is reboot-refactor-and-comment-the-cpu-selection-code.patch This patch should soon appear at https://ozlabs.org/~akpm/mmots/broken-out/reboot-refactor-and-comment-the-cpu-selection-code.patch and later at https://ozlabs.org/~akpm/mmotm/broken-out/reboot-refactor-and-comment-the-cpu-selection-code.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Matteo Croce <mcroce@xxxxxxxxxxxxx> Subject: 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@xxxxxxxxxxxxxxxxxxx Signed-off-by: Matteo Croce <mcroce@xxxxxxxxxxxxx> Cc: Arnd Bergmann <arnd@xxxxxxxx> Cc: Fabian Frederick <fabf@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Guenter Roeck <linux@xxxxxxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Cc: Mike Rapoport <rppt@xxxxxxxxxx> Cc: Pavel Tatashin <pasha.tatashin@xxxxxxxxxx> Cc: Petr Mladek <pmladek@xxxxxxxx> Cc: Robin Holt <robinmholt@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- kernel/reboot.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) --- a/kernel/reboot.c~reboot-refactor-and-comment-the-cpu-selection-code +++ a/kernel/reboot.c @@ -551,20 +551,24 @@ static int __init reboot_setup(char *str break; case 's': - if (isdigit(*(str+1))) - reboot_cpu = simple_strtoul(str+1, NULL, 0); - else if (str[1] == 'm' && str[2] == 'p' && - isdigit(*(str+3))) - reboot_cpu = simple_strtoul(str+3, NULL, 0); - else + /* + * reboot_cpu is s[mp]#### with #### being the processor + * to be used for rebooting. Skip 's' or 'smp' prefix. + */ + str += str[1] == 'm' && str[2] == 'p' ? 3 : 1; + + 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; - 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; case 'g': _ Patches currently in -mm which might be from mcroce@xxxxxxxxxxxxx are revert-kernel-rebootc-convert-simple_strtoul-to-kstrtoint.patch reboot-fix-overflow-parsing-reboot-cpu-number.patch reboot-refactor-and-comment-the-cpu-selection-code.patch