From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org
Cc: Lee Jones <lee@kernel.org>, Vojtech Pavlik <vojtech@ucw.cz>,
Guanglei Zhu <zhugl3@xiaopeng.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] Input: adi - use BIT() and GENMASK() for bitmasks and bit checks
Date: Sun, 29 Nov 2026 21:42:44 -0800 [thread overview]
Message-ID: <20261130054245.2215181-8-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20261130054245.2215181-1-dmitry.torokhov@gmail.com>
Replace raw hexadecimal bitmasks and open-coded bit shifts with BIT()
and GENMASK() helpers for the capability flags, gameport strobe mask,
stream data bit, and pad direction decoding.
No functional changes intended.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 6eb8dabda4e5..787af165db2a 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -7,6 +7,7 @@
* Logitech ADI joystick family driver for Linux
*/
+#include <linux/bits.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -39,8 +40,10 @@ MODULE_LICENSE("GPL");
#define ADI_MAX_CNAME_LENGTH 16
#define ADI_MAX_PHYS_LENGTH 64
-#define ADI_FLAG_HAT 0x04
-#define ADI_FLAG_10BIT 0x08
+#define ADI_FLAG_HAT BIT(2)
+#define ADI_FLAG_10BIT BIT(3)
+#define ADI_DATA_BIT BIT(5)
+#define ADI_STROBE_MASK GENMASK(5, 4)
#define ADI_ID_WMED 0x00
#define ADI_ID_TPD 0x01
@@ -170,13 +173,13 @@ static void adi_read_packet(struct adi_port *port)
w = u ^ (v = x = gameport_read(gameport));
for (i = 0; i < 2; i++, w >>= 2, x >>= 2) {
t[i]--;
- if ((w & 0x30) && s[i]) {
- if ((w & 0x30) < 0x30 &&
+ if ((w & ADI_STROBE_MASK) && s[i]) {
+ if ((w & ADI_STROBE_MASK) != ADI_STROBE_MASK &&
adi[i].ret < ADI_MAX_LENGTH - 1 && t[i] > 0) {
adi[i].data[++adi[i].ret] = w;
t[i] = gameport_time(gameport, ADI_MAX_STROBE);
} else t[i] = 0;
- } else if (!(x & 0x30)) s[i] = 1;
+ } else if (!(x & ADI_STROBE_MASK)) s[i] = 1;
}
} while (t[0] > 0 || t[1] > 0);
@@ -198,7 +201,7 @@ static void adi_move_bits(struct adi_port *port, int length)
adi[0].idx = adi[1].idx = 0;
if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
- if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return;
+ if (adi[0].data[0] & ADI_DATA_BIT || !(adi[1].data[0] & ADI_DATA_BIT)) return;
if (length <= 0)
goto err_out;
@@ -230,7 +233,7 @@ static inline int adi_get_bits(struct adi *adi, int count)
int i;
if ((adi->idx += count) > adi->ret) return 0;
for (i = 0; i < count; i++)
- bits |= ((adi->data[adi->idx - i] >> 5) & 1) << i;
+ bits |= !!(adi->data[adi->idx - i] & ADI_DATA_BIT) << i;
return bits;
}
@@ -257,8 +260,8 @@ static int adi_decode(struct adi *adi)
for (i = 0; i < adi->buttons && i < 63; i++) {
if (i == adi->pad) {
t = adi_get_bits(adi, 4);
- input_report_abs(dev, *abs++, ((t >> 2) & 1) - ( t & 1));
- input_report_abs(dev, *abs++, ((t >> 1) & 1) - ((t >> 3) & 1));
+ input_report_abs(dev, *abs++, !!(t & BIT(2)) - !!(t & BIT(0)));
+ input_report_abs(dev, *abs++, !!(t & BIT(1)) - !!(t & BIT(3)));
}
input_report_key(dev, *key++, adi_get_bits(adi, 1));
}
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-30 5:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 1/8] Input: adi - fix out-of-bounds write in adi_read_packet() Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 2/8] Input: adi - bound two-stream packet merge in adi_move_bits() Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 3/8] Input: adi - validate ID packet axis and button counts Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 4/8] Input: adi - use explicit fixed-width types and const tables Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 5/8] Input: adi - simplify device name formatting Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 6/8] Input: adi - use dev_warn() in adi_id_decode() Dmitry Torokhov
2026-11-30 5:42 ` Dmitry Torokhov [this message]
2026-11-30 5:42 ` [PATCH 8/8] Input: adi - clean up formatting Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130054245.2215181-8-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vojtech@ucw.cz \
--cc=zhugl3@xiaopeng.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox