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=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 EDD7DC2D0A3 for ; Tue, 3 Nov 2020 21:41:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C628B22456 for ; Tue, 3 Nov 2020 21:41:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732849AbgKCVlQ (ORCPT ); Tue, 3 Nov 2020 16:41:16 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37176 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732749AbgKCVlM (ORCPT ); Tue, 3 Nov 2020 16:41:12 -0500 Received: by mail-wr1-f67.google.com with SMTP id w1so20030347wrm.4 for ; Tue, 03 Nov 2020 13:41:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m4raXNcKMqgl6WmEQ4Blg2l4ucQHWNCBFrrf3NpZCXk=; b=L8lB5yZkEeuHiQQ2F2KznvRomC9yd/hr/U0dxC1WszCfyPLsPr7WIV4bNVlWpZOo8O yixEJJotYx4/2W1v6Iqv+5HplS0A+qnaT8+j9q4SjDQ6CKc+iR0ZxTAsLOxcgZMNUgHV kkj0jfaPeO4uw9CT4ydwPSqoykItlb0pskjPk1eFDRZqndHbHwrZ1kPSSuB8KjAyV9vp on91+7/LTAgNF8uLmplUFi8oLB9AhhAZhHmWYXYps4L/VzhLGxjZzH/KJu0F8EK20In7 oJv74V9KmqkY4pGTzB2b3qDsuHHusARnMHzxwBDlLl4MpZxs7K7+ehrwz39HZ2vnbVIk bndg== X-Gm-Message-State: AOAM5334QBne1qDEsM6Pk2k3RwsnQMxCPCOV9KsF0VlhpV6LIqy7LIgl SBZaLC4k8SUUN12DZMuSr/5k9Xykzq6NrIRq X-Google-Smtp-Source: ABdhPJzUAlknIbdAwlcuK4WZxTsbTJUllB4XDCuBJ9G8zbv5Kyj+lbGc2kSw7DyYWufWur/GOskSmQ== X-Received: by 2002:adf:9b8e:: with SMTP id d14mr30092484wrc.360.1604439670268; Tue, 03 Nov 2020 13:41:10 -0800 (PST) Received: from msft-t490s.teknoraver.net (net-5-95-179-145.cust.vodafonedsl.it. [5.95.179.145]) by smtp.gmail.com with ESMTPSA id o63sm84450wmo.2.2020.11.03.13.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 13:41:09 -0800 (PST) From: Matteo Croce To: linux-kernel@vger.kernel.org Cc: Guenter Roeck , Petr Mladek , Arnd Bergmann , Mike Rapoport , Kees Cook , Pavel Tatashin , Robin Holt , Fabian Frederick , Andrew Morton , Greg Kroah-Hartman Subject: [PATCH v3 3/3] reboot: refactor and comment the cpu selection code Date: Tue, 3 Nov 2020 22:40:25 +0100 Message-Id: <20201103214025.116799-4-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201103214025.116799-1-mcroce@linux.microsoft.com> References: <20201103214025.116799-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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", + 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': -- 2.28.0