From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from confino.investici.org (confino.investici.org [93.190.126.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1894538A701 for ; Tue, 7 Jul 2026 18:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.190.126.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783447788; cv=none; b=K8iPJ/hbtBlF7oaYcLycY49UtkuxfO9a2m0hlAjAW0ET5N9wFSyHACWRMRvpTrMPjen7XlaCVk4qQ/C34zql/a/o2VpTzF1X/oAmiom3ekRv8hlO++EY9ph2RhXxovdHJH2VOxWTbBciqCacPv/TqmaihOUajL8QOAf30+zUz9c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783447788; c=relaxed/simple; bh=tF9CQaWzxBb3C4AFi+rxA/ykCo9AOcrKaqjPfPWtkHo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FYZQl1NOslyPo8UexwjtqD/KpWssZm/fz4p30MeLxbEp3ItZVwG+XMsG+mmzrSYAtNCOmvfyChhGMk3PzJ38lHnKNgRRns7C9XntxIUIMabMNeLAgGBCBwwAsQwAON92xOJ0sijafOSG8ufZlx6+mt6JoDKHFm2ClmjJu4DVR0o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net; spf=pass smtp.mailfrom=grrlz.net; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b=UYS6aYi1; arc=none smtp.client-ip=93.190.126.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=grrlz.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=grrlz.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=grrlz.net header.i=@grrlz.net header.b="UYS6aYi1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grrlz.net; s=stigmate; t=1783447784; bh=Alohk10oUCMGxCXhkaymRW4kzjN16l3py/PQvvKLIh0=; h=From:To:Cc:Subject:Date:From; b=UYS6aYi1hifczt0TQyqQZEK7SqpFZLtZ/xwR8AteM14ttNFzNVqGj2PEs3NMd0wt6 ImXjN9hIhAy/ZIJ9mO+UH2fOT4jAxjmvjoC1+q23HsPWEJwvllamFZ0tSeI94aoJI+ eN4AMV6SqaeP/Sb81luS7tESkHJYJzEZ6FtR1/Xo= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4gvq4m3Tmcz1107; Tue, 07 Jul 2026 18:09:44 +0000 (UTC) Received: by mx1.investici.org (Postfix) id 4gvq4m0Z9Cz10yC; Tue, 07 Jul 2026 18:09:44 +0000 (UTC) From: Bradley Morgan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, kees@kernel.org, include@grrlz.net Subject: [PATCH] reboot: use a lookup table for hw_protection_action strings Date: Tue, 7 Jul 2026 18:09:44 +0000 Message-ID: <20260707180945.7781-1-include@grrlz.net> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Replace the switch and if else chains with one table. Signed-off-by: Bradley Morgan --- kernel/reboot.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/kernel/reboot.c b/kernel/reboot.c index 41a2519755aa..bed6967bfa96 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -938,16 +938,18 @@ void orderly_reboot(void) } EXPORT_SYMBOL_GPL(orderly_reboot); +/* DEFAULT is NULL: a sentinel, not a real action. */ +static const char *const hw_protection_action_strs[] = { + [HWPROT_ACT_SHUTDOWN] = "shutdown", + [HWPROT_ACT_REBOOT] = "reboot", +}; + static const char *hw_protection_action_str(enum hw_protection_action action) { - switch (action) { - case HWPROT_ACT_SHUTDOWN: - return "shutdown"; - case HWPROT_ACT_REBOOT: - return "reboot"; - default: + if (action >= ARRAY_SIZE(hw_protection_action_strs) || + !hw_protection_action_strs[action]) return "undefined"; - } + return hw_protection_action_strs[action]; } static enum hw_protection_action hw_failure_emergency_action; @@ -1055,14 +1057,17 @@ EXPORT_SYMBOL_GPL(__hw_protection_trigger); static bool hw_protection_action_parse(const char *str, enum hw_protection_action *action) { - if (sysfs_streq(str, "shutdown")) - *action = HWPROT_ACT_SHUTDOWN; - else if (sysfs_streq(str, "reboot")) - *action = HWPROT_ACT_REBOOT; - else - return false; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(hw_protection_action_strs); i++) { + if (hw_protection_action_strs[i] && + sysfs_streq(str, hw_protection_action_strs[i])) { + *action = i; + return true; + } + } - return true; + return false; } static int __init hw_protection_setup(char *str) -- 2.53.0