Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael Zaidman" <michael.zaidman@gmail.com>
Cc: linux-input@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-gpio@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v4 11/16] HID: ft260: workaround for TN_189 errata endpoint STALL after enumeration
Date: Tue, 17 Nov 2026 20:50:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-219658@kernel.org> (raw)
In-Reply-To: <20261117200423.19561-12-michael.zaidman@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: ft260: race between ft260_reset_and_rebind() and
  ft260_probe()
--

commit 4f2501f4550a54da3c0f10a72785d9919d317381
Author: Michael Zaidman <michael.zaidman@gmail.com>

HID: ft260: workaround for TN_189 errata endpoint STALL after enumeration

This commit adds a workaround for the FT260 TN_189 silicon errata by
checking interrupt IN endpoint health and device responsiveness during
probe, and scheduling a deferred USB device reset and interface rebind
when either check fails.

Link: https://ftdichip.com/wp-content/uploads/2026/05/TN_189-FT260-Errata-Technical-Note.pdf

> diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
> index e708b1be734c7..096e46836d743 100644
> --- a/drivers/hid/hid-ft260.c
> +++ b/drivers/hid/hid-ft260.c

[ ... ]

> @@ -2504,15 +2566,276 @@ static int ft260_uart_probe(struct ft260_device *dev,

[ ... ]

> +static void ft260_reset_and_rebind(struct work_struct *ws)
> +{

[ ... ]

> +	/*
> +	 * usb_reset_device() keeps usbhid bound (its pre_reset/post_reset
> +	 * both return 0) and does not re-trigger HID-level driver probing.
> +	 * Unbind all USB interfaces, reset, and bind them again to force
> +	 * usbhid to destroy stale HID devices and create new ones, which
> +	 * triggers fresh ft260_probe() calls. Unbind before the reset: it
> +	 * waits for a probe still running on either interface, so the
> +	 * reset does not run while that probe stops usbhid.
> +	 */
> +	actconfig = usbdev->actconfig;
> +	for (i = 0; actconfig && i < actconfig->desc.bNumInterfaces; i++) {
> +		struct usb_interface *intf = actconfig->interface[i];
> +
> +		if (intf && intf->dev.driver)
> +			device_release_driver(&intf->dev);
> +	}

[ ... ]

> +static int ft260_check_intr_ep_health(struct hid_device *hdev)
> +{

[ ... ]

> +	pipe = usb_rcvintpipe(usbdev, ep->bEndpointAddress);
> +	ret = usb_interrupt_msg(usbdev, pipe, buf, FT260_REPORT_MAX_LEN,
> +				&actual_length, 100);
> +	kfree(buf);
> +
> +	if (ret == -EPIPE) {
> +		hid_warn(hdev,
> +			 "interrupt IN ep %#x halted (TN_189 errata), scheduling USB reset and rebind\n",
> +			 ep->bEndpointAddress);
> +		return -ENODEV;
> +	}
> +
> +	return 0;
> +}

[ ... ]

> @@ -2540,6 +2869,27 @@ static int ft260_probe(struct hid_device *hdev, const struct hid_device_id *id)
>  		goto hid_fail;
>  	}
>  
> +	/*
> +	 * TN_189 errata workaround: bail out fast on a broken device so
> +	 * that hub_event releases the device lock quickly, allowing the
> +	 * scheduled reset work to acquire it and recover the device.
> +	 */
> +	ret = ft260_check_intr_ep_health(hdev);
> +	if (ret == -ENODEV) {
> +		ft260_schedule_reset(usbif);
> +		goto err_hid_stop;
> +	}

[Severity: Medium]
Can ft260_reset_and_rebind() race with an active ft260_probe() when the
driver is bound outside USB enumeration?

Unlike usb_bus_type, hid_bus_type does not set need_parent_lock.  When
hid-ft260 is loaded after hid-generic has already bound during USB
enumeration (or when reprobed via sysfs), hid_register_driver() probes the
two HID interfaces holding only device_lock(&hdev->dev), without holding
usb_lock_device(usbdev) or device_lock(&intf->dev).

When the first interface (hid0) detects a stalled endpoint and schedules
the reset work, ft260_reset_and_rebind() immediately acquires
usb_lock_device_for_reset() and calls device_release_driver(&intf->dev).
That enters usb_unbind_interface() and usbhid_disconnect() before
device_del(&hdev->dev) waits on device_lock(&hdev->dev):

CPU0 (modprobe hid-ft260)           CPU1 (ft260_reset_wq)
ft260_probe(hid0)
  ft260_check_intr_ep_health(hid0)
  ft260_schedule_reset()
  hid_hw_stop(hid0)
ft260_probe(hid1)
                                    ft260_reset_and_rebind()
                                      usb_lock_device_for_reset(usbdev)
                                      device_release_driver(&intf1->dev)
                                        usb_unbind_interface(intf1)
                                          usb_disable_interface(intf1)
                                          usbhid_disconnect(intf1)
                                            set_bit(HID_DISCONNECTED, ...)
                                            ...
                                            device_del(&hid1->dev)
                                              /* blocks on hid1 lock */
  hid_hw_start(hid1, 0)
    usbhid_start(hid1)
      clear_bit(HID_DISCONNECTED)
  ft260_check_intr_ep_health(hid1)
    usb_interrupt_msg() -> -ENOENT
    returns 0
  ft260_check_dev_responsive(hid1)
    usb_control_msg(ep0) -> 0
  hid_hw_open(hid1)                 <-- arms io_retry on disconnecting hid1

Because usb_disable_interface() has already disabled the interrupt IN
endpoint on intf1, usb_interrupt_msg() fails with -ENOENT, which
ft260_check_intr_ep_health() ignores because it only checks for -EPIPE.
When only the interrupt endpoints are halted under TN_189, ep0 still
answers USB_REQ_GET_STATUS, so ft260_probe(hid1) continues through
hid_hw_open() (with HID_DISCONNECTED cleared by usbhid_start()) and
registers the subdevices on a half-disconnected hid_device.  On hid0,
usb_disable_interface() and hid_bpf_destroy_device() can also run
concurrently with hid_hw_stop(hid0) if the work starts before hid0 finishes
unwinding.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117200423.19561-1-michael.zaidman@gmail.com?part=11

  reply	other threads:[~2026-11-17 20:50 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 20:04 [PATCH v4 00/16] HID: ft260: add UART and GPIO support, plus I2C fixes Michael Zaidman
2026-11-17 20:04 ` [PATCH v4 01/16] HID: ft260: add serial driver Michael Zaidman
2026-11-17 20:32   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 02/16] HID: ft260: uart: fix " Michael Zaidman
2026-11-17 20:49   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 03/16] HID: ft260: add GPIO support Michael Zaidman
2026-11-17 20:23   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 04/16] HID: ft260: i2c: reduce driver module loading time Michael Zaidman
2026-11-17 20:11   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 05/16] HID: ft260: fix sysfs store failure notice for big numbers Michael Zaidman
2026-11-17 20:12   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 06/16] HID: ft260: i2c: reduce bus-error message severity Michael Zaidman
2026-11-17 20:13   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 07/16] HID: ft260: uart: enable flow control Michael Zaidman
2026-11-17 20:21   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 08/16] HID: ft260: uart: add modem pins control via ioctl Michael Zaidman
2026-11-17 20:24   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 09/16] HID: ft260: group sysfs attrs per HID interface Michael Zaidman
2026-11-17 20:30   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 10/16] HID: ft260: i2c: fix large write transaction failure Michael Zaidman
2026-11-17 20:30   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 11/16] HID: ft260: workaround for TN_189 errata endpoint STALL after enumeration Michael Zaidman
2026-11-17 20:50   ` sashiko-bot [this message]
2026-11-17 20:04 ` [PATCH v4 12/16] HID: ft260: i2c: abort in-flight transfers with STOP before reset Michael Zaidman
2026-11-17 20:33   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 13/16] HID: ft260: i2c: reject an I2C clock outside the supported range Michael Zaidman
2026-11-17 20:34   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 14/16] HID: ft260: i2c: fix i2c_reset sysfs store return value Michael Zaidman
2026-11-17 20:35   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 15/16] HID: ft260: i2c: recover a bus held by a slave Michael Zaidman
2026-11-17 20:44   ` sashiko-bot
2026-11-17 20:04 ` [PATCH v4 16/16] HID: ft260: use lock guards Michael Zaidman
2026-11-17 20:36   ` sashiko-bot

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-219658@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=michael.zaidman@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox