[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250409154356.423512-8-visitorckw@gmail.com>
Date: Wed, 9 Apr 2025 23:43:50 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: tglx@...utronix.de,
mingo@...hat.com,
bp@...en8.de,
dave.hansen@...ux.intel.com,
x86@...nel.org,
jk@...abs.org,
joel@....id.au,
eajames@...ux.ibm.com,
andrzej.hajda@...el.com,
neil.armstrong@...aro.org,
rfoss@...nel.org,
maarten.lankhorst@...ux.intel.com,
mripard@...nel.org,
tzimmermann@...e.de,
airlied@...il.com,
simona@...ll.ch,
dmitry.torokhov@...il.com,
mchehab@...nel.org,
awalls@...metrocast.net,
hverkuil@...all.nl,
miquel.raynal@...tlin.com,
richard@....at,
vigneshr@...com,
louis.peens@...igine.com,
andrew+netdev@...n.ch,
davem@...emloft.net,
edumazet@...gle.com,
pabeni@...hat.com,
parthiban.veerasooran@...rochip.com,
arend.vanspriel@...adcom.com,
johannes@...solutions.net,
gregkh@...uxfoundation.org,
jirislaby@...nel.org,
yury.norov@...il.com,
akpm@...ux-foundation.org,
jdelvare@...e.com,
linux@...ck-us.net,
alexandre.belloni@...tlin.com,
pgaj@...ence.com
Cc: hpa@...or.com,
alistair@...ple.id.au,
linux@...musvillemoes.dk,
Laurent.pinchart@...asonboard.com,
jonas@...boo.se,
jernej.skrabec@...il.com,
kuba@...nel.org,
linux-kernel@...r.kernel.org,
linux-fsi@...ts.ozlabs.org,
dri-devel@...ts.freedesktop.org,
linux-input@...r.kernel.org,
linux-media@...r.kernel.org,
linux-mtd@...ts.infradead.org,
oss-drivers@...igine.com,
netdev@...r.kernel.org,
linux-wireless@...r.kernel.org,
brcm80211@...ts.linux.dev,
brcm80211-dev-list.pdl@...adcom.com,
linux-serial@...r.kernel.org,
bpf@...r.kernel.org,
jserv@...s.ncku.edu.tw,
Frank.Li@....com,
linux-hwmon@...r.kernel.org,
linux-i3c@...ts.infradead.org,
david.laight.linux@...il.com,
andrew.cooper3@...rix.com,
Kuan-Wei Chiu <visitorckw@...il.com>,
Yu-Chun Lin <eleanor15x@...il.com>
Subject: [PATCH v4 07/13] Input: joystick - Replace open-coded parity calculation with parity_odd()
Refactor parity calculations to use the standard parity_odd() helper.
This change eliminates redundant implementations.
Co-developed-by: Yu-Chun Lin <eleanor15x@...il.com>
Signed-off-by: Yu-Chun Lin <eleanor15x@...il.com>
Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
---
drivers/input/joystick/grip_mp.c | 17 ++---------------
drivers/input/joystick/sidewinder.c | 25 +++++--------------------
2 files changed, 7 insertions(+), 35 deletions(-)
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 5eadb5a3ca37..e7f60a83a89b 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -18,6 +18,7 @@
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/jiffies.h>
+#include <linux/bitops.h>
#define DRIVER_DESC "Gravis Grip Multiport driver"
@@ -112,20 +113,6 @@ static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5
static int register_slot(int i, struct grip_mp *grip);
-/*
- * Returns whether an odd or even number of bits are on in pkt.
- */
-
-static int bit_parity(u32 pkt)
-{
- int x = pkt ^ (pkt >> 16);
- x ^= x >> 8;
- x ^= x >> 4;
- x ^= x >> 2;
- x ^= x >> 1;
- return x & 1;
-}
-
/*
* Poll gameport; return true if all bits set in 'onbits' are on and
* all bits set in 'offbits' are off.
@@ -236,7 +223,7 @@ static int mp_io(struct gameport* gameport, int sendflags, int sendcode, u32 *pa
pkt = (pkt >> 2) | 0xf0000000;
}
- if (bit_parity(pkt) == 1)
+ if (parity_odd(pkt))
return IO_RESET;
/* Acknowledge packet receipt */
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 3a5873e5fcb3..fb6f7004a485 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,22 +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 +301,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 (parity_odd(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 +318,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 (!parity_odd(GB(0,48)) || (hat = GB(42,4)) > 8)
return -1;
dev = sw->dev[0];
@@ -354,7 +339,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 (!parity_odd(GB(0,43)) || (hat = GB(28,4)) > 8)
return -1;
dev = sw->dev[0];
@@ -379,7 +364,7 @@ static int sw_parse(unsigned char *buf, struct sw *sw)
case SW_ID_FFW:
- if (!sw_parity(GB(0,33)))
+ if (!parity_odd(GB(0,33)))
return -1;
dev = sw->dev[0];
--
2.34.1
Powered by blists - more mailing lists