Skip to contentSkip to conversation

x86/bootflag: Replace open-coded parity calculation with parity8()

PATCH Applied Uros Bizjak 4 participants 5 messages Feb 27, 2025 – Mar 11, 2025 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/bootflag: Replace open-coded parity calculation with parity8()

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 current source.]

---
 arch/x86/kernel/bootflag.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
arch/x86/kernel/bootflag.c +3 -15
index b935c3e42bfd..73274d76ce16 100644
@@ -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>
@@ -20,25 +21,12 @@
 
 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;
Signature · 1 line
2.48.1
#1 lore raw
Quoted 5 lines · Uros Bizjak

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 current source.]

Please preserve the original From line in these cases - I fixed that up by adding:

From: Kuan-Wei Chiu <[email protected]>

Probably the Git rebase/conflict-resolution step made you the author without warning.

Thanks,

Ingo

merge bot Applied
#2 lore raw
In reply to Uros Bizjak
The following commit has been merged into the x86/boot branch of tip:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     9c94c14ca39577b6324c667d8450ffa19fc1e5c4
Gitweb:        https://git.kernel.org/tip/9c94c14ca39577b6324c667d8450ffa19fc1e5c4
Author:        Kuan-Wei Chiu <[email protected]>
AuthorDate:    Thu, 27 Feb 2025 13:55:45 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 27 Feb 2025 14:00:30 +01:00

x86/bootflag: Replace open-coded parity calculation with parity8()

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. ]

---
 arch/x86/kernel/bootflag.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
arch/x86/kernel/bootflag.c +3 -15
index b935c3e..73274d7 100644
@@ -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>
@@ -20,25 +21,12 @@
 
 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;
#3 lore raw

Hi Ingo,

Quoted 17 lines · On Thu, Feb 27, 2025 at 01:15:13PM -0000, tip-bot2 for Kuan-Wei Chiu wrote:

The following commit has been merged into the x86/boot branch of tip:

Commit-ID:     9c94c14ca39577b6324c667d8450ffa19fc1e5c4
Gitweb:        https://git.kernel.org/tip/9c94c14ca39577b6324c667d8450ffa19fc1e5c4
Author:        Kuan-Wei Chiu <[email protected]>
AuthorDate:    Thu, 27 Feb 2025 13:55:45 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 27 Feb 2025 14:00:30 +01:00

x86/bootflag: Replace open-coded parity calculation with parity8()

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. ]

Quoted 7 lines

Thanks for accepting this patch.

Based on the previous email discussion, I plan to rename parity8() to parity_odd() in the next version of the parity patch series (though I'm not too confident it will be accepted...). If I base the series on the current linux-next tree, it might cause conflicts when other maintainers apply it to their own trees. On the other hand, if I base it on Linus's tree, it would conflict with the x86 tree.

I'm not sure which tree I should base the next version on. Since this series touches multiple subsystems, the situation is a bit tricky.

Regards,
Kuan-Wei

Reviewed-by on v1 1/1
#4 lore raw
In reply to Uros Bizjak
Quoted 6 lines · Uros Bizjak

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 current source.]

Quoted 10 lines

Not sure if the Reviewed-by tag is appropriate here, but FWIW:

I'll exclude this patch when sending the v2 parity patch series. Thanks!

Regards,
Kuan-Wei