Refactor parity calculations to use the standard parity64() helper.
This change eliminates redundant implementations and improves code
efficiency.

Co-developed-by: Yu-Chun Lin <eleanor...@gmail.com>
Signed-off-by: Yu-Chun Lin <eleanor...@gmail.com>
Signed-off-by: Kuan-Wei Chiu <visitor...@gmail.com>
---
 drivers/input/joystick/sidewinder.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/input/joystick/sidewinder.c 
b/drivers/input/joystick/sidewinder.c
index 3a5873e5fcb3..9fe980096f70 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -7,6 +7,7 @@
  * Microsoft SideWinder joystick family driver for Linux
  */
 
+#include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -240,21 +241,6 @@ static void sw_init_digital(struct gameport *gameport)
        local_irq_restore(flags);
 }
 
-/*
- * sw_parity() computes parity of __u64
- */
-
-static int sw_parity(__u64 t)
-{
-       int x = t ^ (t >> 32);
-
-       x ^= x >> 16;
-       x ^= x >> 8;
-       x ^= x >> 4;
-       x ^= x >> 2;
-       x ^= x >> 1;
-       return x & 1;
-}
 
 /*
  * sw_ccheck() checks synchronization bits and computes checksum of nibbles.
@@ -316,7 +302,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 
                        for (i = 0; i < sw->number; i ++) {
 
-                               if (sw_parity(GB(i*15,15)))
+                               if (parity64(GB(i*15,15)))
                                        return -1;
 
                                input_report_abs(sw->dev[i], ABS_X, 
GB(i*15+3,1) - GB(i*15+2,1));
@@ -333,7 +319,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
                case SW_ID_PP:
                case SW_ID_FFP:
 
-                       if (!sw_parity(GB(0,48)) || (hat = GB(42,4)) > 8)
+                       if (!parity64(GB(0,48)) || (hat = GB(42,4)) > 8)
                                return -1;
 
                        dev = sw->dev[0];
@@ -354,7 +340,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 
                case SW_ID_FSP:
 
-                       if (!sw_parity(GB(0,43)) || (hat = GB(28,4)) > 8)
+                       if (!parity64(GB(0,43)) || (hat = GB(28,4)) > 8)
                                return -1;
 
                        dev = sw->dev[0];
@@ -379,7 +365,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
 
                case SW_ID_FFW:
 
-                       if (!sw_parity(GB(0,33)))
+                       if (!parity64(GB(0,33)))
                                return -1;
 
                        dev = sw->dev[0];
-- 
2.34.1

Reply via email to