From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796465026; b=mHnff6/hsbjA9Y2X0/Nh4OpQVSnNBkjHJPeqiPSiqTE7CN0+jZQcVu5weN6xVTM0GM9G yS3odDrYuurjdT9CFisCyrlsrL/+qQl9ZYjGChAYj86kPZujh/fw5Jd0MICctdq3LQEpw /NBfjDRj1zLr08kVp849NRHhc+ZDn/u4WrGUhbW1/RJ8l0xOSl4VvAHdJlxI9N20+nW5j M5/qMBi6ch7MoLqlQ8UssnAZPOqdMYqcPbrCCw9flG29srs6ScZn9l2PjwvESkWGFLLyC C5NqCjXkzIcXAiCd8yL9TEHTcgdI8MuNdG3cdYGnlTZ6O7IpdJI2epe035fIBf8Ai/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796465026; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9hh/4vILBAYKvxLVxRGF3W7d8HhRUqe+SGFXxpEuy7E=; b=iccdw+VGR2sdKV93M1Vqk0FmyyVI6nNx7ZGihL6bBnRFGq8P31skIHL7TU6iRAGdqm+0 smedHuanTFbX6QnRFlihYbTPj09fN2wwI90IZBzarj6wVcskzEa19aPTAWuwJxH1zS0l2 d6mstzz5K1cBYJtiZMs0N/nKxj5A1mbYYcwZ6s9tBKm+dVrOy5kXpVNwVUFJNI9iz+Jgo FGwOetTC2mLCY0W3rFvjlzYUbVuvOy69slj7Vv/090mPt4fzHe0xcukCZpnT6IVJq4dxU TRhiRqeocin8QA1qZP9+05vqbzxbZYFiEcsjrP0ru4kJrPqELmnWn7LsDS2wmjqd23Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T9epcF08; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0824606A322 for ; Sat, 5 Dec 2026 10:03:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=T9epcF08 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 127FE1F0092B; Sat, 5 Dec 2026 10:03:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796465026; bh=9hh/4vILBAYKvxLVxRGF3W7d8HhRUqe+SGFXxpEuy7E=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=T9epcF08VNGh2ZqspuCvFc9ZAgsKfnax85vY9wlm1/ol9wfizJRVxZNspTcPoOFLD OfVb6vkxda9xFjzMznl1Larn7+6VUVjnTFQ+/iZI4WMRbY/Gy2oehnuBBVQoHGu4xb 9vRQ6Edd87Tbkw508M/ObyUzqjoucq5dIxF4naiTQ5eAv/wXwQeSqxYwxKjnWeSw8j u+SkPL3lykphvQNrEK24XYalLV5le3Lp+hkgKkRBzfH+EJ3lbwi+XtMj4g/kWZGCdi TurErW8zW67jIHi1MrhbiBujZHBHSdexDNH1TwE8rnJAVnKYOqQNRlaQ/m+4t9Rkdr qMsY/XEib4eYw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] HID: logitech-hidpp: add raw touchpad support for the K400 Plus Reply-To: sashiko-reviews@lists.linux.dev To: "Damiano Ognissanti" Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261205-k400plus-v1-1-d829edf99f6b@chalmers.se> References: <20261205-k400plus-v1-1-d829edf99f6b@chalmers.se> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 10:03:45 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D hidpp->hid_dev; > + struct wtp_data *wd =3D hidpp->private_data; > + struct input_dev *input; > + int ret; > + > + input =3D hidpp_allocate_input(hdev); > + if (!input) > + return -ENOMEM; > + > + input->name =3D devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s Touchpad", > + hidpp->name); > + if (!input->name) > + return -ENOMEM; > + > + k400p_populate_input(wd, input); > + > + ret =3D input_mt_init_slots(input, wd->maxcontacts, > + INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED); > + if (ret) > + return ret; > + > + ret =3D input_register_device(input); > + if (ret) > + return ret; > + > + wd->tp_input =3D 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 =3D hid_get_drvdata(hdev); > + struct wtp_data *wd =3D hidpp->private_data; > + int ret; > + > + if (!wd->x_size) { > + ret =3D wtp_get_config(hidpp); > + if (ret) { > + hid_err(hdev, "Can not get touchpad config: %d\n", ret); > + return ret; > + } > + } > + > + if (!wd->tp_input) { > + ret =3D 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 =3D wd->tp_input; > + bool touching =3D finger->contact_status =3D=3D 1; > + int slot; > + > + if (!finger->finger_id || finger->contact_type) > + /* no actual data */ > + return; > + > + slot =3D 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 =3D hid_get_drvdata(hdev); > + struct wtp_data *wd =3D hidpp->private_data; > + struct hidpp_report *report =3D (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] !=3D REPORT_ID_HIDPP_LONG || > + report->fap.feature_index !=3D wd->mt_feature_index || > + report->fap.funcindex_clientid !=3D EVENT_TOUCHPAD_RAW_XY) > + return 0; > + > + hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw); > + > + for (i =3D 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 () k400p_connect() hidpp_raw_event() wtp_get_config() k400p_raw_event() wd->mt_feature_index =3D ... if (!wd->tp_input) ... wd->y_size =3D ... wd->flip_y =3D ... k400p_create_touchpad() wd->tp_input =3D 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 =3D=3D 0. [ ... ] > @@ -4491,6 +4660,9 @@ static void hidpp_connect_event(struct work_struct = *work) > ret =3D 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); > } > =20 > 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) > =20 > sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); > =20 > + 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[] = =3D { > { /* Keyboard logitech K400 */ > LDJ_DEVICE(0x4024), > .driver_data =3D HIDPP_QUIRK_CLASS_K400 }, > + { /* Keyboard Logitech K400 Plus */ > + LDJ_DEVICE(0x404d), > + .driver_data =3D HIDPP_QUIRK_CLASS_K400_PLUS }, > { /* Solar Keyboard Logitech K750 */ > LDJ_DEVICE(0x4002), > .driver_data =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-k400plus-v= 1-1-d829edf99f6b@chalmers.se?part=3D1