* [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups
@ 2026-11-30 5:42 Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 1/8] Input: adi - fix out-of-bounds write in adi_read_packet() Dmitry Torokhov
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
This series fixes packet bounds checking and ID packet validation in the
Logitech ADI joystick driver, followed by a few follow-up cleanups.
The first three patches fix the off-by-one packet buffer write in
adi_read_packet(), bound the two-stream merge in adi_move_bits(), and
consolidate the parallel model tables into a descriptor array so
adi_id_decode() can reject underflowing or out-of-range axis, pad, and
button counts. The remaining patches switch to explicit fixed-width types
and const tables, simplify device name formatting by dropping the
temporary buffer and dynamic format string, convert remaining warnings to
dev_warn(), adopt BIT() and GENMASK() for bitmasks and bit checks, and
clean up coding style across the driver.
Thanks.
Dmitry Torokhov (8):
Input: adi - fix out-of-bounds write in adi_read_packet()
Input: adi - bound two-stream packet merge in adi_move_bits()
Input: adi - validate ID packet axis and button counts
Input: adi - use explicit fixed-width types and const tables
Input: adi - simplify device name formatting
Input: adi - use dev_warn() in adi_id_decode()
Input: adi - use BIT() and GENMASK() for bitmasks and bit checks
Input: adi - clean up formatting
drivers/input/joystick/adi.c | 301 +++++++++++++++++++++++++----------
1 file changed, 214 insertions(+), 87 deletions(-)
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/8] Input: adi - fix out-of-bounds write in adi_read_packet()
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
@ 2026-11-30 5:42 ` Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 2/8] Input: adi - bound two-stream packet merge in adi_move_bits() Dmitry Torokhov
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input
Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel, sashiko-bot
adi_read_packet() initializes the per-stream packet counter to -1 and
pre-increments it before storing each sample into the fixed-size data
buffer, while checking the upper bound against the full buffer length.
When the buffer already holds 256 samples, another strobe passes the
check and writes one byte past the end of the buffer into adjacent
fields of struct adi_port, and leaves the counter out of bounds for
subsequent packet reads.
Bound the packet counter to one less than the buffer size so writes stay
within the data buffer.
Reported-by: sashiko-bot@kernel.org
Closes: https://sashiko.dev/#/bug/linux-951334ec-a996-4dc4-a03b-d7e6f716e5de
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 0b60c8067faf..43c2e60fcb1c 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -141,7 +141,8 @@ static void adi_read_packet(struct adi_port *port)
for (i = 0; i < 2; i++, w >>= 2, x >>= 2) {
t[i]--;
if ((w & 0x30) && s[i]) {
- if ((w & 0x30) < 0x30 && adi[i].ret < ADI_MAX_LENGTH && t[i] > 0) {
+ if ((w & 0x30) < 0x30 &&
+ 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;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/8] Input: adi - bound two-stream packet merge in adi_move_bits()
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 ` Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 3/8] Input: adi - validate ID packet axis and button counts Dmitry Torokhov
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
In two-stream mode, adi_move_bits() merges the second stream's samples
into the primary stream's data buffer at an offset derived from the
expected packet length, without validating either the length or the
resulting buffer indices and combined sample count. A zero length from
the raw header or an uninitialized primary stream produces an invalid
shift and offset, while overly large offsets or stream lengths write
past the end of the primary buffer into adjacent port state and allow
subsequent bit reads to overrun the buffer.
Reject non-positive lengths before computing the merge offset, and
reject any merge whose combined sample count or destination offset
would reach or exceed the buffer size. Invalidate both streams on
rejection so unmerged half-streams are not decoded as standalone
packets.
Reported-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Link: https://lore.kernel.org/r/20261103111714.472080-1-zhugl3@xiaopeng.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 43c2e60fcb1c..3e34210de4ed 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -162,7 +162,7 @@ static void adi_read_packet(struct adi_port *port)
static void adi_move_bits(struct adi_port *port, int length)
{
- int i;
+ int i, offset;
struct adi *adi = port->adi;
adi[0].idx = adi[1].idx = 0;
@@ -170,11 +170,24 @@ static void adi_move_bits(struct adi_port *port, int length)
if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return;
+ if (length <= 0)
+ goto err_out;
+
+ offset = ((length - 1) >> 1) + 1;
+ if (adi[0].ret + adi[1].ret >= ADI_MAX_LENGTH ||
+ offset + adi[1].ret >= ADI_MAX_LENGTH)
+ goto err_out;
+
for (i = 1; i <= adi[1].ret; i++)
- adi[0].data[((length - 1) >> 1) + i + 1] = adi[1].data[i];
+ adi[0].data[offset + i] = adi[1].data[i];
adi[0].ret += adi[1].ret;
adi[1].ret = -1;
+ return;
+
+err_out:
+ adi[0].ret = -1;
+ adi[1].ret = -1;
}
/*
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/8] Input: adi - validate ID packet axis and button counts
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 ` Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 4/8] Input: adi - use explicit fixed-width types and const tables Dmitry Torokhov
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input
Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel, sashiko-bot
adi_id_decode() only validates parsed axis, hat, and button counts
against the overall packet bit length, allowing malformed ID packets to
trigger integer underflow or out-of-bounds accesses against the static
per-model capability tables:
- When the 10-bit flag is set, subtracting a larger 8-bit axis count
from the total axis count underflows.
- For ThunderPad Digital and WingMan GamePad, subtracting 4 pad bits
from an insufficient button count underflows or leaves the pad index
unreachable during packet decoding.
- Valid packet lengths up to 255 bits can describe far more axes or
buttons than the static per-model tables contain, causing
out-of-bounds reads, bitmask writes, and axis lookups during input
registration, centering, and polling.
Consolidate the parallel model metadata arrays into a single descriptor
table that records each model's axis and key table sizes, attach the
selected model descriptor to the per-device state during ID decoding,
and reject ID packets that underflow axis or button counts or exceed
the selected model's table capacities.
Reported-by: sashiko-bot@kernel.org
Closes: https://sashiko.dev/#/bug/linux-92046c21-e0a8-4274-a502-20ca723131b1
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 107 ++++++++++++++++++++++++++---------
1 file changed, 80 insertions(+), 27 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 3e34210de4ed..7eb193ca5390 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -42,20 +42,22 @@ MODULE_LICENSE("GPL");
#define ADI_FLAG_HAT 0x04
#define ADI_FLAG_10BIT 0x08
+#define ADI_ID_WMED 0x00
#define ADI_ID_TPD 0x01
+#define ADI_ID_SIDECAR 0x02
+#define ADI_ID_CM2 0x03
+#define ADI_ID_WMI 0x04
+#define ADI_ID_WMF 0x05
#define ADI_ID_WGP 0x06
+#define ADI_ID_WMED3D 0x07
#define ADI_ID_WGPE 0x08
+#define ADI_ID_WGP_USB 0x09
#define ADI_ID_MAX 0x0a
/*
* Names, buttons, axes ...
*/
-static char *adi_names[] = { "WingMan Extreme Digital", "ThunderPad Digital", "SideCar", "CyberMan 2",
- "WingMan Interceptor", "WingMan Formula", "WingMan GamePad",
- "WingMan Extreme Digital 3D", "WingMan GamePad Extreme",
- "WingMan GamePad USB", "Unknown Device %#x" };
-
static char adi_wmgpe_abs[] = { ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y };
static char adi_wmi_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
static char adi_wmed3d_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y };
@@ -67,11 +69,35 @@ static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_B
static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
-static char* adi_abs[] = { adi_wmi_abs, adi_wmgpe_abs, adi_wmf_abs, adi_cm2_abs, adi_wmi_abs, adi_wmf_abs,
- adi_wmgpe_abs, adi_wmed3d_abs, adi_wmgpe_abs, adi_wmgpe_abs, adi_wmi_abs };
+struct adi_model {
+ const char *name;
+ const char *abs;
+ const short *key;
+ unsigned char num_abs;
+ unsigned char num_key;
+};
+
+#define ADI_MODEL(_name, _abs, _key) { \
+ .name = (_name), \
+ .abs = (_abs), \
+ .num_abs = ARRAY_SIZE(_abs), \
+ .key = (_key), \
+ .num_key = ARRAY_SIZE(_key), \
+}
-static short* adi_key[] = { adi_wmi_key, adi_wmgpe_key, adi_cm2_key, adi_cm2_key, adi_wmi_key, adi_cm2_key,
- adi_wmgpe_key, adi_wmed3d_key, adi_wmgpe_key, adi_wmgpe_key, adi_wmi_key };
+static const struct adi_model adi_models[] = {
+ [ADI_ID_WMED] = ADI_MODEL("WingMan Extreme Digital", adi_wmi_abs, adi_wmi_key),
+ [ADI_ID_TPD] = ADI_MODEL("ThunderPad Digital", adi_wmgpe_abs, adi_wmgpe_key),
+ [ADI_ID_SIDECAR] = ADI_MODEL("SideCar", adi_wmf_abs, adi_cm2_key),
+ [ADI_ID_CM2] = ADI_MODEL("CyberMan 2", adi_cm2_abs, adi_cm2_key),
+ [ADI_ID_WMI] = ADI_MODEL("WingMan Interceptor", adi_wmi_abs, adi_wmi_key),
+ [ADI_ID_WMF] = ADI_MODEL("WingMan Formula", adi_wmf_abs, adi_cm2_key),
+ [ADI_ID_WGP] = ADI_MODEL("WingMan GamePad", adi_wmgpe_abs, adi_wmgpe_key),
+ [ADI_ID_WMED3D] = ADI_MODEL("WingMan Extreme Digital 3D", adi_wmed3d_abs, adi_wmed3d_key),
+ [ADI_ID_WGPE] = ADI_MODEL("WingMan GamePad Extreme", adi_wmgpe_abs, adi_wmgpe_key),
+ [ADI_ID_WGP_USB] = ADI_MODEL("WingMan GamePad USB", adi_wmgpe_abs, adi_wmgpe_key),
+ [ADI_ID_MAX] = ADI_MODEL("Unknown Device %#x", adi_wmi_abs, adi_wmi_key),
+};
/*
* Hat to axis conversion arrays.
@@ -97,8 +123,7 @@ struct adi {
char axes8;
signed char pad;
char hats;
- char *abs;
- short *key;
+ const struct adi_model *model;
char name[ADI_MAX_NAME_LENGTH];
char cname[ADI_MAX_CNAME_LENGTH];
char phys[ADI_MAX_PHYS_LENGTH];
@@ -112,6 +137,11 @@ struct adi_port {
int reads;
};
+static int adi_num_axes(const struct adi *adi)
+{
+ return adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2;
+}
+
/*
* adi_read_packet() reads a Logitech ADI packet.
*/
@@ -211,8 +241,8 @@ static inline int adi_get_bits(struct adi *adi, int count)
static int adi_decode(struct adi *adi)
{
struct input_dev *dev = adi->dev;
- char *abs = adi->abs;
- short *key = adi->key;
+ const char *abs = adi->model->abs;
+ const short *key = adi->model->key;
int i, t;
if (adi->ret < adi->length || adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4)))
@@ -324,6 +354,8 @@ static void adi_init_digital(struct gameport *gameport)
static void adi_id_decode(struct adi *adi, struct adi_port *port)
{
+ struct device *dev = &port->gameport->dev;
+ const struct adi_model *model;
int i, t;
if (adi->ret < ADI_MIN_ID_LENGTH) /* Minimum ID packet length */
@@ -361,6 +393,12 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
i = adi_get_bits(adi, 4);
if (t & ADI_FLAG_10BIT) {
+ if (i > adi->axes8) {
+ dev_warn(dev, "Bad 10-bit axis count (%d > %d)\n",
+ i, adi->axes8);
+ adi->length = 0;
+ return;
+ }
adi->axes10 = adi->axes8 - i;
adi->axes8 = i;
}
@@ -381,37 +419,52 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
switch (adi->id) {
case ADI_ID_TPD:
adi->pad = 4;
- adi->buttons -= 4;
break;
case ADI_ID_WGP:
adi->pad = 0;
- adi->buttons -= 4;
break;
default:
adi->pad = -1;
break;
}
+
+ if (adi->pad >= 0) {
+ if (adi->buttons <= adi->pad + 4) {
+ dev_warn(dev, "Invalid button count %d for pad %d\n",
+ adi->buttons, adi->pad);
+ adi->length = 0;
+ return;
+ }
+ adi->buttons -= 4;
+ }
+
+ model = &adi_models[adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX];
+ if (adi_num_axes(adi) > model->num_abs || adi->buttons > model->num_key) {
+ dev_warn(dev,
+ "Model %#x reports too many axes (%d, max %d) or buttons (%d, max %d)\n",
+ adi->id, adi_num_axes(adi), model->num_abs,
+ adi->buttons, model->num_key);
+ adi->length = 0;
+ return;
+ }
+
+ adi->model = model;
}
static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
{
struct input_dev *input_dev;
char buf[ADI_MAX_NAME_LENGTH];
- int i, t;
+ int i;
adi->dev = input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
- t = adi->id < ADI_ID_MAX ? adi->id : ADI_ID_MAX;
-
- snprintf(buf, ADI_MAX_PHYS_LENGTH, adi_names[t], adi->id);
+ snprintf(buf, ADI_MAX_PHYS_LENGTH, adi->model->name, adi->id);
scnprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half);
- adi->abs = adi_abs[t];
- adi->key = adi_key[t];
-
input_dev->name = adi->name;
input_dev->phys = adi->phys;
input_dev->id.bustype = BUS_GAMEPORT;
@@ -427,11 +480,11 @@ static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
- for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++)
- set_bit(adi->abs[i], input_dev->absbit);
+ for (i = 0; i < adi_num_axes(adi); i++)
+ set_bit(adi->model->abs[i], input_dev->absbit);
for (i = 0; i < adi->buttons; i++)
- set_bit(adi->key[i], input_dev->keybit);
+ set_bit(adi->model->key[i], input_dev->keybit);
return 0;
}
@@ -443,9 +496,9 @@ static void adi_init_center(struct adi *adi)
if (!adi->length)
return;
- for (i = 0; i < adi->axes10 + adi->axes8 + (adi->hats + (adi->pad != -1)) * 2; i++) {
+ for (i = 0; i < adi_num_axes(adi); i++) {
- t = adi->abs[i];
+ t = adi->model->abs[i];
x = input_abs_get_val(adi->dev, t);
if (t == ABS_THROTTLE || t == ABS_RUDDER || adi->id == ADI_ID_WGPE)
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 4/8] Input: adi - use explicit fixed-width types and const tables
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
` (2 preceding siblings ...)
2026-11-30 5:42 ` [PATCH 3/8] Input: adi - validate ID packet axis and button counts Dmitry Torokhov
@ 2026-11-30 5:42 ` Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 5/8] Input: adi - simplify device name formatting Dmitry Torokhov
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
Use explicit fixed-width u8/s8 types for the wire-decoded fields and
packet buffer in struct adi so signedness does not depend on
architecture or compiler flags. Qualify the static input code tables
as const and use unsigned char and unsigned short for the tables and
corresponding model pointers.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 40 ++++++++++++++++++------------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 7eb193ca5390..a016a73cca27 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -58,21 +58,21 @@ MODULE_LICENSE("GPL");
* Names, buttons, axes ...
*/
-static char adi_wmgpe_abs[] = { ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y };
-static char adi_wmi_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
-static char adi_wmed3d_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y };
-static char adi_cm2_abs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
-static char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
+static const unsigned char adi_wmgpe_abs[] = { ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y };
+static const unsigned char adi_wmi_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
+static const unsigned char adi_wmed3d_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y };
+static const unsigned char adi_cm2_abs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
+static const unsigned char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
-static short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT };
-static short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA };
-static short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
-static short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
+static const unsigned short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT };
+static const unsigned short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA };
+static const unsigned short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
+static const unsigned short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
struct adi_model {
const char *name;
- const char *abs;
- const short *key;
+ const unsigned char *abs;
+ const unsigned short *key;
unsigned char num_abs;
unsigned char num_key;
};
@@ -117,17 +117,17 @@ struct adi {
int length;
int ret;
int idx;
- unsigned char id;
- char buttons;
- char axes10;
- char axes8;
- signed char pad;
- char hats;
+ u8 id;
+ u8 buttons;
+ u8 axes10;
+ u8 axes8;
+ s8 pad;
+ u8 hats;
const struct adi_model *model;
char name[ADI_MAX_NAME_LENGTH];
char cname[ADI_MAX_CNAME_LENGTH];
char phys[ADI_MAX_PHYS_LENGTH];
- unsigned char data[ADI_MAX_LENGTH];
+ u8 data[ADI_MAX_LENGTH];
};
struct adi_port {
@@ -241,8 +241,8 @@ static inline int adi_get_bits(struct adi *adi, int count)
static int adi_decode(struct adi *adi)
{
struct input_dev *dev = adi->dev;
- const char *abs = adi->model->abs;
- const short *key = adi->model->key;
+ const unsigned char *abs = adi->model->abs;
+ const unsigned short *key = adi->model->key;
int i, t;
if (adi->ret < adi->length || adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4)))
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5/8] Input: adi - simplify device name formatting
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
` (3 preceding siblings ...)
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 ` Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 6/8] Input: adi - use dev_warn() in adi_id_decode() Dmitry Torokhov
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
Currently adi_init_input() formats the device name in two steps through
a temporary stack buffer, passing the model name string as a non-literal
format argument and mistakenly bounding that buffer with the physical
path length constant instead of the buffer's own size.
Set the unknown-model entry's name to NULL and format directly into the
device name buffer using literal format strings based on whether a
model name is present, removing the intermediate stack buffer while
preserving the resulting device names.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index a016a73cca27..34febfc54ae3 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -96,7 +96,7 @@ static const struct adi_model adi_models[] = {
[ADI_ID_WMED3D] = ADI_MODEL("WingMan Extreme Digital 3D", adi_wmed3d_abs, adi_wmed3d_key),
[ADI_ID_WGPE] = ADI_MODEL("WingMan GamePad Extreme", adi_wmgpe_abs, adi_wmgpe_key),
[ADI_ID_WGP_USB] = ADI_MODEL("WingMan GamePad USB", adi_wmgpe_abs, adi_wmgpe_key),
- [ADI_ID_MAX] = ADI_MODEL("Unknown Device %#x", adi_wmi_abs, adi_wmi_key),
+ [ADI_ID_MAX] = ADI_MODEL(NULL, adi_wmi_abs, adi_wmi_key),
};
/*
@@ -454,15 +454,19 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
{
struct input_dev *input_dev;
- char buf[ADI_MAX_NAME_LENGTH];
int i;
adi->dev = input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
- snprintf(buf, ADI_MAX_PHYS_LENGTH, adi->model->name, adi->id);
- scnprintf(adi->name, ADI_MAX_NAME_LENGTH, "Logitech %s [%s]", buf, adi->cname);
+ if (adi->model->name)
+ scnprintf(adi->name, sizeof(adi->name),
+ "Logitech %s [%s]", adi->model->name, adi->cname);
+ else
+ scnprintf(adi->name, sizeof(adi->name),
+ "Logitech Unknown Device %#x [%s]",
+ adi->id, adi->cname);
snprintf(adi->phys, ADI_MAX_PHYS_LENGTH, "%s/input%d", port->gameport->phys, half);
input_dev->name = adi->name;
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 6/8] Input: adi - use dev_warn() in adi_id_decode()
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
` (4 preceding siblings ...)
2026-11-30 5:42 ` [PATCH 5/8] Input: adi - simplify device name formatting Dmitry Torokhov
@ 2026-11-30 5:42 ` Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 7/8] Input: adi - use BIT() and GENMASK() for bitmasks and bit checks Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 8/8] Input: adi - clean up formatting Dmitry Torokhov
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
Convert the remaining printk(KERN_WARNING) calls in adi_id_decode() to
dev_warn() against the gameport device, dropping the manual driver name
prefix.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 34febfc54ae3..6eb8dabda4e5 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -362,7 +362,8 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
return;
if (adi->ret < (t = adi_get_bits(adi, 10))) {
- printk(KERN_WARNING "adi: Short ID packet: reported: %d != read: %d\n", t, adi->ret);
+ dev_warn(dev, "Short ID packet: reported: %d != read: %d\n",
+ t, adi->ret);
return;
}
@@ -373,7 +374,7 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
adi->length = adi_get_bits(adi, 10);
if (adi->length >= ADI_MAX_LENGTH || adi->length < ADI_MIN_LENGTH) {
- printk(KERN_WARNING "adi: Bad data packet length (%d).\n", adi->length);
+ dev_warn(dev, "Bad data packet length (%d).\n", adi->length);
adi->length = 0;
return;
}
@@ -382,7 +383,7 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
adi->buttons = adi_get_bits(adi, 6);
if (adi_get_bits(adi, 6) != 8 && adi->hats) {
- printk(KERN_WARNING "adi: Other than 8-dir POVs not supported yet.\n");
+ dev_warn(dev, "Other than 8-dir POVs not supported yet.\n");
adi->length = 0;
return;
}
@@ -411,7 +412,8 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
t = 8 + adi->buttons + adi->axes10 * 10 + adi->axes8 * 8 + adi->hats * 4;
if (adi->length != t && adi->length != t + (t & 1)) {
- printk(KERN_WARNING "adi: Expected length %d != data length %d\n", t, adi->length);
+ dev_warn(dev, "Expected length %d != data length %d\n",
+ t, adi->length);
adi->length = 0;
return;
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 7/8] Input: adi - use BIT() and GENMASK() for bitmasks and bit checks
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
` (5 preceding siblings ...)
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
2026-11-30 5:42 ` [PATCH 8/8] Input: adi - clean up formatting Dmitry Torokhov
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 8/8] Input: adi - clean up formatting
2026-11-30 5:42 [PATCH 0/8] Input: adi - bounds checking fixes and driver cleanups Dmitry Torokhov
` (6 preceding siblings ...)
2026-11-30 5:42 ` [PATCH 7/8] Input: adi - use BIT() and GENMASK() for bitmasks and bit checks Dmitry Torokhov
@ 2026-11-30 5:42 ` Dmitry Torokhov
7 siblings, 0 replies; 9+ messages in thread
From: Dmitry Torokhov @ 2026-11-30 5:42 UTC (permalink / raw)
To: linux-input; +Cc: Lee Jones, Vojtech Pavlik, Guanglei Zhu, linux-kernel
Wrap the static capability and hat-mapping tables within 80 columns,
add missing blank lines between declarations, move assignments out of
conditionals, split single-line statements and chained assignments onto
separate lines, balance braces and remove redundant void return
statements, and fix switch, conditional, and error-label indentation.
No functional changes intended.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/joystick/adi.c | 129 ++++++++++++++++++++++++-----------
1 file changed, 90 insertions(+), 39 deletions(-)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 787af165db2a..9d461734a3d1 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -61,16 +61,46 @@ MODULE_LICENSE("GPL");
* Names, buttons, axes ...
*/
-static const unsigned char adi_wmgpe_abs[] = { ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y };
-static const unsigned char adi_wmi_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
-static const unsigned char adi_wmed3d_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y };
-static const unsigned char adi_cm2_abs[] = { ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ };
-static const unsigned char adi_wmf_abs[] = { ABS_WHEEL, ABS_GAS, ABS_BRAKE, ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y };
+static const unsigned char adi_wmgpe_abs[] = {
+ ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y
+};
+
+static const unsigned char adi_wmi_abs[] = {
+ ABS_X, ABS_Y, ABS_THROTTLE,
+ ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y
+};
+
+static const unsigned char adi_wmed3d_abs[] = {
+ ABS_X, ABS_Y, ABS_THROTTLE, ABS_RZ, ABS_HAT0X, ABS_HAT0Y
+};
+
+static const unsigned char adi_cm2_abs[] = {
+ ABS_X, ABS_Y, ABS_Z, ABS_RX, ABS_RY, ABS_RZ
+};
-static const unsigned short adi_wmgpe_key[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT };
-static const unsigned short adi_wmi_key[] = { BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA };
-static const unsigned short adi_wmed3d_key[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2 };
-static const unsigned short adi_cm2_key[] = { BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8 };
+static const unsigned char adi_wmf_abs[] = {
+ ABS_WHEEL, ABS_GAS, ABS_BRAKE,
+ ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y, ABS_HAT2X, ABS_HAT2Y
+};
+
+static const unsigned short adi_wmgpe_key[] = {
+ BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,
+ BTN_TL, BTN_TR, BTN_START, BTN_MODE, BTN_SELECT
+};
+
+static const unsigned short adi_wmi_key[] = {
+ BTN_TRIGGER, BTN_TOP, BTN_THUMB, BTN_TOP2,
+ BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4, BTN_EXTRA
+};
+
+static const unsigned short adi_wmed3d_key[] = {
+ BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2,
+ BTN_BASE, BTN_BASE2
+};
+
+static const unsigned short adi_cm2_key[] = {
+ BTN_1, BTN_2, BTN_3, BTN_4, BTN_5, BTN_6, BTN_7, BTN_8
+};
struct adi_model {
const char *name;
@@ -109,7 +139,10 @@ static const struct adi_model adi_models[] = {
static struct {
int x;
int y;
-} adi_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}};
+} adi_hat_to_axis[] = {
+ { 0, 0 }, { 0, -1 }, { 1, -1 }, { 1, 0 }, { 1, 1 },
+ { 0, 1 }, { -1, 1 }, { -1, 0 }, { -1, -1 }
+};
/*
* Per-port information.
@@ -178,14 +211,16 @@ static void adi_read_packet(struct adi_port *port)
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 & ADI_STROBE_MASK)) s[i] = 1;
+ } else {
+ t[i] = 0;
+ }
+ } else if (!(x & ADI_STROBE_MASK)) {
+ s[i] = 1;
+ }
}
} while (t[0] > 0 || t[1] > 0);
local_irq_restore(flags);
-
- return;
}
/*
@@ -195,13 +230,16 @@ static void adi_read_packet(struct adi_port *port)
static void adi_move_bits(struct adi_port *port, int length)
{
- int i, offset;
struct adi *adi = port->adi;
+ int i, offset;
- adi[0].idx = adi[1].idx = 0;
+ adi[0].idx = 0;
+ adi[1].idx = 0;
- if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
- if (adi[0].data[0] & ADI_DATA_BIT || !(adi[1].data[0] & ADI_DATA_BIT)) return;
+ if (adi[0].ret <= 0 || adi[1].ret <= 0)
+ return;
+ if (adi[0].data[0] & ADI_DATA_BIT || !(adi[1].data[0] & ADI_DATA_BIT))
+ return;
if (length <= 0)
goto err_out;
@@ -231,7 +269,11 @@ static inline int adi_get_bits(struct adi *adi, int count)
{
int bits = 0;
int i;
- if ((adi->idx += count) > adi->ret) return 0;
+
+ adi->idx += count;
+ if (adi->idx > adi->ret)
+ return 0;
+
for (i = 0; i < count; i++)
bits |= !!(adi->data[adi->idx - i] & ADI_DATA_BIT) << i;
return bits;
@@ -248,7 +290,8 @@ static int adi_decode(struct adi *adi)
const unsigned short *key = adi->model->key;
int i, t;
- if (adi->ret < adi->length || adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4)))
+ if (adi->ret < adi->length ||
+ adi->id != (adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4)))
return -1;
for (i = 0; i < adi->axes10; i++)
@@ -267,7 +310,9 @@ static int adi_decode(struct adi *adi)
}
for (i = 0; i < adi->hats; i++) {
- if ((t = adi_get_bits(adi, 4)) > 8) t = 0;
+ t = adi_get_bits(adi, 4);
+ if (t > 8)
+ t = 0;
input_report_abs(dev, *abs++, adi_hat_to_axis[t].x);
input_report_abs(dev, *abs++, adi_hat_to_axis[t].y);
}
@@ -294,7 +339,7 @@ static int adi_read(struct adi_port *port)
for (i = 0; i < 2; i++)
if (port->adi[i].length)
- result |= adi_decode(port->adi + i);
+ result |= adi_decode(port->adi + i);
return result;
}
@@ -350,7 +395,7 @@ static void adi_init_digital(struct gameport *gameport)
msleep(seq[i]);
if (seq[i] < 0) {
mdelay(-seq[i]);
- udelay(-seq[i]*14); /* It looks like mdelay() is off by approx 1.4% */
+ udelay(-seq[i] * 14); /* It looks like mdelay() is off by approx 1.4% */
}
}
}
@@ -364,7 +409,8 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
if (adi->ret < ADI_MIN_ID_LENGTH) /* Minimum ID packet length */
return;
- if (adi->ret < (t = adi_get_bits(adi, 10))) {
+ t = adi_get_bits(adi, 10);
+ if (adi->ret < t) {
dev_warn(dev, "Short ID packet: reported: %d != read: %d\n",
t, adi->ret);
return;
@@ -372,7 +418,9 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
adi->id = adi_get_bits(adi, 4) | (adi_get_bits(adi, 4) << 4);
- if ((t = adi_get_bits(adi, 4)) & ADI_FLAG_HAT) adi->hats++;
+ t = adi_get_bits(adi, 4);
+ if (t & ADI_FLAG_HAT)
+ adi->hats++;
adi->length = adi_get_bits(adi, 10);
@@ -422,15 +470,15 @@ static void adi_id_decode(struct adi *adi, struct adi_port *port)
}
switch (adi->id) {
- case ADI_ID_TPD:
- adi->pad = 4;
- break;
- case ADI_ID_WGP:
- adi->pad = 0;
- break;
- default:
- adi->pad = -1;
- break;
+ case ADI_ID_TPD:
+ adi->pad = 4;
+ break;
+ case ADI_ID_WGP:
+ adi->pad = 0;
+ break;
+ default:
+ adi->pad = -1;
+ break;
}
if (adi->pad >= 0) {
@@ -461,9 +509,10 @@ static int adi_init_input(struct adi *adi, struct adi_port *port, int half)
struct input_dev *input_dev;
int i;
- adi->dev = input_dev = input_allocate_device();
+ input_dev = input_allocate_device();
if (!input_dev)
return -ENOMEM;
+ adi->dev = input_dev;
if (adi->model->name)
scnprintf(adi->name, sizeof(adi->name),
@@ -506,7 +555,6 @@ static void adi_init_center(struct adi *adi)
return;
for (i = 0; i < adi_num_axes(adi); i++) {
-
t = adi->model->abs[i];
x = input_abs_get_val(adi->dev, t);
@@ -585,16 +633,19 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
return 0;
- fail3: while (--i >= 0) {
+fail3:
+ while (--i >= 0) {
if (port->adi[i].length > 0) {
input_unregister_device(port->adi[i].dev);
port->adi[i].dev = NULL;
}
}
- fail2: for (i = 0; i < 2; i++)
+fail2:
+ for (i = 0; i < 2; i++)
input_free_device(port->adi[i].dev);
gameport_close(gameport);
- fail1: gameport_set_drvdata(gameport, NULL);
+fail1:
+ gameport_set_drvdata(gameport, NULL);
kfree(port);
return err;
}
--
2.56.1.839.g22a8290db9-goog
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-30 5:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 7/8] Input: adi - use BIT() and GENMASK() for bitmasks and bit checks Dmitry Torokhov
2026-11-30 5:42 ` [PATCH 8/8] Input: adi - clean up formatting Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®