All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damiano Ognissanti" <damiano@chalmers.se>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2] HID: logitech-hidpp: add raw touchpad support for the K400 Plus
Date: Sat, 05 Dec 2026 17:35:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-251773@kernel.org> (raw)
In-Reply-To: <20261205-k400plus-v2-1-35d4c17d0c9b@chalmers.se>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] HID: logitech-hidpp: dropping HID_GD_MOUSE breaks K400 Plus
  mouse fallback
- [Medium] HID: logitech-hidpp: K400 Plus default mode change and module
  parameter
- [Medium] HID: logitech-hidpp: probe race on hdev->name and raw-mode
  leak on error
- [Low] HID: logitech-hidpp: duplicate WTP logic and K400 Plus fields in
  wtp_data
- [Low] HID: logitech-hidpp: redundant evbit setup and generic
  input_event() use
- [Low] HID: logitech-hidpp: k400p_raw_event() ignores end_of_frame on
  MT sync
--

commit d3f967091f6c14c07b9e166f154750ea441d9ff0
Author: Damiano Ognissanti <damiano@chalmers.se>

HID: logitech-hidpp: add raw touchpad support for the K400 Plus

This commit adds a K400 Plus device class to hid-logitech-hidpp that enables
HID++ 0x6100 raw touchpad reporting on a separate multitouch input device
while dropping the default HID mouse collection, along with a
disable_raw_touchpad module parameter to retain firmware mouse mode.

> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
> index a170aaf635b0e..9e64e35724b04 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -38,6 +38,11 @@ module_param(disable_tap_to_click, bool, 0644);
>  MODULE_PARM_DESC(disable_tap_to_click,
>  	"Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
>  
> +static bool disable_raw_touchpad;
> +module_param(disable_raw_touchpad, bool, 0444);
> +MODULE_PARM_DESC(disable_raw_touchpad,
> +	"Keep the firmware mouse mode for keyboards with a raw touchpad (only on the K400 Plus currently).");

[Severity: Medium]
Does switching the K400 Plus (0x404d) from its default relative HID mouse to
an absolute multitouch touchpad break existing userspace setups on kernel
upgrade?

Previously, 0x404d matched LDJ_DEVICE(HID_ANY_ID) and exposed a standard
EV_REL mouse.  Dropping HID_GD_MOUSE and exposing only an EV_ABS touchpad
regresses pointer support and existing mouse rules on non-libinput setups
(such as HTPC, console/GPM, or minimal X11) unless users pass
disable_raw_touchpad=1.  Adding a global read-only disable_raw_touchpad
parameter also reintroduces a pattern removed in commit cae253d6033d
("Revert "HID: logitech-hidpp: add a module parameter to keep firmware
gestures"").

[ ... ]

> @@ -2938,6 +2945,9 @@ struct wtp_data {
>  	u8 maxcontacts;
>  	bool flip_y;
>  	unsigned int resolution;
> +	/* separate touchpad input node and its lock, only used by the K400 Plus */
> +	struct input_dev *tp_input;
> +	spinlock_t tp_lock;
>  };

[Severity: Low]
Can HIDPP_QUIRK_CLASS_WTP be generalized or share common helpers instead of
adding K400-Plus-only fields to struct wtp_data and duplicating the WTP class
as k400p_*?

Duplicating wtp_allocate(), wtp_populate_input(), wtp_connect(),
wtp_touch_event(), and wtp_raw_event() into a parallel class causes the two
HID++ 0x6100 touchpad paths to diverge in protocol and lifecycle handling.
Commit 3a61e97563d7 ("HID: logitech-hidpp: support combo keyboard touchpad
TK820") previously layered combo-keyboard support onto HIDPP_QUIRK_CLASS_WTP.

[ ... ]

> +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, taken over from the regular mouse report */
> +	input_set_capability(input, EV_KEY, BTN_LEFT);
> +	input_set_capability(input, EV_KEY, BTN_RIGHT);
> +}

[Severity: Low]
This isn't a bug, but __set_bit(EV_ABS, input->evbit) and
__set_bit(EV_KEY, input->evbit) are redundant here because
input_set_abs_params() and input_set_capability() already set those bits.
Similarly, k400p_touch_event() uses generic input_event(input, EV_ABS, ...)
where input_report_abs() is preferred.

[ ... ]

> +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",
> +				     hdev->name);

[Severity: Medium]
Can this race with hidpp_unifying_init() updating hdev->name during probe?

In hidpp_probe(), hid_device_io_start(hdev) allows incoming HID++ reports
before hidpp_unifying_init() writes hdev->name and before hid_connect() runs.
If a Unifying 0x41 connect notification arrives in that window,
hidpp_raw_hidpp_event() schedules hidpp->work concurrently:

CPU0                              CPU1
hidpp_probe()
  hid_device_io_start(hdev)
                                  hidpp_raw_hidpp_event()
                                    schedule_work(&hidpp->work)
  hidpp_unifying_init(hidpp)      hidpp_connect_event()
    snprintf(hdev->name, ...)       k400p_connect()
                                      k400p_create_touchpad()
                                        devm_kasprintf(..., hdev->name)
                                          <-- data race on hdev->name

That unlocked race can leave the touchpad permanently registered with a
torn, truncated, or placeholder name.

In the same window, if k400p_connect() enables raw mode and hid_connect()
then fails, the hid_hw_init_fail error path in hidpp_probe() calls
hid_hw_stop() before cancel_work_sync(&hidpp->work) and never calls
k400p_stop_raw(), leaving the touchpad stuck in raw mode after probe failure.

[ ... ]

> +	case REPORT_ID_HIDPP_LONG:
> +		/* size is already checked in hidpp_raw_event. */
> +		if (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);
> +
> +		spin_lock_irqsave(&wd->tp_lock, flags);
> +		for (i = 0; i < 2; i++)
> +			k400p_touch_event(wd, input, &raw.fingers[i]);
> +
> +		/* fingers not reported in this frame have been lifted */
> +		input_mt_sync_frame(input);
> +		input_sync(input);
> +		spin_unlock_irqrestore(&wd->tp_lock, flags);
> +		return 1;

[Severity: Low]
Should input_mt_sync_frame() and input_sync() be guarded with
"if (raw.end_of_frame || raw.finger_count <= 2)" as in
wtp_send_raw_xy_event()?

Each HID++ 0x6100 report carries at most two fingers, while k400p_connect()
accepts any non-zero wd->maxcontacts and initializes slots with
INPUT_MT_DROP_UNUSED.  If a firmware revision or another device using this
class reports more than two fingers across multiple packets, syncing
unconditionally on every packet will prematurely drop contacts carried in
the remaining packets of the frame.

[ ... ]

> @@ -4032,6 +4308,10 @@ static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
>  	else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560 &&
>  			field->application != HID_GD_MOUSE)
>  		return m560_input_mapping(hdev, hi, field, usage, bit, max);
> +	else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400_PLUS &&
> +		 field->application == HID_GD_MOUSE)
> +		/* replaced by the touchpad input, see k400p_raw_event() */
> +		return -1;

[Severity: Medium]
Does unconditionally dropping HID_GD_MOUSE here break the fallback to
firmware mouse mode when raw touchpad initialization fails?

hid_connect() runs during probe before hidpp_connect_event() calls
k400p_connect().  If wtp_get_config() or k400p_create_touchpad() fails,
k400p_connect() leaves wd->tp_input NULL and disables raw reporting to return
the hardware to firmware mouse mode, and hidpp_connect_event() ignores the
error.  Because k400p_raw_event() returns 0 when wd->tp_input is NULL and
HID_GD_MOUSE was already unmapped, firmware mouse reports have no input
device and the touchpad produces no pointer or button input at all.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-k400plus-v2-1-35d4c17d0c9b@chalmers.se?part=1

      reply	other threads:[~2026-12-05 17:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 17:18 [PATCH v2] HID: logitech-hidpp: add raw touchpad support for the K400 Plus Damiano Ognissanti
2026-12-05 17:18 ` Damiano Ognissanti via B4 Relay
2026-12-05 17:35 ` sashiko-bot [this message]

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=sashiko-outbox-251773@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damiano@chalmers.se \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.