[PATCH] HID: xinmo: prevent NULL pointer dereference in xinmo_event()
From: zhangdaolong
Date: Tue Nov 03 2026 - 01:04:22 EST
In xinmo_event(), field->hidinput->input is accessed when handling out of
bounds negative events. If the device has not been claimed as an input
device or if field->hidinput is NULL (for fields not mapped to an input
device), accessing field->hidinput->input leads to a NULL pointer
dereference.
Add a check for (hdev->claimed & HID_CLAIMED_INPUT) and field->hidinput
before processing events, which matches the standard pattern used across
other HID drivers.
Fixes: cb2c9e3f9248 ("HID: Add new driver for non-compliant Xin-Mo devices.")
Signed-off-by: zhangdaolong <dlzhangak@xxxxxxxxxxxxxx>
---
drivers/hid/hid-xinmo.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/hid/hid-xinmo.c b/drivers/hid/hid-xinmo.c
index 66b8bfb6e647..f308f36bf5a7 100644
--- a/drivers/hid/hid-xinmo.c
+++ b/drivers/hid/hid-xinmo.c
@@ -25,6 +25,9 @@
static int xinmo_event(struct hid_device *hdev, struct hid_field *field,
struct hid_usage *usage, __s32 value)
{
+ if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput)
+ return 0;
+
switch (usage->code) {
case ABS_X:
case ABS_Y:
--
2.48.1