From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3E68C55178 for ; Thu, 5 Nov 2020 18:09:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84BC02087D for ; Thu, 5 Nov 2020 18:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qAJ4IYQC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731234AbgKESJ4 (ORCPT ); Thu, 5 Nov 2020 13:09:56 -0500 Received: from mx2.suse.de ([195.135.220.15]:37560 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbgKESJ4 (ORCPT ); Thu, 5 Nov 2020 13:09:56 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1604599794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mv7ODK6mkgvs0jq5vnw1lPFEHG64V1hqt9dlD+8z708=; b=qAJ4IYQCtWO5HNQQT9GoZF12XXiutACfMoz2nVVT8Le/kJGZCgTPj0/roXO98foZwCJMRl eaCQ+scvWW833SNJ/WQyATmk6Ih5CcNPGGO5W1/CGvvw7C/il1nK1Lm7dlARF0z+zhAYXN yJ/ktifov7l96XasilqHHcHyZufkz38= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6773DABAE; Thu, 5 Nov 2020 18:09:54 +0000 (UTC) Date: Thu, 5 Nov 2020 19:09:53 +0100 From: Petr Mladek To: Matteo Croce Cc: linux-kernel@vger.kernel.org, Guenter Roeck , Arnd Bergmann , Mike Rapoport , Kees Cook , Pavel Tatashin , Robin Holt , Fabian Frederick , Andrew Morton , Greg Kroah-Hartman Subject: Re: [PATCH v3 3/3] reboot: refactor and comment the cpu selection code Message-ID: <20201105180953.GI1602@alley> References: <20201103214025.116799-1-mcroce@linux.microsoft.com> <20201103214025.116799-4-mcroce@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201103214025.116799-4-mcroce@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 2020-11-03 22:40:25, Matteo Croce wrote: > From: Matteo Croce > > 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 > > Signed-off-by: Matteo Croce > --- > kernel/reboot.c | 30 +++++++++++++++++------------- > 1 file changed, 17 insertions(+), 13 deletions(-) > > diff --git a/kernel/reboot.c b/kernel/reboot.c > index af6f23d8bea1..dd483bde932b 100644 > --- a/kernel/reboot.c > +++ b/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", Same here. I am not sure if Andrew would like to get this on a single line. In both cases: Reviewed-by: Petr Mladek Best Regards, Petr