]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
x86/bootflag: Replace open-coded parity calculation with parity8()
authorKuan-Wei Chiu <visitorckw@gmail.com>
Thu, 27 Feb 2025 12:55:45 +0000 (13:55 +0100)
committerIngo Molnar <mingo@kernel.org>
Thu, 27 Feb 2025 13:00:30 +0000 (14:00 +0100)
Refactor parity calculations to use the standard parity8() helper. This
change eliminates redundant implementations and improves code
efficiency.

[ ubizjak: Updated the patch to apply to the latest x86 tree. ]

Co-developed-by: Yu-Chun Lin <eleanor15x@gmail.com>
Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com>
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/r/20250227125616.2253774-1-ubizjak@gmail.com
arch/x86/kernel/bootflag.c

index b935c3e42bfdffef2924a7cf26f326fc0b306e55..73274d76ce16751d8ab9a17e6a229fe8c3589af1 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/string.h>
 #include <linux/spinlock.h>
 #include <linux/acpi.h>
+#include <linux/bitops.h>
 #include <asm/io.h>
 
 #include <linux/mc146818rtc.h>
 
 int sbf_port __initdata = -1;  /* set via acpi_boot_init() */
 
-static bool __init parity(u8 v)
-{
-       int x = 0;
-       int i;
-
-       for (i = 0; i < 8; i++) {
-               x ^= (v & 1);
-               v >>= 1;
-       }
-
-       return !!x;
-}
-
 static void __init sbf_write(u8 v)
 {
        unsigned long flags;
 
        if (sbf_port != -1) {
-               if (!parity(v))
+               if (!parity8(v))
                        v ^= SBF_PARITY;
 
                printk(KERN_INFO "Simple Boot Flag at 0x%x set to 0x%x\n",
@@ -69,7 +57,7 @@ static bool __init sbf_value_valid(u8 v)
 {
        if (v & SBF_RESERVED)           /* Reserved bits */
                return false;
-       if (!parity(v))
+       if (!parity8(v))
                return false;
 
        return true;