* [PATCH] HID: logitech-hidpp: add raw touchpad support for the K400 Plus
@ 2026-12-05 9:45 Damiano Ognissanti via B4 Relay
2026-12-05 10:03 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Damiano Ognissanti via B4 Relay @ 2026-12-05 9:45 UTC (permalink / raw)
To: Filipe Laíns, Bastien Nocera, Jiri Kosina,
Benjamin Tissoires, Henrik Rydberg
Cc: linux-input, Damiano Ognissanti
From: Damiano Ognissanti <damiano@chalmers.se>
The Logitech K400 Plus (0x404d) is a keyboard with an embedded
touchpad. By default the touchpad is exposed as a relative mouse and
all touch handling (tapping, two-finger scrolling) is done in firmware.
The firmware scrolling only reports whole wheel detents, only starts
after the fingers have moved some distance and ignores slow finger
movements, which makes it hard to control.
The keyboard also supports the HID++ feature 0x6100 (TouchPad Raw XY),
the same feature that is used by the wireless touchpads handled by the
WTP class. In raw mode it reports the absolute position of up to two
fingers (3570x2040 units at 1390 dpi) at about 83 Hz.
The WTP class cannot be reused as is, because it turns the whole HID
device into a touchpad and drops all other usages, while the K400 Plus
also needs its keyboard. Add a K400 Plus class instead, which:
- keeps the regular HID inputs (keyboard and mouse) untouched,
- creates a separate multitouch input node for the touchpad,
- enables raw reporting on connect and on every reconnect,
- hands the touchpad back to the firmware when the driver is removed.
The configuration query and the raw report parsing are shared with the
WTP code. The physical buttons keep being reported through the regular
mouse input.
With this, userspace (libinput) handles the touchpad like any other
touchpad, including smooth two-finger scrolling, tapping and gestures.
Tested on a K400 Plus (firmware RQK 63.02.B0016) paired to a Unifying
receiver (046d:c52b), on v7.3.1: pointer motion, tapping, two-finger
scrolling, the keyboard, and unloading the module (the touchpad goes
back to firmware mode). Also builds without warnings (W=1) on v7.4-rc5.
The code and this changelog were written with an AI coding assistant
(Claude Opus 5.5, by Anthropic), which also analysed raw report dumps
from my keyboard to work out the report format. I reviewed the result
and tested it on my hardware as described above.
Signed-off-by: Damiano Ognissanti <damiano@chalmers.se>
---
This is my first kernel patch, feedback welcome.
---
drivers/hid/hid-logitech-hidpp.c | 182 +++++++++++++++++++++++++++++++++++++++
1 file changed, 182 insertions(+)
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index a170aaf63..ea3a9b094 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -64,6 +64,7 @@ MODULE_PARM_DESC(disable_tap_to_click,
#define HIDPP_QUIRK_CLASS_K400 BIT(2)
#define HIDPP_QUIRK_CLASS_G920 BIT(3)
#define HIDPP_QUIRK_CLASS_K750 BIT(4)
+#define HIDPP_QUIRK_CLASS_K400_PLUS BIT(5)
/* bits 2..20 are reserved for classes */
/* #define HIDPP_QUIRK_CONNECT_EVENTS BIT(21) disabled */
@@ -180,6 +181,7 @@ struct hidpp_scroll_counter {
};
struct hidpp_reprog_control_mapping;
+static struct input_dev *hidpp_allocate_input(struct hid_device *hdev);
struct hidpp_device {
struct hid_device *hid_dev;
@@ -2938,6 +2940,8 @@ struct wtp_data {
u8 maxcontacts;
bool flip_y;
unsigned int resolution;
+ /* separate touchpad input node, only used by the K400 Plus */
+ struct input_dev *tp_input;
};
static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
@@ -3409,6 +3413,169 @@ static int k400_connect(struct hid_device *hdev)
return k400_disable_tap_to_click(hidpp);
}
+/* ------------------------------------------------------------------------- */
+/* Logitech K400 Plus: keyboard with a raw touchpad */
+/* ------------------------------------------------------------------------- */
+
+/*
+ * The K400 Plus normally reports its touchpad as a relative mouse, with
+ * tap, scroll and gesture handling done in firmware. It also supports the
+ * HID++ feature 0x6100 (TouchPad Raw XY), like the T650/T651 touchpads.
+ *
+ * Unlike those, the K400 Plus is a keyboard too, so the regular HID inputs
+ * are kept as they are and the raw touch data is reported on a separate
+ * multitouch input node, so that userspace (libinput) can treat it as a
+ * real touchpad.
+ */
+
+static void k400p_populate_input(struct wtp_data *wd, struct input_dev *input)
+{
+ __set_bit(EV_ABS, input->evbit);
+ __set_bit(EV_KEY, input->evbit);
+
+ input_set_abs_params(input, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
+ input_abs_set_res(input, ABS_MT_POSITION_X, wd->resolution);
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
+ input_abs_set_res(input, ABS_MT_POSITION_Y, wd->resolution);
+
+ /* the physical buttons are reported by the regular mouse input */
+ input_set_capability(input, EV_KEY, BTN_LEFT);
+ input_set_capability(input, EV_KEY, BTN_RIGHT);
+}
+
+static int k400p_create_touchpad(struct hidpp_device *hidpp)
+{
+ struct hid_device *hdev = hidpp->hid_dev;
+ struct wtp_data *wd = hidpp->private_data;
+ struct input_dev *input;
+ int ret;
+
+ input = hidpp_allocate_input(hdev);
+ if (!input)
+ return -ENOMEM;
+
+ input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s Touchpad",
+ hidpp->name);
+ if (!input->name)
+ return -ENOMEM;
+
+ k400p_populate_input(wd, input);
+
+ ret = input_mt_init_slots(input, wd->maxcontacts,
+ INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED);
+ if (ret)
+ return ret;
+
+ ret = input_register_device(input);
+ if (ret)
+ return ret;
+
+ wd->tp_input = input;
+ return 0;
+}
+
+static int k400p_connect(struct hid_device *hdev)
+{
+ struct hidpp_device *hidpp = hid_get_drvdata(hdev);
+ struct wtp_data *wd = hidpp->private_data;
+ int ret;
+
+ if (!wd->x_size) {
+ ret = wtp_get_config(hidpp);
+ if (ret) {
+ hid_err(hdev, "Can not get touchpad config: %d\n", ret);
+ return ret;
+ }
+ }
+
+ if (!wd->tp_input) {
+ ret = k400p_create_touchpad(hidpp);
+ if (ret) {
+ hid_err(hdev, "Can not create touchpad input: %d\n", ret);
+ return ret;
+ }
+ }
+
+ return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
+ true, true);
+}
+
+static void k400p_touch_event(struct wtp_data *wd,
+ struct hidpp_touchpad_raw_xy_finger *finger)
+{
+ struct input_dev *input = wd->tp_input;
+ bool touching = finger->contact_status == 1;
+ int slot;
+
+ if (!finger->finger_id || finger->contact_type)
+ /* no actual data */
+ return;
+
+ slot = input_mt_get_slot_by_key(input, finger->finger_id);
+ if (slot < 0)
+ return;
+
+ input_mt_slot(input, slot);
+ input_mt_report_slot_state(input, MT_TOOL_FINGER, touching);
+ if (touching) {
+ input_event(input, EV_ABS, ABS_MT_POSITION_X, finger->x);
+ input_event(input, EV_ABS, ABS_MT_POSITION_Y,
+ wd->flip_y ? wd->y_size - finger->y : finger->y);
+ }
+}
+
+static int k400p_raw_event(struct hid_device *hdev, u8 *data, int size)
+{
+ struct hidpp_device *hidpp = hid_get_drvdata(hdev);
+ struct wtp_data *wd = hidpp->private_data;
+ struct hidpp_report *report = (struct hidpp_report *)data;
+ struct hidpp_touchpad_raw_xy raw;
+ int i;
+
+ if (!wd || !wd->tp_input || !wd->mt_feature_index)
+ return 0;
+
+ /* size is already checked in hidpp_raw_event. */
+ if (data[0] != REPORT_ID_HIDPP_LONG ||
+ report->fap.feature_index != wd->mt_feature_index ||
+ report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)
+ return 0;
+
+ hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
+
+ for (i = 0; i < 2; i++)
+ k400p_touch_event(wd, &raw.fingers[i]);
+
+ /* fingers not reported in this frame have been lifted */
+ input_mt_sync_frame(wd->tp_input);
+ input_sync(wd->tp_input);
+
+ return 1;
+}
+
+/* Hand the touchpad back to the firmware, e.g. when the module is unloaded. */
+static void k400p_stop_raw(struct hidpp_device *hidpp)
+{
+ struct wtp_data *wd = hidpp->private_data;
+ struct hidpp_report *message;
+
+ if (!wd || !wd->mt_feature_index)
+ return;
+
+ message = kzalloc_obj(struct hidpp_report);
+ if (!message)
+ return;
+
+ /* fire and forget: no answers are received while being removed */
+ message->report_id = REPORT_ID_HIDPP_LONG;
+ message->fap.feature_index = wd->mt_feature_index;
+ message->fap.funcindex_clientid = CMD_TOUCHPAD_SET_RAW_REPORT_STATE |
+ LINUX_KERNEL_SW_ID;
+ message->fap.params[0] = 0;
+ __hidpp_send_report(hidpp->hid_dev, message);
+ kfree(message);
+}
+
/* ------------------------------------------------------------------------- */
/* Logitech G920 Driving Force Racing Wheel for Xbox One */
/* ------------------------------------------------------------------------- */
@@ -4273,6 +4440,8 @@ static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
return wtp_raw_event(hdev, data, size);
else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560)
return m560_raw_event(hdev, data, size);
+ else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS)
+ return k400p_raw_event(hdev, data, size);
return 0;
}
@@ -4491,6 +4660,9 @@ static void hidpp_connect_event(struct work_struct *work)
ret = k400_connect(hdev);
if (ret)
return;
+ } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS) {
+ /* the keyboard keeps working even if this fails */
+ k400p_connect(hdev);
}
if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
@@ -4719,6 +4891,10 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
ret = k400_allocate(hdev);
if (ret)
return ret;
+ } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS) {
+ ret = wtp_allocate(hdev, id);
+ if (ret)
+ return ret;
}
INIT_WORK(&hidpp->work, hidpp_connect_event);
@@ -4830,6 +5006,9 @@ static void hidpp_remove(struct hid_device *hdev)
sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
+ if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS)
+ k400p_stop_raw(hidpp);
+
hid_hw_stop(hdev);
cancel_work_sync(&hidpp->work);
cancel_work_sync(&hidpp->reset_hi_res_work);
@@ -4868,6 +5047,9 @@ static const struct hid_device_id hidpp_devices[] = {
{ /* Keyboard logitech K400 */
LDJ_DEVICE(0x4024),
.driver_data = HIDPP_QUIRK_CLASS_K400 },
+ { /* Keyboard Logitech K400 Plus */
+ LDJ_DEVICE(0x404d),
+ .driver_data = HIDPP_QUIRK_CLASS_K400_PLUS },
{ /* Solar Keyboard Logitech K750 */
LDJ_DEVICE(0x4002),
.driver_data = HIDPP_QUIRK_CLASS_K750 },
---
base-commit: 47d0d5ce3cfca63a04eabcbeef7086d06240ff97
change-id: 20261205-k400plus-09053a83195f
Best regards,
--
Damiano Ognissanti <damiano@chalmers.se>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] HID: logitech-hidpp: add raw touchpad support for the K400 Plus
2026-12-05 9:45 [PATCH] HID: logitech-hidpp: add raw touchpad support for the K400 Plus Damiano Ognissanti via B4 Relay
@ 2026-12-05 10:03 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-05 10:03 UTC (permalink / raw)
To: Damiano Ognissanti; +Cc: linux-input, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [Medium] HID: logitech-hidpp: unused BTN_LEFT/BTN_RIGHT on K400 Plus
touchpad node
- [Medium] HID: logitech-hidpp: unconditional raw mode breaks K400 Plus
mouse default
- [Medium] HID: logitech-hidpp: k400p_stop_raw() races with
hidpp_connect_event()
- [Medium] HID: logitech-hidpp: missing acquire/release ordering on
wd->tp_input
- [Medium] HID: logitech-hidpp: leak devm input_dev and name in
k400p_create_touchpad()
- [Low] HID: logitech-hidpp: k400p_connect() registers input before raw
mode succeeds
- [Low] HID: logitech-hidpp: K400 Plus MT contacts not cleared on
disconnect
--
commit 8d01bffe9e1a34145aae727352972da3d2cb885f
Author: Damiano Ognissanti <damiano@chalmers.se>
HID: logitech-hidpp: add raw touchpad support for the K400 Plus
This commit adds a HIDPP_QUIRK_CLASS_K400_PLUS class to enable HID++
0x6100 raw XY touchpad reporting on the Logitech K400 Plus keyboard and
expose it through a separate multitouch input device.
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> index a170aaf635b0e..ea3a9b094a340 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
[ ... ]
> @@ -3409,6 +3413,169 @@ static int k400_connect(struct hid_device *hdev)
[ ... ]
> +static void k400p_populate_input(struct wtp_data *wd, struct input_dev *input)
> +{
> + __set_bit(EV_ABS, input->evbit);
> + __set_bit(EV_KEY, input->evbit);
> +
> + input_set_abs_params(input, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
> + input_abs_set_res(input, ABS_MT_POSITION_X, wd->resolution);
> + input_set_abs_params(input, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
> + input_abs_set_res(input, ABS_MT_POSITION_Y, wd->resolution);
> +
> + /* the physical buttons are reported by the regular mouse input */
> + input_set_capability(input, EV_KEY, BTN_LEFT);
> + input_set_capability(input, EV_KEY, BTN_RIGHT);
> +}
[Severity: Medium]
Should wd->tp_input advertise BTN_LEFT and BTN_RIGHT when no code path
ever emits them on this device?
k400p_raw_event() only handles HID++ raw XY touch reports, so physical
button clicks stay on the separate regular HID mouse input node.
Splitting contacts and buttons across two evdev nodes breaks userspace
features that correlate both on one device, such as libinput
middle-button emulation, palm detection during clicks, and
click-and-drag.
In wtp_raw_event(), HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS intercepts mouse
report 0x02 and routes BTN_LEFT and BTN_RIGHT onto the touchpad input
node so buttons and contacts share a single device.
> +static int k400p_create_touchpad(struct hidpp_device *hidpp)
> +{
> + struct hid_device *hdev = hidpp->hid_dev;
> + struct wtp_data *wd = hidpp->private_data;
> + struct input_dev *input;
> + int ret;
> +
> + input = hidpp_allocate_input(hdev);
> + if (!input)
> + return -ENOMEM;
> +
> + input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s Touchpad",
> + hidpp->name);
> + if (!input->name)
> + return -ENOMEM;
> +
> + k400p_populate_input(wd, input);
> +
> + ret = input_mt_init_slots(input, wd->maxcontacts,
> + INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED);
> + if (ret)
> + return ret;
> +
> + ret = input_register_device(input);
> + if (ret)
> + return ret;
> +
> + wd->tp_input = input;
> + return 0;
> +}
[Severity: Medium]
Do these error paths leak the devres-managed input_dev and name string
until driver removal?
k400p_create_touchpad() runs from hidpp_connect_event() after probe has
succeeded, so devm allocations attached to &hdev->dev are not freed
until hid_device_remove(). Because wd->tp_input stays NULL and
hidpp_connect_event() ignores k400p_connect() failures, each wireless
reconnect retries k400p_create_touchpad() and can accumulate orphaned
allocations.
Calling input_free_device(input) (as the delayed_input path in
hidpp_connect_event() already does) and devm_kfree(&hdev->dev,
input->name) on error releases them immediately.
> +static int k400p_connect(struct hid_device *hdev)
> +{
> + struct hidpp_device *hidpp = hid_get_drvdata(hdev);
> + struct wtp_data *wd = hidpp->private_data;
> + int ret;
> +
> + if (!wd->x_size) {
> + ret = wtp_get_config(hidpp);
> + if (ret) {
> + hid_err(hdev, "Can not get touchpad config: %d\n", ret);
> + return ret;
> + }
> + }
> +
> + if (!wd->tp_input) {
> + ret = k400p_create_touchpad(hidpp);
> + if (ret) {
> + hid_err(hdev, "Can not create touchpad input: %d\n", ret);
> + return ret;
> + }
> + }
> +
> + return hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
> + true, true);
> +}
[Severity: Low]
Can k400p_connect() leave a non-functional Touchpad input device
registered if enabling raw mode fails?
k400p_create_touchpad() registers wd->tp_input before
hidpp_touchpad_set_raw_report_state() is called, and neither
k400p_connect() nor hidpp_connect_event() logs or rolls back on failure.
If the HID++ command times out or returns an error, userspace sees a
dead touchpad node while the hardware remains in firmware mouse mode.
Enabling raw reporting before registering wd->tp_input avoids this.
Separately, hidpp_connect_event() calls k400p_connect() before
hidpp_get_device_name() updates hidpp->name, so wd->tp_input gets a
different name depending on whether creation succeeds on first connect
or on a later reconnect.
> +static void k400p_touch_event(struct wtp_data *wd,
> + struct hidpp_touchpad_raw_xy_finger *finger)
> +{
> + struct input_dev *input = wd->tp_input;
> + bool touching = finger->contact_status == 1;
> + int slot;
> +
> + if (!finger->finger_id || finger->contact_type)
> + /* no actual data */
> + return;
> +
> + slot = input_mt_get_slot_by_key(input, finger->finger_id);
> + if (slot < 0)
> + return;
> +
> + input_mt_slot(input, slot);
> + input_mt_report_slot_state(input, MT_TOOL_FINGER, touching);
> + if (touching) {
> + input_event(input, EV_ABS, ABS_MT_POSITION_X, finger->x);
> + input_event(input, EV_ABS, ABS_MT_POSITION_Y,
> + wd->flip_y ? wd->y_size - finger->y : finger->y);
> + }
> +}
> +
> +static int k400p_raw_event(struct hid_device *hdev, u8 *data, int size)
> +{
> + struct hidpp_device *hidpp = hid_get_drvdata(hdev);
> + struct wtp_data *wd = hidpp->private_data;
> + struct hidpp_report *report = (struct hidpp_report *)data;
> + struct hidpp_touchpad_raw_xy raw;
> + int i;
> +
> + if (!wd || !wd->tp_input || !wd->mt_feature_index)
> + return 0;
> +
> + /* size is already checked in hidpp_raw_event. */
> + if (data[0] != REPORT_ID_HIDPP_LONG ||
> + report->fap.feature_index != wd->mt_feature_index ||
> + report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY)
> + return 0;
> +
> + hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
> +
> + for (i = 0; i < 2; i++)
> + k400p_touch_event(wd, &raw.fingers[i]);
> +
> + /* fingers not reported in this frame have been lifted */
> + input_mt_sync_frame(wd->tp_input);
> + input_sync(wd->tp_input);
> +
> + return 1;
> +}
[Severity: Medium]
Is there a data race and missing memory ordering on wd->tp_input and
the sibling fields in struct wtp_data?
Because HIDPP_QUIRK_CLASS_K400_PLUS does not set
HIDPP_QUIRK_DELAYED_INIT, HID reports are already active when
hidpp_connect_event() runs on the workqueue:
CPU0 (kworker) CPU1 (<softirq>)
k400p_connect() hidpp_raw_event()
wtp_get_config() k400p_raw_event()
wd->mt_feature_index = ... if (!wd->tp_input) ...
wd->y_size = ...
wd->flip_y = ...
k400p_create_touchpad()
wd->tp_input = input /* sees non-NULL wd->tp_input */
k400p_touch_event()
wd->flip_y, wd->y_size
<-- stale zero values
Because wd->mt_feature_index, wd->flip_y and wd->y_size have no address
dependency on wd->tp_input, a weakly-ordered CPU can observe a non-NULL
wd->tp_input while reading stale values for those fields, corrupting
coordinates or misrouting reports. Publishing wd->tp_input with
smp_store_release() and loading it once with smp_load_acquire() in
k400p_raw_event() orders all prior initialization.
Also, guarding wtp_get_config() only with !wd->x_size allows reconnects
to overwrite struct wtp_data fields concurrently with k400p_raw_event()
if a device reports x_size == 0.
[ ... ]
> @@ -4491,6 +4660,9 @@ static void hidpp_connect_event(struct work_struct *work)
> ret = k400_connect(hdev);
> if (ret)
> return;
> + } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS) {
> + /* the keyboard keeps working even if this fails */
> + k400p_connect(hdev);
> }
>
> if (hidpp->quirks & HIDPP_QUIRK_HIDPP_WHEELS) {
[Severity: Low]
Are active multitouch contacts on wd->tp_input left stuck when the
keyboard disconnects or powers off during a touch?
On RF link loss, hid-logitech-dj only synthesizes null reports for
standard DJ reports, which k400p_raw_event() ignores, and the disconnect
path in hidpp_connect_event() returns without clearing active slots on
wd->tp_input. BTN_TOUCH then stays pressed while disconnected, and on
reconnect a matching finger_id can reuse the stale tracking ID and cause
a cursor jump (or drop the first frame if all slots are stuck active).
Clearing active MT slots on disconnect or reconnect (synchronized with
k400p_raw_event(), which runs under hdev->driver_input_lock) would avoid
stuck contacts.
[ ... ]
> @@ -4830,6 +5006,9 @@ static void hidpp_remove(struct hid_device *hdev)
>
> sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group);
>
> + if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS)
> + k400p_stop_raw(hidpp);
> +
> hid_hw_stop(hdev);
> cancel_work_sync(&hidpp->work);
> cancel_work_sync(&hidpp->reset_hi_res_work);
[Severity: Medium]
Can k400p_stop_raw() race with an already-queued or running
hidpp_connect_event() work item?
hid_device_remove() prevents new work from being scheduled, but
hidpp_remove() calls k400p_stop_raw() before draining hidpp->work and
hidpp->reset_hi_res_work:
CPU0 (rmmod/unbind) CPU1 (kworker)
hidpp_remove() hidpp_connect_event()
k400p_stop_raw() k400p_connect()
__hidpp_send_report(off)
hid_hw_stop()
cancel_work_sync(&hidpp->work) hidpp_touchpad_set_raw_report_state(
..., true, true)
<-- re-enables raw mode
This can leave the touchpad stuck in raw mode and unusable as a firmware
mouse after driver removal. There is also an unsynchronized data race
on wd->mt_feature_index between wtp_get_config() and k400p_stop_raw(),
and k400p_stop_raw() calls __hidpp_send_report() without holding
hidpp->send_mutex while the workers may concurrently transmit under it.
Calling cancel_work_sync(&hidpp->work) and
cancel_work_sync(&hidpp->reset_hi_res_work) before k400p_stop_raw()
closes all three races.
> @@ -4868,6 +5047,9 @@ static const struct hid_device_id hidpp_devices[] = {
> { /* Keyboard logitech K400 */
> LDJ_DEVICE(0x4024),
> .driver_data = HIDPP_QUIRK_CLASS_K400 },
> + { /* Keyboard Logitech K400 Plus */
> + LDJ_DEVICE(0x404d),
> + .driver_data = HIDPP_QUIRK_CLASS_K400_PLUS },
> { /* Solar Keyboard Logitech K750 */
> LDJ_DEVICE(0x4002),
> .driver_data = HIDPP_QUIRK_CLASS_K750 },
[Severity: Medium]
Does unconditionally switching the K400 Plus into raw mode regress
existing users who rely on the firmware mouse default?
Previously, 0x404d operated as a standard relative mouse, and enabling
HID++ 0x6100 raw mode with no opt-out stops relative motion on the
existing mouse node and disables firmware features such as the Fn +
Left Click tap-to-click toggle. Environments without a touchpad stack
like libinput (for example minimal X11 with xf86-input-evdev or VM
evdev passthrough of the mouse node) lose pointer movement.
Note also that raw touchpad mode on another Logitech combo keyboard
was reverted in 5006c1052aaf ("Revert \"HID: logitech-hidpp: support
combo keyboard touchpad TK820\"") due to a firmware bug causing delayed
keys and key-repeat when typing while resting fingers on the touch
sensor; it is worth verifying whether the K400 Plus is unaffected.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-k400plus-v1-1-d829edf99f6b@chalmers.se?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 10:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 9:45 [PATCH] HID: logitech-hidpp: add raw touchpad support for the K400 Plus Damiano Ognissanti via B4 Relay
2026-12-05 10:03 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox