All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rong Zhang" <i@rong.moe>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v5 10/13] HID: haptic: Decouple from hid-multitouch and support other devices
Date: Sun, 29 Nov 2026 18:29:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-239912@kernel.org> (raw)
In-Reply-To: <20261130-hid-haptic-kmod-v5-10-4903f73d8cac@rong.moe>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] HID: haptic: hid_haptic_check_prerequisites() attaches FF to
  unpopulated input
- [Medium] HID: haptic: broken stylus matching on composite
  hid-multitouch devices
--

commit 5e7c8d80793026eea1a44d7350febde68e4e4d18
Author: Rong Zhang <i@rong.moe>

HID: haptic: Decouple from hid-multitouch and support other devices

This commit allows hid-haptic to fall back to selecting an input device
based on collection type or multi-input quirks when the HID driver has
not chosen one, enabling haptic support on devices other than multitouch
touchpads.

Link: https://usb.org/sites/default/files/hutrr63b_-_haptics_page_redline_0.pdf [1]
Link: https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/input-haptics-implementation-guide [2]
Link: https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/haptic-pen-implementation-guide [3]

> diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
> index 84b35ec8365a3..eab7bbaaf504a 100644
> --- a/drivers/hid/hid-haptic.c
> +++ b/drivers/hid/hid-haptic.c
> @@ -566,19 +566,55 @@ static int hid_haptic_init(struct hid_device *hdev, struct hid_haptic_device *ha
>  static int hid_haptic_check_prerequisites(struct hid_device *hdev,
>  					  struct hid_haptic_device *haptic, struct hid_input *hi)
>  {
> +	struct hid_report *report;
> +
>  	if (!haptic->waveform_list_report || !haptic->duration_list_report ||
>  	    !haptic->manual_trigger_report)
>  		return -ENOENT;
>  
> -	if (IS_ERR_OR_NULL(haptic->input_dev))
> -		return PTR_ERR(haptic->input_dev) ?: -EXDEV;
> -
>  	/* Check the prerequisites only. */
>  	if (!hi)
>  		return 1;
>  
> -	if (haptic->input_dev == hi->input)
> -		return 0;
> +	/*
> +	 * Honor the HID driver's choice.
> +	 *
> +	 * If the driver didn't choose an input device or failed its
> +	 * prerequisites check, initialize the haptic device without the
> +	 * integration with the driver.
> +	 */
> +	if (IS_ERR_OR_NULL(haptic->input_dev))
> +		haptic->input_dev = NULL;
> +	else
> +		return haptic->input_dev != hi->input;
> +
> +	/*
> +	 * A Simple Haptic Controller may be either a Collection Application
> +	 * (CA) or a Collection Logical (CL):
> +	 *
> +	 * A CA is a dedicated HID application, i.e., not associated with other
> +	 * HID applications. Choose the first HID input device to attach the FF
> +	 * device, as other FF drivers do. Haptic Mouse usually falls into this
> +	 * category.
> +	 *
> +	 * A CL is contained within another HID application. The HID input
> +	 * device handling the manual trigger report must be the one handling
> +	 * the associated HID application. Haptic Touchpad and Stylus usually
> +	 * fall into this category.
> +	 *
> +	 * When HID_QUIRK_MULTI_INPUT is set, the quirky collection hierarchy
> +	 * makes no sense anyway, so the first input device is chosen instead.
> +	 */
> +	if (haptic->manual_trigger_report->application == HID_HP_SIMPLECONTROLLER ||
> +	    hdev->quirks & HID_QUIRK_MULTI_INPUT) {
> +		if (list_is_first(&hi->list, &hdev->inputs))
> +			return 0;

[Severity: High]
Can this attach the force-feedback device to an unpopulated hid_input?

In hidinput_connect(), hid_haptic_input_configured() runs before
hidinput_has_been_populated() removes and frees empty hid_input entries
from hdev->inputs:

drivers/hid/hid-input.c:hidinput_connect() {
    ...
		if (haptic_ff)
			haptic_ff = hid_haptic_input_configured(hid, hidinput) >= 0;

		if (!hidinput_has_been_populated(hidinput)) {
			/* no need to register an input device not populated */
			hidinput_cleanup_hidinput(hid, hidinput);
			continue;
		}
    ...
}

If the first hid_input in hdev->inputs has no mapped input usages (such
as an unmapped vendor collection or battery report), matching it here
causes hid_haptic_init() to set EV_FF and FF_HAPTIC on hi->input.
hidinput_has_been_populated() then sees EV_FF set and registers an empty,
EV_FF-only input device while leaving the actual input device without
haptic support.  Checking hidinput_has_been_populated(hi) before running
hid_haptic_input_configured() (or inside hid_haptic_check_prerequisites())
would avoid selecting unpopulated hid_input instances.

> +	} else {
> +		list_for_each_entry(report, &hi->reports, hidinput_list) {
> +			if (report == haptic->manual_trigger_report)
> +				return 0;
> +		}
> +	}

[Severity: Medium]
Does matching hi->reports against haptic->manual_trigger_report work for a
haptic stylus on a composite hid-multitouch device?

On composite touchscreen and pen devices bound to hid-multitouch
(HID_QUIRK_INPUT_PER_APP with maxapplication > 1), the pen top-level
collection has application HID_DG_PEN, while its stylus input fields have
physical usage HID_DG_STYLUS.  When hidinput_connect() processes
HID_INPUT_REPORT first, mt_input_mapping() changes hi->application on the
pen hid_input from HID_DG_PEN to HID_DG_STYLUS:

drivers/hid/hid-multitouch.c:mt_input_mapping() {
    ...
	if (field->physical == HID_DG_STYLUS)
		hi->application = HID_DG_STYLUS;
    ...
}

When hidinput_connect() then processes HID_OUTPUT_REPORT,
manual_trigger_report still has report->application == HID_DG_PEN, so
hidinput_match_application() does not match the stylus hid_input (now
HID_DG_STYLUS) and instead allocates a second, unpopulated hid_input for
manual_trigger_report.  Searching hi->reports here then matches that
second hid_input rather than the stylus hid_input, registering a separate
EV_FF-only input device and leaving the stylus input device without haptic
support.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-hid-haptic-kmod-v5-0-4903f73d8cac@rong.moe?part=10

  reply	other threads:[~2026-11-29 18:29 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 17:52 [PATCH v5 00/13] HID: Add hid-plugin framework & convert hid-haptic into a generic plugin Rong Zhang
2026-11-29 17:52 ` [PATCH v5 01/13] HID: haptic: Get rid of input_ff_destroy() in error paths Rong Zhang
2026-11-29 17:52 ` [PATCH v5 02/13] HID: haptic: Fix use-after-free when draining workqueue Rong Zhang
2026-11-29 17:52 ` [PATCH v5 03/13] HID: haptic, multitouch: Check haptic prerequisite properly Rong Zhang
2026-11-29 18:10   ` sashiko-bot
2026-11-29 18:14     ` Rong Zhang
2026-11-29 18:19       ` Rong Zhang
2026-11-29 17:52 ` [PATCH v5 04/13] HID: haptic: Postpone GET_REPORT to init Rong Zhang
2026-11-29 17:52 ` [PATCH v5 05/13] HID: Add hid-plugin framework for loadable plugin modules Rong Zhang
2026-11-29 17:52 ` [PATCH v5 06/13] HID: haptic: Convert to a loadable plugin module Rong Zhang
2026-11-29 17:52 ` [PATCH v5 07/13] HID: haptic: Adopt pr_fmt, dev_fmt and hid_*() printk helpers Rong Zhang
2026-11-29 17:52 ` [PATCH v5 08/13] HID: Add Ordinal page defines Rong Zhang
2026-11-29 17:52 ` [PATCH v5 09/13] HID: haptic: Handle list reports separately and make auto trigger optional Rong Zhang
2026-11-29 17:52 ` [PATCH v5 10/13] HID: haptic: Decouple from hid-multitouch and support other devices Rong Zhang
2026-11-29 18:29   ` sashiko-bot [this message]
2026-11-30 14:20     ` Rong Zhang
2026-11-29 17:52 ` [PATCH v5 11/13] HID: haptic: Add quirk table Rong Zhang
2026-11-29 17:52 ` [PATCH v5 12/13] HID: haptic: Add HID_HAPTIC_QUIRK_NO_RETRIGGER to disable retriggering Rong Zhang
2026-11-29 17:52 ` [PATCH v5 13/13] HID: haptic: Add quirk flag for Logitech MX Master 4 Rong Zhang
2026-12-01 11:07 ` [PATCH v5 00/13] HID: Add hid-plugin framework & convert hid-haptic into a generic plugin Aaron Erhardt
2026-12-01 17:39   ` On the hid-lamparray design (was: Re: [PATCH v5 00/13] HID: Add hid-plugin framework & convert hid-haptic into a generic plugin) Rong Zhang

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-239912@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=i@rong.moe \
    --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.