From 2fad8d241a6833d0c7aeafa0ab596e83c7b4ec9c Mon Sep 17 00:00:00 2001 From: Radhey Shyam Pandey Date: Mon, 28 Sep 2026 17:30:13 +0530 Subject: [PATCH 01/45] usb: dwc3: xilinx: fix system suspend and resume PHY handling System suspend and resume error paths do not handle PHY and clock resources correctly. Suspend calls phy_exit() without first powering off the PHY and ignores failures, while resume can leave clocks enabled if PHY reinitialization fails. Propagate errors to the PM core and unwind resources to ensure a consistent state on suspend and resume failures. Fixes: d6edcdc1ef06 ("usb: dwc3: xilinx: fix usb3 non-wakeup source resume failure") Cc: stable Assisted-by: Claude:claude-opus-5 Signed-off-by: Radhey Shyam Pandey Acked-by: Thinh Nguyen Link: https://patch.msgid.link/20260928120015.3152461-2-radhey.shyam.pandey@amd.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/dwc3-xilinx.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c index b832505e1b04..8c63e02575f1 100644 --- a/drivers/usb/dwc3/dwc3-xilinx.c +++ b/drivers/usb/dwc3/dwc3-xilinx.c @@ -383,13 +383,26 @@ static int __maybe_unused dwc3_xlnx_runtime_idle(struct device *dev) static int __maybe_unused dwc3_xlnx_suspend(struct device *dev) { struct dwc3_xlnx *priv_data = dev_get_drvdata(dev); + int ret; - phy_exit(priv_data->usb3_phy); + ret = phy_power_off(priv_data->usb3_phy); + if (ret < 0) + return ret; + + ret = phy_exit(priv_data->usb3_phy); + if (ret < 0) + goto err_phy_power_on; /* Disable the clocks */ clk_bulk_disable(priv_data->num_clocks, priv_data->clks); return 0; + +err_phy_power_on: + if (phy_power_on(priv_data->usb3_phy)) + dev_err(dev, "failed to restore PHY power after suspend error\n"); + + return ret; } static int __maybe_unused dwc3_xlnx_resume(struct device *dev) @@ -403,15 +416,20 @@ static int __maybe_unused dwc3_xlnx_resume(struct device *dev) ret = phy_init(priv_data->usb3_phy); if (ret < 0) - return ret; + goto err_clk_disable; ret = phy_power_on(priv_data->usb3_phy); if (ret < 0) { phy_exit(priv_data->usb3_phy); - return ret; + goto err_clk_disable; } return 0; + +err_clk_disable: + clk_bulk_disable(priv_data->num_clocks, priv_data->clks); + + return ret; } static const struct dev_pm_ops dwc3_xlnx_dev_pm_ops = { From f33f0dd2eb014bffda02ecfd182de3ddab058596 Mon Sep 17 00:00:00 2001 From: Radhey Shyam Pandey Date: Mon, 28 Sep 2026 17:30:14 +0530 Subject: [PATCH 02/45] usb: dwc3: xilinx: re-assert resets on ZynqMP init error paths If reset deassert or PHY setup fails partway through dwc3_xlnx_init_zynqmp(), re-assert the resets that were already released before unwinding the PHY. Only undo the reset cycle the function actually performed. The cycle is skipped when no usb3-phy is present, because asserting the core resets can break a USB3 configuration that is live but missing from the device tree, so the error path skips it for the same reason. Asserting an already asserted reset is harmless, so one block covers however far the deasserts progressed. Save the ZynqMP reset handles in driver private data so later probe teardown can re-assert released resets. Fixes: 84770f028fab ("usb: dwc3: Add driver for Xilinx platforms") Cc: stable Assisted-by: Claude:claude-opus-5 Signed-off-by: Radhey Shyam Pandey Acked-by: Thinh Nguyen Link: https://patch.msgid.link/20260928120015.3152461-3-radhey.shyam.pandey@amd.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/dwc3-xilinx.c | 55 ++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c index 8c63e02575f1..d2315573b3d3 100644 --- a/drivers/usb/dwc3/dwc3-xilinx.c +++ b/drivers/usb/dwc3/dwc3-xilinx.c @@ -48,6 +48,9 @@ struct dwc3_xlnx { void __iomem *regs; int (*pltfm_init)(struct dwc3_xlnx *data); struct phy *usb3_phy; + struct reset_control *usb_crst; + struct reset_control *usb_hibrst; + struct reset_control *usb_apbrst; }; static void dwc3_xlnx_mask_phy_rst(struct dwc3_xlnx *priv_data, bool mask) @@ -112,7 +115,6 @@ static int dwc3_xlnx_init_versal(struct dwc3_xlnx *priv_data) static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) { struct device *dev = priv_data->dev; - struct reset_control *crst, *hibrst, *apbrst; struct gpio_desc *reset_gpio; int ret = 0; @@ -124,25 +126,25 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) goto err; } - crst = devm_reset_control_get_exclusive(dev, "usb_crst"); - if (IS_ERR(crst)) { - ret = PTR_ERR(crst); + priv_data->usb_crst = devm_reset_control_get_exclusive(dev, "usb_crst"); + if (IS_ERR(priv_data->usb_crst)) { + ret = PTR_ERR(priv_data->usb_crst); dev_err_probe(dev, ret, "failed to get core reset signal\n"); goto err; } - hibrst = devm_reset_control_get_exclusive(dev, "usb_hibrst"); - if (IS_ERR(hibrst)) { - ret = PTR_ERR(hibrst); + priv_data->usb_hibrst = devm_reset_control_get_exclusive(dev, "usb_hibrst"); + if (IS_ERR(priv_data->usb_hibrst)) { + ret = PTR_ERR(priv_data->usb_hibrst); dev_err_probe(dev, ret, "failed to get hibernation reset signal\n"); goto err; } - apbrst = devm_reset_control_get_exclusive(dev, "usb_apbrst"); - if (IS_ERR(apbrst)) { - ret = PTR_ERR(apbrst); + priv_data->usb_apbrst = devm_reset_control_get_exclusive(dev, "usb_apbrst"); + if (IS_ERR(priv_data->usb_apbrst)) { + ret = PTR_ERR(priv_data->usb_apbrst); dev_err_probe(dev, ret, "failed to get APB reset signal\n"); goto err; @@ -156,19 +158,19 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) * absent. */ if (priv_data->usb3_phy) { - ret = reset_control_assert(crst); + ret = reset_control_assert(priv_data->usb_crst); if (ret < 0) { dev_err(dev, "Failed to assert core reset\n"); goto err; } - ret = reset_control_assert(hibrst); + ret = reset_control_assert(priv_data->usb_hibrst); if (ret < 0) { dev_err(dev, "Failed to assert hibernation reset\n"); goto err; } - ret = reset_control_assert(apbrst); + ret = reset_control_assert(priv_data->usb_apbrst); if (ret < 0) { dev_err(dev, "Failed to assert APB reset\n"); goto err; @@ -179,7 +181,7 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) if (ret < 0) goto err; - ret = reset_control_deassert(apbrst); + ret = reset_control_deassert(priv_data->usb_apbrst); if (ret < 0) { dev_err(dev, "Failed to release APB reset\n"); goto err_phy_exit; @@ -195,21 +197,21 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) writel(PIPE_CLK_DESELECT, priv_data->regs + XLNX_USB_FPD_PIPE_CLK); } - ret = reset_control_deassert(crst); + ret = reset_control_deassert(priv_data->usb_crst); if (ret < 0) { dev_err(dev, "Failed to release core reset\n"); - goto err_phy_exit; + goto err_reset_assert; } - ret = reset_control_deassert(hibrst); + ret = reset_control_deassert(priv_data->usb_hibrst); if (ret < 0) { dev_err(dev, "Failed to release hibernation reset\n"); - goto err_phy_exit; + goto err_reset_assert; } ret = phy_power_on(priv_data->usb3_phy); if (ret < 0) - goto err_phy_exit; + goto err_reset_assert; /* ulpi reset via gpio-modepin or gpio-framework driver */ reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); @@ -230,6 +232,21 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) err_phy_power_off: phy_power_off(priv_data->usb3_phy); +err_reset_assert: + /* + * Undo only the reset cycle performed above. That cycle is skipped + * when there is no usb3-phy. The deasserts stay unconditional so a + * core the bootloader left in reset still comes up, but they are + * deliberately not paired with an assert here: resetting a USB3 + * configuration that is live but missing from the device tree could + * break it. Asserting an already asserted reset is harmless, so one + * block covers however far the cycle's deasserts got. + */ + if (priv_data->usb3_phy) { + reset_control_assert(priv_data->usb_hibrst); + reset_control_assert(priv_data->usb_crst); + reset_control_assert(priv_data->usb_apbrst); + } err_phy_exit: phy_exit(priv_data->usb3_phy); err: From 6c6508e742b47539224eb18cb23f7ed5d401dcb6 Mon Sep 17 00:00:00 2001 From: Radhey Shyam Pandey Date: Mon, 28 Sep 2026 17:30:15 +0530 Subject: [PATCH 03/45] usb: dwc3: xilinx: unwind ZynqMP platform init on probe failure and remove dwc3_xlnx_init_zynqmp() leaves the controller out of reset with the PHY powered on, but nothing undoes that if probe fails later or when the driver is removed. The resets stay deasserted and the PHY stays on with no driver bound. Register the teardown with devm_add_action_or_reset() once init has completed, so it runs on probe failure without the driver having to track how far init progressed. The teardown only undoes the reset cycle init performed, so it carries the same usb3-phy guard: with no PHY the resets were never asserted, and asserting them could break a USB3 configuration that is live but missing from the device tree. The resets have to be asserted while the clocks are still running, so both the probe error path and remove() run the teardown explicitly before gating the clocks rather than leaving it to devres, which would otherwise run it afterwards. devm_release_action() unlinks the action before calling it, so devres cannot run it a second time. Running it from remove() also covers .shutdown, which shares dwc3_xlnx_remove(): device_shutdown() does not call devres_release_all(), so a teardown left to devres would never run there. Fixes: 84770f028fab ("usb: dwc3: Add driver for Xilinx platforms") Cc: stable Suggested-by: Philipp Zabel Assisted-by: Claude:claude-opus-5 Signed-off-by: Radhey Shyam Pandey Acked-by: Thinh Nguyen Link: https://patch.msgid.link/20260928120015.3152461-4-radhey.shyam.pandey@amd.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/dwc3-xilinx.c | 44 +++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/dwc3-xilinx.c b/drivers/usb/dwc3/dwc3-xilinx.c index d2315573b3d3..475bc19a1746 100644 --- a/drivers/usb/dwc3/dwc3-xilinx.c +++ b/drivers/usb/dwc3/dwc3-xilinx.c @@ -112,6 +112,39 @@ static int dwc3_xlnx_init_versal(struct dwc3_xlnx *priv_data) return 0; } +static void dwc3_xlnx_zynqmp_teardown(void *data) +{ + struct dwc3_xlnx *priv_data = data; + + phy_power_off(priv_data->usb3_phy); + + /* + * Undo only the reset cycle init performed. As on the init error + * path, the unconditional deasserts are not paired with an assert + * here: with no usb3-phy, resetting the core could break a USB3 + * configuration that is live but missing from the device tree. + */ + if (priv_data->usb3_phy) { + reset_control_assert(priv_data->usb_hibrst); + reset_control_assert(priv_data->usb_crst); + reset_control_assert(priv_data->usb_apbrst); + } + + phy_exit(priv_data->usb3_phy); +} + +/* + * Run the platform teardown explicitly, so the resets are asserted while the + * clocks are still running. devm_release_action() unlinks the action before + * calling it, so devres will not run it a second time. + */ +static void dwc3_xlnx_release_teardown(struct device *dev, + struct dwc3_xlnx *priv_data) +{ + if (devm_is_action_added(dev, dwc3_xlnx_zynqmp_teardown, priv_data)) + devm_release_action(dev, dwc3_xlnx_zynqmp_teardown, priv_data); +} + static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) { struct device *dev = priv_data->dev; @@ -228,7 +261,8 @@ static int dwc3_xlnx_init_zynqmp(struct dwc3_xlnx *priv_data) dwc3_xlnx_set_coherency(priv_data, XLNX_USB_TRAFFIC_ROUTE_CONFIG); - return 0; + return devm_add_action_or_reset(dev, dwc3_xlnx_zynqmp_teardown, + priv_data); err_phy_power_off: phy_power_off(priv_data->usb3_phy); @@ -355,6 +389,7 @@ err_pm_set_suspended: pm_runtime_set_suspended(dev); err_clk_put: + dwc3_xlnx_release_teardown(dev, priv_data); clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks); return ret; @@ -367,6 +402,13 @@ static void dwc3_xlnx_remove(struct platform_device *pdev) of_platform_depopulate(dev); + /* + * This is also what makes .shutdown behave the same as .remove: + * device_shutdown() does not call devres_release_all(), so a teardown + * left to devres would never run on the shutdown path. + */ + dwc3_xlnx_release_teardown(dev, priv_data); + clk_bulk_disable_unprepare(priv_data->num_clocks, priv_data->clks); priv_data->num_clocks = 0; From 688bee95b42395f5d127cbd7523d52b218ae5f8f Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Sat, 3 Oct 2026 02:18:05 +0000 Subject: [PATCH 04/45] MAINTAINERS: take over dwc2 maintainership Minas is stepping down as the DWC2 maintainer. Thank you Minas for your years of work maintaining this driver. I'm taking over DWC2 maintenance in addition to DWC3 so that both DesignWare USB DRD drivers share a single point of contact. Also drop the stale tree entry pointing at balbi/usb.git, which is no longer where dwc2 patches are picked up. This matches the DWC3 entry, which does not list a tree either. Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/c2a97d0eafcbaa9509edce5b7b2648d6f9d80863.1790993820.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- MAINTAINERS | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 748ce4d1c6a2..f292eef1197c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7555,10 +7555,9 @@ F: drivers/dma/dw-edma/ F: include/linux/dma/edma.h DESIGNWARE USB2 DRD IP DRIVER -M: Minas Harutyunyan +M: Thinh Nguyen L: linux-usb@vger.kernel.org S: Maintained -T: git git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git F: drivers/usb/dwc2/ DESIGNWARE USB3 DRD IP DRIVER From 5b4b83c2ffe8740f6f3e54ea4d4962a62c063ef1 Mon Sep 17 00:00:00 2001 From: Uttkarsh Aggarwal Date: Tue, 29 Sep 2026 14:59:39 +0530 Subject: [PATCH 05/45] usb: typec: ucsi: Set ucsi->connector before enabling notifications In ucsi_init(), ucsi->connector is assigned only after the UCSI_SET_NOTIFICATION_ENABLE command completes. But once that command is sent, the PPM is free to raise a connector change notification at any time, which is handled through: ucsi_notify_common() -> ucsi_connector_change() ucsi_connector_change() indexes into ucsi->connector to get the connector and schedule its work item. If this notification arrives before ucsi_init() reaches the "ucsi->connector = connector;" line, ucsi->connector is still NULL and the driver crashes dereferencing it. Fix this by setting ucsi->connector right after the connectors are registered, before notifications are enabled, so it is always valid by the time a connector change event can be delivered. Also clear ucsi->connector in the err_unregister path so it isn't left pointing at freed memory if a later step in ucsi_init() fails. Fixes: 0482c34ec6f8 ("usb: ucsi: Fix ucsi->connector race") Cc: stable Signed-off-by: Uttkarsh Aggarwal Reviewed-by: Peter Chen Reviewed-by: Heikki Krogerus Link: https://patch.msgid.link/20260929092939.1806907-1-uttkarsh.aggarwal@oss.qualcomm.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/ucsi.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 5aab8ab9f013..2f9adf4f8bde 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -2134,6 +2134,14 @@ static int ucsi_init(struct ucsi *ucsi) goto err_unregister; } + /* + * Set ucsi->connector before enabling notifications. A connector + * change event can be handled as soon as the notifications are + * enabled below, and ucsi_connector_change() indexes into + * ucsi->connector, so it must not be NULL at that point. + */ + ucsi->connector = connector; + /* Enable all supported notifications */ ntfy = ucsi_get_supported_notifications(ucsi); command = UCSI_SET_NOTIFICATION_ENABLE | ntfy; @@ -2141,7 +2149,6 @@ static int ucsi_init(struct ucsi *ucsi) if (ret < 0) goto err_unregister; - ucsi->connector = connector; ucsi->ntfy = ntfy; mutex_lock(&ucsi->ppm_lock); @@ -2155,6 +2162,7 @@ static int ucsi_init(struct ucsi *ucsi) return 0; err_unregister: + ucsi->connector = NULL; for (con = connector; con->port; con++) ucsi_unregister_port(con); for (i = 0; i < ucsi->cap.num_connectors; i++) From ea6cf69ad03c8d85138830c0d2c3b946b5ae231d Mon Sep 17 00:00:00 2001 From: Brian Ellis Date: Tue, 13 Oct 2026 14:57:03 -0600 Subject: [PATCH 06/45] usb: gadget: u_serial: fix NULL deref in gs_close() after failed open gs_close() opens with struct gs_port *port = tty->driver_data; ... spin_lock_irq(&port->port_lock); and never checks port. gs_open() assigns tty->driver_data only on the port.count 0 -> 1 edge, so any failure earlier in gs_open() leaves it NULL, and tty_open() calls tty_release(), and hence ->close(), when ->open() fails. syzbot hit exactly this on arm64. Fault injection failed the kfifo_alloc() of the write buffer in gs_open(): __kfifo_alloc_node+0x10c/0x208 lib/kfifo.c:44 gs_open+0x144/0x514 drivers/usb/gadget/function/u_serial.c:636 tty_open+0x404/0x89c drivers/tty/tty_io.c:2137 and the tty core's close of the failed open then took port_lock through the NULL port: BUG: unable to handle kernel paging request in gs_close KASAN: null-ptr-deref in range [0x00000000000003a0-0x00000000000003a7] Call trace: spin_lock_irq include/linux/spinlock.h:372 [inline] gs_close+0xac/0x65c drivers/usb/gadget/function/u_serial.c:698 tty_release+0x2c4/0xffc drivers/tty/tty_io.c:1745 tty_open+0x46c/0x89c drivers/tty/tty_io.c:2146 Return early instead. There is nothing to release when the open never got far enough to claim the port. Unlike the check reverted by commit f6c7bc4a6823 ("Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io""), this is not hiding a race: the tty core calls ->close() for an ->open() that failed by design, so driver_data is legitimately unset on that path. Fixes: c1dca562be8a ("usb gadget: split out serial core") Reported-by: syzbot+782b2f1063e38ba8fa6e@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=782b2f1063e38ba8fa6e Cc: stable Assisted-by: LLM Signed-off-by: Brian Ellis Link: https://patch.msgid.link/20261013-u_serial-gs-close-null-v4-1-9ea038501994@gotenna.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/u_serial.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index cdd1dfc666c4..892d2673e9b0 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -695,6 +695,9 @@ static void gs_close(struct tty_struct *tty, struct file *file) struct gs_port *port = tty->driver_data; struct gserial *gser; + if (!port) + return; + spin_lock_irq(&port->port_lock); if (port->port.count != 1) { From fafd23d61494461256d374f67c121f2712e1af2f Mon Sep 17 00:00:00 2001 From: Olivier Kaloudoff Date: Wed, 14 Oct 2026 18:57:41 +0200 Subject: [PATCH 07/45] usb: uas: ignore UAS for ASMT135x bridges (174c:55aa) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ASMedia chip detection in uas_use_uas_driver() assumes that every device with idVendor/idProduct 174c:5106 or 174c:55aa reporting a config.MaxPower of 0 is an ASM1153 with working UAS. ASMT135x bridges (iProduct "ASMT135x") share the same 174c:55aa id and also report MaxPower == 0, so they take the "ASM1153, do nothing" path — but their UAS implementation is broken: - The first READ(16) issued by sd probing times out after 30 s; enumeration only completes after a uas_eh_abort_handler plus a full uas_eh_host_reset_handler cycle: scsi 3:0:0:0: Direct-Access ASMT ASMT135x 0 PQ: 0 ANSI: 6 sd 3:0:0:0: [sdb] tag#26 uas_eh_abort_handler 0 uas-tag 1 inflight: CMD IN sd 3:0:0:0: [sdb] tag#26 CDB: Read(16) 88 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 scsi host3: uas_eh_host_reset_handler start usb 6-2: reset SuperSpeed USB device number 2 using xhci_hcd scsi host3: uas_eh_host_reset_handler success - Under concurrent load the bridge stalls: all inflight commands (20+ UAS tags in the captured incident, mixed READ(16)/WRITE(16)) hit the 30 s UAS timeout in the same event, forcing repeated abort/reset cycles and eventually a USB disconnect. Writes dropped mid-flight during these resets returned zeros to the filesystem (observed as XFS metadata corruption on the mounted volume). - Sequential-write throughput is ~45 MiB/s under UAS versus ~136 MiB/s after disabling UAS (usb-storage BOT mode), which is fully stable: several tens of GiB written without a single error. - Bulk reads of healthy LBA ranges do work under UAS (~190 MiB/s, no errors); the failure pattern is command-timeout at enumeration and under queue depth / write load, not a broken transfer path. Since 174c:55aa is shared across several ASMedia bridges and enclosure rebrandings, distinguish the ASMT135x by its product string — the same approach used for the HIKSEMI MD202 check a few lines below. The product strings of working bridges using the same id ("ASM1053E", "ASM1153", "ASM1153E", "ASM1351", vendor rebrands such as "YZWY_TECH") do not contain "ASMT135", so the match is safe. Verified on an ORICO enclosure (iManufacturer "ASMT", iProduct "ASMT135x", bcdDevice 1.00) attached through an Alpine Ridge TB3 dock: with the equivalent usb-storage quirks parameter (174c:55aa:u) the device is completely stable. Signed-off-by: Olivier Kaloudoff Cc: stable Acked-by: Alan Stern Link: https://patch.msgid.link/20261014165741.35758-1-olivier.kaloudoff@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/uas-detect.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb/storage/uas-detect.h b/drivers/usb/storage/uas-detect.h index 4d3b49e5b87a..523a17cf0a3c 100644 --- a/drivers/usb/storage/uas-detect.h +++ b/drivers/usb/storage/uas-detect.h @@ -78,6 +78,8 @@ static int uas_use_uas_driver(struct usb_interface *intf, * ASM1051 - with broken (*) uas support * ASM1053 - with working uas support, but problems with large xfers * ASM1153 - with working uas support + * ASMT135x - broken uas support, shares the ASM1153 MaxPower == 0 + * signature, identify it by its product string * * Devices with these chips re-use a number of device-ids over the * entire line, so the device-id is useless to determine if we're @@ -99,7 +101,11 @@ static int uas_use_uas_driver(struct usb_interface *intf, (le16_to_cpu(udev->descriptor.idProduct) == 0x5106 || le16_to_cpu(udev->descriptor.idProduct) == 0x55aa)) { if (udev->actconfig->desc.bMaxPower == 0) { - /* ASM1153, do nothing */ + if (udev->product && strstr(udev->product, "ASMT135")) { + /* ASMT135x, broken uas */ + flags |= US_FL_IGNORE_UAS; + } + /* else ASM1153, do nothing */ } else if (udev->speed < USB_SPEED_SUPER) { /* No streams info, assume ASM1051 */ flags |= US_FL_IGNORE_UAS; From fdaca138694111153f96c7d76877734b9dbf0e01 Mon Sep 17 00:00:00 2001 From: YuanZhe Liu <25031212351@stu.xidian.edu.cn> Date: Fri, 16 Oct 2026 15:27:50 +0800 Subject: [PATCH 08/45] usb: usbtest: prevent divide by zero in simple_io() with zero length A divide error oops was observed in simple_io(): usbtest 1-1:1.0: TEST 3: write/1 0..0 bytes 16307 times Oops: divide error: 0000 [#1] SMP KASAN RIP: 0010:simple_io+0x2c4/0x540 drivers/usb/misc/usbtest.c:497 The variable-length tests (test 3 and test 4) compute the next URB size with "len %= max", where max is the original urb->transfer_buffer_length. However, when a zero-length transfer is requested (param->length == 0), simple_alloc_urb() still returns a valid URB with transfer_buffer_length set to 0. On the first vary update, "len %= max" divides by zero and the kernel oopses. Commit 564e69893c63 ("USB: usbtest: prevent a divide by zero bug") added the equivalent zero check to alloc_sglist(), which covers the scatterlist tests (test 7/8), but the single-URB variable-length path in simple_io() was left unprotected. Fix this by returning -EINVAL early from simple_io() when vary is requested but max is zero, so the divide by zero never occurs. Zero-length transfers without vary remain valid for the other callers of simple_io(). Cc: stable Co-developed-by: Bin Yu Signed-off-by: Bin Yu Co-developed-by: Cheng Wen Signed-off-by: Cheng Wen Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn> Reviewed-by: Alan Stern Link: https://patch.msgid.link/20261016072750.34256-1-25031212351@stu.xidian.edu.cn Signed-off-by: Greg Kroah-Hartman --- drivers/usb/misc/usbtest.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c index 8759df49be28..e2f5e6be353a 100644 --- a/drivers/usb/misc/usbtest.c +++ b/drivers/usb/misc/usbtest.c @@ -466,6 +466,9 @@ static int simple_io( int retval = 0; unsigned long expire; + if (vary && !max) + return -EINVAL; + urb->context = &completion; while (retval == 0 && iterations-- > 0) { init_completion(&completion); From bc9dd21ec61acd152d9e7c12cb07db37c63ad41a Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Mon, 19 Oct 2026 14:37:55 +0200 Subject: [PATCH 09/45] USB: cdc-acm: fix NULL-deref on hangup Make sure to take a reference to the port tty when processing carrier detect changes to avoid dereferencing a NULL pointer when the port is being hung up. Fixes: 3b563b901eef ("usb: cdc-acm: add PPS support") Cc: stable Cc: Dan Drown Signed-off-by: Johan Hovold Link: https://patch.msgid.link/20261019123755.2008384-1-johan@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/cdc-acm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 489575d40bd1..666969ffd194 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -294,6 +294,7 @@ static void acm_process_notification(struct acm *acm, unsigned char *buf) unsigned long flags; struct usb_cdc_notification *dr = (struct usb_cdc_notification *)buf; unsigned char *data = buf + sizeof(struct usb_cdc_notification); + struct tty_struct *tty; switch (dr->bNotificationType) { case USB_CDC_NOTIFY_NETWORK_CONNECTION: @@ -320,12 +321,17 @@ static void acm_process_notification(struct acm *acm, unsigned char *buf) difference = acm->ctrlin ^ newctrl; - if ((difference & USB_CDC_SERIAL_STATE_DCD) && acm->port.tty) { - struct tty_ldisc *ld = tty_ldisc_ref(acm->port.tty); - if (ld) { - if (ld->ops->dcd_change) - ld->ops->dcd_change(acm->port.tty, newctrl & USB_CDC_SERIAL_STATE_DCD); - tty_ldisc_deref(ld); + if (difference & USB_CDC_SERIAL_STATE_DCD) { + tty = tty_port_tty_get(&acm->port); + if (tty) { + struct tty_ldisc *ld = tty_ldisc_ref(tty); + + if (ld) { + if (ld->ops->dcd_change) + ld->ops->dcd_change(tty, newctrl & USB_CDC_SERIAL_STATE_DCD); + tty_ldisc_deref(ld); + } + tty_kref_put(tty); } } From 450fa94d7ae9fc91c3df525f5d1322bf8fecf7b2 Mon Sep 17 00:00:00 2001 From: Yu Zhang Date: Tue, 20 Oct 2026 12:30:50 +1000 Subject: [PATCH 10/45] usb: gadget: f_mass_storage: take filesem in nofua store to fix backing-file UAF fsg_store_nofua() syncs the LUN's backing file when switching from async to sync mode: if (!nofua && curlun->nofua) fsg_lun_fsync_sub(curlun); fsg_lun_fsync_sub() dereferences curlun->filp (vfs_fsync(filp)). Unlike every other store that touches the backing file -- fsg_store_ro() and fsg_store_cdrom() (down_read), fsg_store_file() (down_write) -- fsg_store_nofua() holds no filesem while doing so. A concurrent close of the backing file runs under down_write(filesem) and does fput(curlun->filp) in fsg_lun_close() (fsg_store_file() with an empty path, the SCSI START_STOP eject in do_start_stop(), or forced_eject), so it can free the file while fsg_store_nofua() is dereferencing it: BUG: KASAN: slab-use-after-free in vfs_fsync+0x20/0xe0 vfs_fsync+0x20/0xe0 fsg_lun_fsync_sub+0xa0/0xd0 fsg_store_nofua+0x138/0x160 configfs_write_iter+0x1a7/0x250 vfs_write+0x5df/0x940 Allocated by task 3459: fsg_store_file+0x150/0x1f0 configfs_write_iter+0x1a7/0x250 Freed by task 3459: __fput+0x456/0x6c0 __fput_deferred+0x10d/0x330 fsg_store_file+0x9e/0x1f0 configfs_write_iter+0x1a7/0x250 Hold filesem for read around the fsync in fsg_store_nofua() so the backing file cannot be closed underneath it. The lock is only needed when the fsync actually runs, so it is taken only in that branch. Reproduced on a mass_storage gadget over dummy_hcd by writing lun.N/nofua (1 then 0) from one task while another task rewrites and clears lun.N/file. Cc: stable Signed-off-by: Yu Zhang Acked-by: Alan Stern Link: https://patch.msgid.link/20261020023050.87701-1-yuz08559@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_mass_storage.c | 8 ++++++-- drivers/usb/gadget/function/storage_common.c | 7 +++++-- drivers/usb/gadget/function/storage_common.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index e3c9b7ab9f39..52314a00d8e6 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2669,8 +2669,9 @@ static ssize_t nofua_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct fsg_lun *curlun = fsg_lun_from_dev(dev); + struct rw_semaphore *filesem = dev_get_drvdata(dev); - return fsg_store_nofua(curlun, buf, count); + return fsg_store_nofua(curlun, filesem, buf, count); } static ssize_t file_store(struct device *dev, struct device_attribute *attr, @@ -3248,7 +3249,10 @@ static ssize_t fsg_lun_opts_nofua_show(struct config_item *item, char *page) static ssize_t fsg_lun_opts_nofua_store(struct config_item *item, const char *page, size_t len) { - return fsg_store_nofua(to_fsg_lun_opts(item)->lun, page, len); + struct fsg_lun_opts *opts = to_fsg_lun_opts(item); + struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent); + + return fsg_store_nofua(opts->lun, &fsg_opts->common->filesem, page, len); } CONFIGFS_ATTR(fsg_lun_opts_, nofua); diff --git a/drivers/usb/gadget/function/storage_common.c b/drivers/usb/gadget/function/storage_common.c index 75831f2c7abe..51a70f2abe57 100644 --- a/drivers/usb/gadget/function/storage_common.c +++ b/drivers/usb/gadget/function/storage_common.c @@ -415,7 +415,8 @@ ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, } EXPORT_SYMBOL_GPL(fsg_store_ro); -ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) +ssize_t fsg_store_nofua(struct fsg_lun *curlun, struct rw_semaphore *filesem, + const char *buf, size_t count) { bool nofua; int ret; @@ -425,8 +426,10 @@ ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count) return ret; /* Sync data when switching from async mode to sync */ - if (!nofua && curlun->nofua) + if (!nofua && curlun->nofua) { + guard(rwsem_read)(filesem); fsg_lun_fsync_sub(curlun); + } curlun->nofua = nofua; diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h index e73a30cc553f..e66b753d7cbd 100644 --- a/drivers/usb/gadget/function/storage_common.h +++ b/drivers/usb/gadget/function/storage_common.h @@ -245,7 +245,8 @@ ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf); ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf); ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem, const char *buf, size_t count); -ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count); +ssize_t fsg_store_nofua(struct fsg_lun *curlun, struct rw_semaphore *filesem, + const char *buf, size_t count); ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem, const char *buf, size_t count); ssize_t fsg_store_cdrom(struct fsg_lun *curlun, struct rw_semaphore *filesem, From d8090de52e0a8f1761ced4fc31d52a3e289e341c Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:47:17 +0000 Subject: [PATCH 11/45] usb: dwc3: trace: Restore request name assignment The commit 0a06917432a7 ("usb: dwc3: Log dwc3 address in traces") removed the __assign_str(name) call from dwc3_log_request. The name field still exists in the trace event, but nothing fills it in, so the endpoint name printed for these events is leftover garbage from the ring buffer. Put the __assign_str() call back so the endpoint name is logged again. Fixes: 0a06917432a7 ("usb: dwc3: Log dwc3 address in traces") Cc: stable Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/8bd045b136bfef8ce5de79f1fa2f09db639f0707.1792543567.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/trace.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h index 5253da23d8b0..0caaa0b396d1 100644 --- a/drivers/usb/dwc3/trace.h +++ b/drivers/usb/dwc3/trace.h @@ -141,6 +141,7 @@ DECLARE_EVENT_CLASS(dwc3_log_request, ), TP_fast_assign( __entry->base_address = req->dep->dwc->xhci_resources[0].start; + __assign_str(name); __entry->req = req; __entry->actual = req->request.actual; __entry->length = req->request.length; From 2022b10726be78849626ea3fa33038ee96a54e46 Mon Sep 17 00:00:00 2001 From: Chaz Bailey Date: Fri, 16 Oct 2026 13:20:45 +0100 Subject: [PATCH 12/45] usb: typec: nb7vpq904m: Set client data in probe to avoid crash on remove nb7vpq904m_probe() allocates struct nb7vpq904m, but client data is not set during probe. In nb7vpq904m_remove(), i2c_get_clientdata(client) returns NULL, leading to a NULL pointer dereference when accessing nb7->retimer or nb7->sw. Set client data upon successful allocation in probe. Fixes: 88d8f3ac9c67 ("usb: typec: add support for the nb7vpq904m Type-C Linear Redriver") Cc: stable Signed-off-by: Chaz Bailey Reviewed-by: Krishna Kurapati Reviewed-by: Heikki Krogerus Link: https://patch.msgid.link/20261016122045.187862-1-charles.s.bailey@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/mux/nb7vpq904m.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/typec/mux/nb7vpq904m.c b/drivers/usb/typec/mux/nb7vpq904m.c index d1fa26ff442c..52e3c9db35a7 100644 --- a/drivers/usb/typec/mux/nb7vpq904m.c +++ b/drivers/usb/typec/mux/nb7vpq904m.c @@ -396,6 +396,7 @@ static int nb7vpq904m_probe(struct i2c_client *client) return -ENOMEM; nb7->client = client; + i2c_set_clientdata(client, nb7); nb7->regmap = devm_regmap_init_i2c(client, &nb7_regmap); if (IS_ERR(nb7->regmap)) { From 89aaaa26f6985d55676fc5c90440f279733fa132 Mon Sep 17 00:00:00 2001 From: Joonhoe Kim <26rote@gmail.com> Date: Fri, 23 Oct 2026 01:51:43 +0900 Subject: [PATCH 13/45] usb: typec: mux: fsa4480: Keep the USB 2.0 switch on in DP-only modes DisplayPort pin assignments C and E give all four SuperSpeed lanes to DisplayPort, but the USB 2.0 D+/D- pair is not part of the pin assignment and stays available. The FSA4480 sits on that pair, and in these modes the driver turns its USB switch off, so a USB 2.0 hub or device behind a DisplayPort sink is disconnected as soon as the DisplayPort mode is set. Configure the USB switch the same way in all DisplayPort modes. Fixes: c7054c31c1c9 ("usb: typec: fsa4480: rework mux & switch setup to handle more states") Cc: stable Signed-off-by: Joonhoe Kim <26rote@gmail.com> Reviewed-by: Konrad Dybcio Acked-by: Heikki Krogerus Link: https://patch.msgid.link/20261022165143.1327-1-26rote@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/mux/fsa4480.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/usb/typec/mux/fsa4480.c b/drivers/usb/typec/mux/fsa4480.c index bea0c1deec94..e05ab3c10c81 100644 --- a/drivers/usb/typec/mux/fsa4480.c +++ b/drivers/usb/typec/mux/fsa4480.c @@ -93,16 +93,9 @@ static int fsa4480_set(struct fsa4480 *fsa) sel = FSA4480_SEL_USB; } else if (fsa->svid) { switch (fsa->mode) { - /* DP Only */ case TYPEC_DP_STATE_C: - case TYPEC_DP_STATE_E: - enable |= FSA4480_ENABLE_SBU; - if (reverse) - sel = FSA4480_SEL_SBU_REVERSE; - break; - - /* DP + USB */ case TYPEC_DP_STATE_D: + case TYPEC_DP_STATE_E: case TYPEC_DP_STATE_F: enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_SBU; sel = FSA4480_SEL_USB; From 7cfb037005c04b9dee5b0c4626e56e2eddeef157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Ahmet=20Memi=C5=9F?= Date: Sat, 24 Oct 2026 20:44:41 +0300 Subject: [PATCH 14/45] usb: typec: ucsi: debugfs: Fix GET commands on UCSI < 2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the debugfs response buffer grew to 24 bytes, every GET command fails with -EINVAL on UCSI < 2.0, where the data length is limited to 16 bytes. Clamp the length to UCSI_MAX_DATA_LENGTH(). Fixes: d9dc19910321 ("usb: typec: ucsi: Fix debugfs response truncation beyond 16 bytes") Cc: stable Signed-off-by: Ali Ahmet Memiş Reviewed-by: Heikki Krogerus Link: https://patch.msgid.link/20261024174441.878903-1-aliamemis@disroot.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/debugfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/ucsi/debugfs.c b/drivers/usb/typec/ucsi/debugfs.c index 77a0dd75edd3..3cffd3778c67 100644 --- a/drivers/usb/typec/ucsi/debugfs.c +++ b/drivers/usb/typec/ucsi/debugfs.c @@ -60,7 +60,8 @@ static int ucsi_cmd(void *data, u64 val) case UCSI_GET_LPM_PPM_INFO: ret = ucsi_send_command(ucsi, val, &ucsi->debugfs->response, - sizeof(ucsi->debugfs->response)); + min(sizeof(ucsi->debugfs->response), + UCSI_MAX_DATA_LENGTH(ucsi))); break; default: ret = -EOPNOTSUPP; From 3ee1e1c3fca6fb5d0abbe0fc91539951ffa60aa7 Mon Sep 17 00:00:00 2001 From: Ihor Urazov Date: Mon, 26 Oct 2026 01:47:52 +0200 Subject: [PATCH 15/45] usb: typec: ucsi: acpi: Assume UCSI 1.0 on HP ZBook 8 G2i 14 The HP ZBook 8 G2i 14 (board 8ED9) exposes a working UCSI ACPI PPM, but its UCSI VERSION field reads zero until the first command completes. ucsi_register() rejects a zero version with -ENODEV, so no Type-C ports are registered. The firmware's _DSM READ function (2) is a stub. The mailbox VERSION field is written only by the EC response handler, after a command completes, after which it reads 0x0100 (UCSI 1.0). The mailbox is 48 bytes with 16-byte MESSAGE_IN/MESSAGE_OUT fields, the UCSI 1.x layout, and _DSM function 5 is not implemented. Add a DMI-specific read_version for this board that substitutes the version the firmware itself reports, UCSI 1.0, only when VERSION reads zero. A non-zero firmware version is used as is. The same firmware defect on the HP ZBook Fury G1i 16 was discussed in "[RFC PATCH] usb: typec: ucsi: acpi: bootstrap PPM on HP systems with empty _DSM func 2" [1]. The defect was reported to HP as case 5166176673. Tested on an HP ZBook 8 G2i 14 with BIOS Y70 01.02.08, from a fresh boot where VERSION reads zero: three connectors register, the PD contract and alternate modes of a Thunderbolt dock are reported, and its DisplayPort output stays up across the PPM reset in ucsi_init(). Dock unplug/replug and s2idle suspend/resume update the connector state without errors. Link: https://lore.kernel.org/linux-usb/f3M_fpjtt8FxDqGKcA84vqXmRbKzCBfpCrIK4-jCWvIscER51zkD8qD8FYpz75qZw51rMDRSkUyYlrBvLvdM8CGRY2l8TFVvr4MC1LdTzbc=@interstellar.eu/ [1] Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface") Cc: stable Cc: Francesco Orro Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Ihor Urazov Reviewed-by: Heikki Krogerus Reviewed-by: Huang Wei Link: https://patch.msgid.link/20261026-ucsi-hp-zbook-8-g2i-v1-1-91002e9ef073@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/ucsi_acpi.c | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi_acpi.c b/drivers/usb/typec/ucsi/ucsi_acpi.c index 5697ccc24ec3..2421a92ecb0e 100644 --- a/drivers/usb/typec/ucsi/ucsi_acpi.c +++ b/drivers/usb/typec/ucsi/ucsi_acpi.c @@ -148,6 +148,34 @@ static const struct ucsi_operations ucsi_acer_ops = { .async_control = ucsi_acpi_async_control }; +static int ucsi_hp_read_version(struct ucsi *ucsi, u16 *version) +{ + struct ucsi_acpi *ua = ucsi_get_drvdata(ucsi); + int ret; + + ret = ucsi_acpi_read_version(ucsi, version); + if (ret) + return ret; + + /* Firmware fills in VERSION (1.0) only after the first command completes */ + if (!*version) { + dev_warn(ua->dev, "UCSI version is zero, assuming 1.0\n"); + *version = UCSI_VERSION_1_0; + } + + return 0; +} + +static const struct ucsi_operations ucsi_hp_ops = { + .read_version = ucsi_hp_read_version, + .read_cci = ucsi_acpi_read_cci, + .poll_cci = ucsi_acpi_poll_cci, + .read_message_in = ucsi_acpi_read_message_in, + .write_message_out = ucsi_acpi_write_message_out, + .sync_control = ucsi_sync_control_common, + .async_control = ucsi_acpi_async_control +}; + static int ucsi_gram_sync_control(struct ucsi *ucsi, u64 command, u32 *cci, void *val, size_t len, void *msg_out, size_t msg_out_size) @@ -196,6 +224,13 @@ static const struct dmi_system_id ucsi_acpi_quirks[] = { }, .driver_data = (void *)&ucsi_acer_ops, }, + { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_BOARD_NAME, "8ED9"), + }, + .driver_data = (void *)&ucsi_hp_ops, + }, { .matches = { DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"), From 5eb11b1647b0534b3a61a21473d77ebf4ffbed7c Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:37:51 +0000 Subject: [PATCH 16/45] usb: dwc3: gadget: Reject requests to a disabled endpoint __dwc3_gadget_ep_disable() releases the lock while giving back requests, and DWC3_EP_ENABLED is only cleared afterward. A function driver can queue a new request in this window, and the driver would start a transfer on an endpoint that is already disabled in hardware. Clear DWC3_EP_ENABLED before giving back the requests, and reject requests queued to an endpoint that is not enabled. Fixes: 72246da40f37 ("usb: Introduce DesignWare USB3 DRD Driver") Cc: stable Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/4ceab6aa5d6af0e4780f9d3a964fd5d8168a0a02.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index ee837235630a..eb6666b7bb98 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1084,6 +1084,8 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) reg &= ~DWC3_DALEPENA_EP(dep->number); dwc3_writel(dwc, DWC3_DALEPENA, reg); + dep->flags &= ~DWC3_EP_ENABLED; + dwc3_remove_requests(dwc, dep, -ESHUTDOWN); dep->stream_capable = false; @@ -1990,7 +1992,8 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) { struct dwc3 *dwc = dep->dwc; - if (!dep->endpoint.desc || !dwc->pullups_connected || !dwc->connected) { + if (!(dep->flags & DWC3_EP_ENABLED) || !dep->endpoint.desc || + !dwc->pullups_connected || !dwc->connected) { dev_dbg(dwc->dev, "%s: can't queue to disabled endpoint\n", dep->name); return -ESHUTDOWN; From af91c6322e633504aa45de278f5d520f39d127be Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:37:56 +0000 Subject: [PATCH 17/45] usb: dwc3: gadget: Track a timed out End Transfer If an End Transfer command with CMDIOC times out, the driver clears the resource index but keeps DWC3_EP_TRANSFER_STARTED without setting DWC3_EP_END_TRANSFER_PENDING. The command is still outstanding, but a later stop issues another End Transfer with resource index 0, and the next Start Transfer fails with "No Resource". Mark the timed out End Transfer as pending so that no other command is issued to the endpoint until it completes. For any other failure, there is no outstanding command, so clear DWC3_EP_TRANSFER_STARTED. Fixes: e192cc7b5239 ("usb: dwc3: gadget: move cmd_endtransfer to extra function") Cc: stable Reported-by: Selvarasu Ganesan Closes: https://lore.kernel.org/linux-usb/3fdda532-8181-48e9-b58d-cad7289408e7@samsung.com/ Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/5815c41a7e7923edb114741f29697cf0161f523c.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index eb6666b7bb98..df5407e75788 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1798,9 +1798,9 @@ static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool int dep->resource_index = 0; - if (!interrupt) + if (!interrupt || (ret && ret != -ETIMEDOUT)) dep->flags &= ~DWC3_EP_TRANSFER_STARTED; - else if (!ret) + else dep->flags |= DWC3_EP_END_TRANSFER_PENDING; dep->flags &= ~DWC3_EP_DELAY_STOP; From f2bd20f92a7dc68980a6098397503067192ce63a Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:38:02 +0000 Subject: [PATCH 18/45] usb: dwc3: gadget: Clear delayed stop on End Transfer completion When an End Transfer command times out outside of the SETUP phase, the driver sets DWC3_EP_DELAY_STOP to retry it on the next SETUP phase. If the command completes in the meantime, the flag is left set. Requests queued to the endpoint are then deferred, and the retry may end a transfer that is started later. Clear DWC3_EP_DELAY_STOP when the End Transfer command completes. Fixes: 4db0fbb60136 ("usb: dwc3: gadget: Don't delay End Transfer on delayed_status") Cc: stable Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/c28a9660f7b6bfa626077ddcfbadd50e6b503f86.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index df5407e75788..4de3b81cb678 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3875,6 +3875,7 @@ static void dwc3_gadget_endpoint_command_complete(struct dwc3_ep *dep, if (dep->stream_capable) dep->flags |= DWC3_EP_IGNORE_NEXT_NOSTREAM; + dep->flags &= ~DWC3_EP_DELAY_STOP; dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING; dep->flags &= ~DWC3_EP_TRANSFER_STARTED; dwc3_gadget_ep_cleanup_cancelled_requests(dep); From e616d91e02881983e5dadf6980c4aa08123800b3 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:38:07 +0000 Subject: [PATCH 19/45] usb: dwc3: gadget: Issue no-op Start Transfer only for stream endpoints The function driver may re-enable an endpoint before the End Transfer command issued on ep disable completes. The no-op Start Transfer issued on ep enable then fails with "No Resource". Only stream endpoints need the no-op Start Transfer to initiate a stream. Other bulk and interrupt endpoints start their transfer when a request is queued. Skip it for those endpoints, and move it to a helper to be reused. Fixes: a97ea994605e ("usb: dwc3: gadget: offset Start Transfer latency for bulk EPs") Cc: stable Reported-by: Selvarasu Ganesan Closes: https://lore.kernel.org/linux-usb/20260227121236.963-1-selvarasu.g@samsung.com/ Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/227e97e30d26a017c92d7008a8633c01f955d088.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 97 ++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 4de3b81cb678..e68584f20fbd 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -906,6 +906,54 @@ static int dwc3_gadget_resize_tx_fifos(struct dwc3_ep *dep) return 0; } +static int dwc3_gadget_ep_start_noop_transfer(struct dwc3_ep *dep) +{ + struct dwc3_gadget_ep_cmd_params params; + struct dwc3 *dwc = dep->dwc; + struct dwc3_trb *trb; + dma_addr_t trb_dma; + u32 cmd; + int ret; + + memset(¶ms, 0, sizeof(params)); + trb = &dep->trb_pool[0]; + trb_dma = dwc3_trb_dma_offset(dep, trb); + + params.param0 = upper_32_bits(trb_dma); + params.param1 = lower_32_bits(trb_dma); + + cmd = DWC3_DEPCMD_STARTTRANSFER; + + ret = dwc3_send_gadget_ep_cmd(dep, cmd, ¶ms); + if (ret < 0) + return ret; + + /* + * For streams, at start, there maybe a race where the host primes the + * endpoint before the function driver queues a request to initiate a + * stream. In that case, the controller will not see the prime to + * generate the ERDY and start stream. To workaround this, issue a + * no-op TRB as normal, but end it immediately. As a result, when the + * function driver queues the request, the next START_TRANSFER command + * will cause the controller to generate an ERDY to initiate the + * stream. + */ + dwc3_stop_active_transfer(dep, false, true); + + /* + * All stream eps will reinitiate stream on NoStream rejection. + * + * However, if the controller is capable of TXF_FLUSH_BYPASS, then IN + * direction endpoints will automatically restart the stream without + * the driver initiation. + */ + if (!dep->direction || + !(dwc->hwparams.hwparams9 & DWC3_GHWPARAMS9_DEV_TXF_FLUSH_BYPASS)) + dep->flags |= DWC3_EP_FORCE_RESTART_STREAM; + + return 0; +} + /** * __dwc3_gadget_ep_enable - initializes a hw endpoint * @dep: endpoint to be initialized @@ -971,55 +1019,10 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) * Issue StartTransfer here with no-op TRB so we can always rely on No * Response Update Transfer command. */ - if (usb_endpoint_xfer_bulk(desc) || - usb_endpoint_xfer_int(desc)) { - struct dwc3_gadget_ep_cmd_params params; - struct dwc3_trb *trb; - dma_addr_t trb_dma; - u32 cmd; - - memset(¶ms, 0, sizeof(params)); - trb = &dep->trb_pool[0]; - trb_dma = dwc3_trb_dma_offset(dep, trb); - - params.param0 = upper_32_bits(trb_dma); - params.param1 = lower_32_bits(trb_dma); - - cmd = DWC3_DEPCMD_STARTTRANSFER; - - ret = dwc3_send_gadget_ep_cmd(dep, cmd, ¶ms); + if (dep->stream_capable) { + ret = dwc3_gadget_ep_start_noop_transfer(dep); if (ret < 0) return ret; - - if (dep->stream_capable) { - /* - * For streams, at start, there maybe a race where the - * host primes the endpoint before the function driver - * queues a request to initiate a stream. In that case, - * the controller will not see the prime to generate the - * ERDY and start stream. To workaround this, issue a - * no-op TRB as normal, but end it immediately. As a - * result, when the function driver queues the request, - * the next START_TRANSFER command will cause the - * controller to generate an ERDY to initiate the - * stream. - */ - dwc3_stop_active_transfer(dep, false, true); - - /* - * All stream eps will reinitiate stream on NoStream - * rejection. - * - * However, if the controller is capable of - * TXF_FLUSH_BYPASS, then IN direction endpoints will - * automatically restart the stream without the driver - * initiation. - */ - if (!dep->direction || - !(dwc->hwparams.hwparams9 & - DWC3_GHWPARAMS9_DEV_TXF_FLUSH_BYPASS)) - dep->flags |= DWC3_EP_FORCE_RESTART_STREAM; - } } out: From 1338410c21a5710b7ba88057034d35367ba0f054 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:38:13 +0000 Subject: [PATCH 20/45] usb: dwc3: gadget: Wait for End Transfer completion on ep disable The End Transfer command on ep disable is issued without interrupt, and the endpoint flags are cleared right after a fixed delay. The command may not have completed by then. If the function driver re-enables the endpoint and queues a request, the next Start Transfer fails with "No Resource". Issue the End Transfer command with interrupt on ep disable, and keep DWC3_EP_END_TRANSFER_PENDING and DWC3_EP_TRANSFER_STARTED until the command completes. Defer the no-op Start Transfer of a stream endpoint re-enabled in the meantime to the command completion. Fixes: c5353b225df9 ("usb: dwc3: gadget: don't enable interrupt when disabling endpoint") Cc: stable Reported-by: Selvarasu Ganesan Closes: https://lore.kernel.org/linux-usb/20260227121236.963-1-selvarasu.g@samsung.com/ Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/24fa8adeb0222dab415c8c2799405188440bad4b.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/core.h | 4 +++- drivers/usb/dwc3/ep0.c | 2 +- drivers/usb/dwc3/gadget.c | 42 ++++++++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index f3dabb37f806..267c922ca11b 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -771,6 +771,7 @@ struct dwc3_ep { #define DWC3_EP_TXFIFO_RESIZED BIT(12) #define DWC3_EP_DELAY_STOP BIT(13) #define DWC3_EP_RESOURCE_ALLOCATED BIT(14) +#define DWC3_EP_PENDING_NOOP_START BIT(15) /* This last one is specific to EP0 */ #define DWC3_EP0_DIR_IN BIT(31) @@ -1695,7 +1696,8 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned int cmd, int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned int cmd, u32 param); void dwc3_gadget_clear_tx_fifos(struct dwc3 *dwc); -void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status); +void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status, + bool interrupt); #else static inline int dwc3_gadget_init(struct dwc3 *dwc) { return 0; } diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c index 46a34c4a046b..cf5a47b71efc 100644 --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -315,7 +315,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc) if (dwc->connected) dwc3_stop_active_transfer(dwc3_ep, false, true); else - dwc3_remove_requests(dwc, dwc3_ep, -ESHUTDOWN); + dwc3_remove_requests(dwc, dwc3_ep, -ESHUTDOWN, false); } } diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e68584f20fbd..e531adc02a40 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1020,9 +1020,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action) * Response Update Transfer command. */ if (dep->stream_capable) { - ret = dwc3_gadget_ep_start_noop_transfer(dep); - if (ret < 0) - return ret; + if (dep->flags & (DWC3_EP_END_TRANSFER_PENDING | + DWC3_EP_DELAY_STOP)) { + dep->flags |= DWC3_EP_PENDING_NOOP_START; + } else { + ret = dwc3_gadget_ep_start_noop_transfer(dep); + if (ret < 0) + return ret; + } } out: @@ -1031,16 +1036,21 @@ out: return 0; } -void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status) +void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep, int status, + bool interrupt) { struct dwc3_request *req; - dwc3_stop_active_transfer(dep, false, false); + dwc3_stop_active_transfer(dep, false, interrupt); /* If endxfer is delayed, avoid unmapping requests */ if (dep->flags & DWC3_EP_DELAY_STOP) return; + /* Give the controller time to stop accessing the request buffers */ + if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) + mdelay(1); + /* - giveback all requests to gadget driver */ while (!list_empty(&dep->started_list)) { req = next_request(&dep->started_list); @@ -1089,7 +1099,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) dep->flags &= ~DWC3_EP_ENABLED; - dwc3_remove_requests(dwc, dep, -ESHUTDOWN); + dwc3_remove_requests(dwc, dep, -ESHUTDOWN, true); dep->stream_capable = false; dep->type = 0; @@ -1101,6 +1111,15 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep) */ if (dep->flags & DWC3_EP_DELAY_STOP) mask |= (DWC3_EP_DELAY_STOP | DWC3_EP_TRANSFER_STARTED); + + /* + * The End Transfer command is still in progress. Do not clear the + * flags, so that the ep is only rearmed once the command completes. + */ + if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) + mask |= (DWC3_EP_END_TRANSFER_PENDING | + DWC3_EP_TRANSFER_STARTED); + dep->flags &= mask; /* Clear out the ep descriptors for non-ep0 */ @@ -2553,7 +2572,7 @@ static void dwc3_stop_active_transfers(struct dwc3 *dwc) if (!dep) continue; - dwc3_remove_requests(dwc, dep, -ESHUTDOWN); + dwc3_remove_requests(dwc, dep, -ESHUTDOWN, false); } } @@ -3901,7 +3920,16 @@ static void dwc3_gadget_endpoint_command_complete(struct dwc3_ep *dep, dwc3_ep0_send_delayed_status(dwc); } + if (dep->flags & DWC3_EP_PENDING_NOOP_START) { + dep->flags &= ~DWC3_EP_PENDING_NOOP_START; + + if (!(dep->flags & DWC3_EP_DELAY_START) && + (dep->flags & DWC3_EP_ENABLED)) + dwc3_gadget_ep_start_noop_transfer(dep); + } + if ((dep->flags & DWC3_EP_DELAY_START) && + (dep->flags & DWC3_EP_ENABLED) && !usb_endpoint_xfer_isoc(dep->endpoint.desc)) __dwc3_gadget_kick_transfer(dep); From 7c9bc134e5b3315e0456cda9e8e59c752309ea78 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:38:19 +0000 Subject: [PATCH 21/45] usb: dwc3: gadget: Reset endpoint flags on controller start The flags of a disabled endpoint may be preserved while its End Transfer command is pending. If the command never completes, the stale flags persist across a soft disconnect or an error recovery, and the endpoint can't be used again. Reset the flags of all non-control endpoints when starting the controller. Fixes: 76bff31c7fba ("usb: dwc3: gadget: Do not clear ep delayed stop flag during ep disable") Cc: stable Signed-off-by: Thinh Nguyen Link: https://patch.msgid.link/21cd189962b9d32a4f9df381df4947d35341d5a9.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e531adc02a40..a8f12e583a0f 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2972,6 +2972,7 @@ static int __dwc3_gadget_start(struct dwc3 *dwc) { struct dwc3_ep *dep; int ret = 0; + u32 epnum; u32 reg; /* @@ -3029,6 +3030,15 @@ static int __dwc3_gadget_start(struct dwc3 *dwc) return ret; } + for (epnum = 2; epnum < dwc->num_eps; epnum++) { + dep = dwc->eps[epnum]; + if (!dep) + continue; + + dep->flags &= (DWC3_EP_TXFIFO_RESIZED | + DWC3_EP_RESOURCE_ALLOCATED); + } + dep = dwc->eps[0]; dep->flags = 0; ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT); From 61575534fb05d52d36979f38976ece74649f091a Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Wed, 21 Oct 2026 00:38:24 +0000 Subject: [PATCH 22/45] usb: dwc3: gadget: Recover from End Transfer timeout If the End Transfer command times out, the endpoint resource is never released and every subsequent Start Transfer to the endpoint fails with "No Resource". Schedule an error recovery to reset the controller. Signed-off-by: Thinh Nguyen Cc: stable Link: https://patch.msgid.link/7523e9a11303a33acd0b92a092fb0e8218d509d2.1792542945.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a8f12e583a0f..a76f669a796c 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1775,6 +1775,8 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc) return DWC3_DSTS_SOFFN(reg); } +static void dwc3_schedule_err_recovery(struct dwc3 *dwc); + /** * __dwc3_stop_active_transfer - stop the current active transfer * @dep: isoc endpoint @@ -1818,6 +1820,9 @@ static int __dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force, bool int dev_err_ratelimited(dep->dwc->dev, "end transfer failed: %d\n", ret); + if (ret == -ETIMEDOUT && dep->dwc->err_state == DWC3_ERR_NONE) + dwc3_schedule_err_recovery(dep->dwc); + dep->resource_index = 0; if (!interrupt || (ret && ret != -ETIMEDOUT)) From 03e3c33fe074ba57ae4457894fe5b6a90e3be6ee Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 15:24:52 +0100 Subject: [PATCH 23/45] thunderbolt: stream: Undo more if the start fails If the receive buffers cannot be allocated or mapped, tbstream_dev_start() stops and frees the rings, but - leaves the DMA paths through the XDomain connection enabled, with the hop IDs of rings which no longer exist; - does not release the frame array and the pages which tbstream_dev_alloc_rx_buffers() had allocated and mapped before it failed. Fixes: 6db21d817b43 ("thunderbolt: Add support for USB4STREAM") Cc: stable Cc: Andreas Noever Cc: Mika Westerberg Cc: Yehezkel Bernat Cc: Alan Borzeszkowski Signed-off-by: Josef Bacik Acked-by: Mika Westerberg (Intel) Link: https://patch.msgid.link/2026102751-nibble-synapse-d406@gregkh Signed-off-by: Greg Kroah-Hartman --- drivers/thunderbolt/stream.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/thunderbolt/stream.c b/drivers/thunderbolt/stream.c index 4f9a57b77bfa..c9e1987a6924 100644 --- a/drivers/thunderbolt/stream.c +++ b/drivers/thunderbolt/stream.c @@ -683,6 +683,12 @@ static int tbstream_dev_start(struct tbstream_dev *sdev) err_stop: tb_ring_stop(sdev->rx_ring.ring); tb_ring_stop(sdev->tx_ring.ring); + tb_xdomain_disable_paths(xd, sdev->out_hopid, + sdev->tx_ring.ring->hop, + sdev->in_hopid, + sdev->rx_ring.ring->hop); + if (sdev->rx_ring.frames) + tbstream_ring_free(&sdev->rx_ring); err_free_rx: tb_ring_free(sdev->rx_ring.ring); err_free_tx_buffers: From 1981b53c2b52a00f0f4b9eb87183c9aedc8dac5d Mon Sep 17 00:00:00 2001 From: Krystian Kaniewski Date: Thu, 22 Oct 2026 11:13:59 +0200 Subject: [PATCH 24/45] usb: gadget: u_serial: pin ports while TTYs are installed A slab-use-after-free can occur when gserial_free_line() frees struct gs_port while it is still reachable through an installed TTY. The port->port.count value tracks successful opens, but it is zero before gs_open() and again after gs_close(), before TTY cleanup has finished. Teardown can therefore free gs_port while tty_init_dev() or release_tty() still accesses its tty_port. Manage gs_port lifetime with tty_port references. Take a reference in gs_install(), drop it in gs_cleanup(), and move the final free to gs_port_destruct(). Unregister the TTY device before dropping the owner reference. Keep each minor reserved until the old port is destroyed so an installed TTY for one generation cannot overlap a replacement at the same minor. Publish the new port before device registration so the cdev and add uevent never expose a TTY before gs_install() can pin it. Since commit 8df07fe93573 ("tty: fix saved termios reset race"), u_serial registration no longer frees saved termios. On registration failure, unpublish the port before dropping its owner reference. Check in gs_open() that the installed port is still the published generation. Track failures after a successful install so close callbacks issued by the TTY core do not decrement port->port.count for opens that never incremented it. Fixes: 19b10a8828a6 ("usb: gadget: allocate & giveback serial ports instead hard code them") Assisted-by: Gemini:gemini-3.8-flash syzbot Reported-by: syzbot+fe63e4d633540f230624@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=fe63e4d633540f230624 Link: https://syzkaller.appspot.com/ai_job?id=ec789387-2e7b-4a8f-a7a1-a47bf7fa57f5 Cc: stable Signed-off-by: Krystian Kaniewski Tested-by: syzbot@syzkaller.appspotmail.com Tested-by: Mehmet Fide Reported-by: syzbot+bca09f5d8b843bbf7571@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=bca09f5d8b843bbf7571 Link: https://patch.msgid.link/20261022091359.1187468-1-krystianmkaniewski@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/u_serial.c | 167 ++++++++++++++++++++----- 1 file changed, 134 insertions(+), 33 deletions(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 892d2673e9b0..0a304f508bc3 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -70,10 +70,28 @@ * gserial->ioport == usb_ep->driver_data ... gs_port * gs_port->port_usb ... gserial * - * gs_port <---> tty_struct ... links will be null when the TTY file - * isn't opened; managed by gs_open()/gs_close() - * gserial->port_tty ... tty_struct - * tty_struct->driver_data ... gserial + * gs_port <---> tty_struct: + * tty->driver_data refers to gs_port from install through cleanup, + * pinning the port via tty_port reference counting. + * gs_port->port.tty exists only while the port is open. + * + * Each entry in ports[] is guarded by ports[i].lock and models three states: + * - Free: !port && !reserved + * - Published: port && reserved + * - Retiring: !port && reserved + * + * A minor remains reserved until gs_port_destruct() runs upon final tty_port + * release, preventing minor reuse while cleanup of the installed TTY is still + * underway. The owner reference is retained through device unregister so the + * destructor releases the reservation only after device teardown is complete. + * + * open_close_failures tracks failed gs_open() calls where port->port.count + * was not incremented. The TTY core calls gs_close() on open failure to tear + * down the tty; tracking failures as aggregate credits allows gs_close() to + * consume a credit and exit without decrementing port->port.count. Credits + * are aggregate rather than paired with individual files (another gs_close() + * can consume a failed open's credit before that file's own close runs). + * It is protected by tty_lock. */ /* RX and TX queues can buffer QUEUE_SIZE packets before they hit the @@ -128,6 +146,7 @@ struct gs_port { wait_queue_head_t close_wait; bool suspended; /* port suspended */ bool start_delayed; /* delay start when suspended */ + unsigned int open_close_failures; /* protected by tty_lock */ struct async_icount icount; /* REVISIT this state ... */ @@ -135,8 +154,9 @@ struct gs_port { }; static struct portmaster { - struct mutex lock; /* protect open/close */ + struct mutex lock; /* protect open/close and port slot */ struct gs_port *port; + bool reserved; } ports[MAX_U_SERIAL_PORTS]; #define GS_CLOSE_TIMEOUT 15 /* seconds */ @@ -603,22 +623,60 @@ static int gserial_wakeup_host(struct gserial *gser) /* TTY Driver */ +static int gs_install(struct tty_driver *driver, struct tty_struct *tty) +{ + struct gs_port *port; + struct tty_port *tport; + int ret; + + mutex_lock(&ports[tty->index].lock); + port = ports[tty->index].port; + if (!port) { + mutex_unlock(&ports[tty->index].lock); + return -ENODEV; + } + + tport = tty_port_get(&port->port); + if (!tport) { + mutex_unlock(&ports[tty->index].lock); + return -ENODEV; + } + + ret = tty_port_install(tport, driver, tty); + if (ret) { + mutex_unlock(&ports[tty->index].lock); + tty_port_put(tport); + return ret; + } + + tty->driver_data = port; + mutex_unlock(&ports[tty->index].lock); + + return 0; +} + +static void gs_cleanup(struct tty_struct *tty) +{ + tty_port_put(tty->port); +} + /* - * gs_open sets up the link between a gs_port and its associated TTY. - * That link is broken *only* by TTY close(), and all driver methods - * know that. + * gs_open associates an open TTY with its gs_port. + * + * There are two TTY-to-port relationships: port->port.tty exists from the + * first successful open until final close, while tty->driver_data is assigned + * during gs_install() and remains valid through gs_cleanup(). */ static int gs_open(struct tty_struct *tty, struct file *file) { int port_num = tty->index; - struct gs_port *port; + struct gs_port *port = tty->driver_data; int status = 0; mutex_lock(&ports[port_num].lock); - port = ports[port_num].port; - if (!port) { + if (ports[port_num].port != port) { status = -ENODEV; - goto out; + goto fail_unlock; } spin_lock_irq(&port->port_lock); @@ -638,7 +696,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) if (status) { pr_debug("gs_open: ttyGS%d (%p,%p) no buffer\n", port_num, tty, file); - goto out; + goto fail_unlock; } spin_lock_irq(&port->port_lock); @@ -648,7 +706,6 @@ static int gs_open(struct tty_struct *tty, struct file *file) if (port->port.count++) goto exit_unlock_port; - tty->driver_data = port; port->port.tty = tty; /* if connected, start the I/O stream */ @@ -672,7 +729,11 @@ static int gs_open(struct tty_struct *tty, struct file *file) exit_unlock_port: spin_unlock_irq(&port->port_lock); -out: + mutex_unlock(&ports[port_num].lock); + return status; + +fail_unlock: + port->open_close_failures++; mutex_unlock(&ports[port_num].lock); return status; } @@ -698,6 +759,11 @@ static void gs_close(struct tty_struct *tty, struct file *file) if (!port) return; + if (port->open_close_failures > 0) { + port->open_close_failures--; + return; + } + spin_lock_irq(&port->port_lock); if (port->port.count != 1) { @@ -912,8 +978,10 @@ static int gs_get_icount(struct tty_struct *tty, } static const struct tty_operations gs_tty_ops = { + .install = gs_install, .open = gs_open, .close = gs_close, + .cleanup = gs_cleanup, .write = gs_write, .put_char = gs_put_char, .flush_chars = gs_flush_chars, @@ -1206,14 +1274,41 @@ static void gs_console_exit(struct gs_port *port) #endif -static int +static void gs_port_destruct(struct tty_port *tport) +{ + struct gs_port *port = container_of(tport, struct gs_port, port); + unsigned int port_num = port->port_num; + + mutex_lock(&ports[port_num].lock); + if (WARN_ON(ports[port_num].port)) + ports[port_num].port = NULL; + WARN_ON(!ports[port_num].reserved); + if (gs_tty_driver) + gs_tty_driver->ports[port_num] = NULL; + ports[port_num].reserved = false; + mutex_unlock(&ports[port_num].lock); + + kfifo_free(&port->port_write_buf); + kfree(port); +} + +static const struct tty_port_operations gs_port_ops = { + .destruct = gs_port_destruct, +}; + +static struct gs_port * gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) { struct gs_port *port; int ret = 0; mutex_lock(&ports[port_num].lock); - if (ports[port_num].port) { + if (WARN_ON_ONCE(ports[port_num].port && !ports[port_num].reserved)) { + ret = -EBUSY; + goto out; + } + + if (ports[port_num].reserved) { ret = -EBUSY; goto out; } @@ -1225,6 +1320,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) } tty_port_init(&port->port); + port->port.ops = &gs_port_ops; spin_lock_init(&port->port_lock); init_waitqueue_head(&port->drain_wait); init_waitqueue_head(&port->close_wait); @@ -1238,10 +1334,14 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) port->port_num = port_num; port->port_line_coding = *coding; + ports[port_num].reserved = true; ports[port_num].port = port; + mutex_unlock(&ports[port_num].lock); + return port; + out: mutex_unlock(&ports[port_num].lock); - return ret; + return ERR_PTR(ret); } static int gs_closed(struct gs_port *port) @@ -1261,8 +1361,7 @@ static void gserial_free_port(struct gs_port *port) /* wait for old opens to finish */ wait_event(port->close_wait, gs_closed(port)); WARN_ON(port->port_usb != NULL); - tty_port_destroy(&port->port); - kfree(port); + tty_port_put(&port->port); } void gserial_free_line(unsigned char port_num) @@ -1279,15 +1378,15 @@ void gserial_free_line(unsigned char port_num) ports[port_num].port = NULL; mutex_unlock(&ports[port_num].lock); - gserial_free_port(port); tty_unregister_device(gs_tty_driver, port_num); + gserial_free_port(port); } EXPORT_SYMBOL_GPL(gserial_free_line); int gserial_alloc_line_no_console(unsigned char *line_num) { struct usb_cdc_line_coding coding; - struct gs_port *port; + struct gs_port *port = ERR_PTR(-EBUSY); struct device *tty_dev; int ret; int port_num; @@ -1298,19 +1397,20 @@ int gserial_alloc_line_no_console(unsigned char *line_num) coding.bDataBits = USB_CDC_1_STOP_BITS; for (port_num = 0; port_num < MAX_U_SERIAL_PORTS; port_num++) { - ret = gs_port_alloc(port_num, &coding); - if (ret == -EBUSY) - continue; - if (ret) + port = gs_port_alloc(port_num, &coding); + if (IS_ERR(port)) { + ret = PTR_ERR(port); + if (ret == -EBUSY) + continue; return ret; + } break; } - if (ret) - return ret; + if (IS_ERR(port)) + return PTR_ERR(port); /* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */ - port = ports[port_num].port; tty_dev = tty_port_register_device(&port->port, gs_tty_driver, port_num, NULL); if (IS_ERR(tty_dev)) { @@ -1319,14 +1419,15 @@ int gserial_alloc_line_no_console(unsigned char *line_num) ret = PTR_ERR(tty_dev); mutex_lock(&ports[port_num].lock); + WARN_ON(ports[port_num].port != port); ports[port_num].port = NULL; mutex_unlock(&ports[port_num].lock); - gserial_free_port(port); - goto err; + tty_port_put(&port->port); + return ret; } + *line_num = port_num; -err: - return ret; + return 0; } EXPORT_SYMBOL_GPL(gserial_alloc_line_no_console); From 78a8d6537f1de34770e460edee360b556ef40427 Mon Sep 17 00:00:00 2001 From: Sonali Pradhan Date: Wed, 28 Oct 2026 07:48:21 +0000 Subject: [PATCH 25/45] usb: gadget: f_midi: fix UAF race during IN request handling f_midi_disable() drains and frees pre-allocated IN requests from in_req_fifo without holding midi->transmit_lock. If f_midi_transmit() runs concurrently on the workqueue, f_midi_do_transmit() can peek a request from in_req_fifo and write into its buffer while f_midi_disable() frees it, leading to a use-after-free. Additionally, when usb_ep_queue() fails in f_midi_do_transmit() (such as with -ESHUTDOWN when the endpoint is disabled concurrently), it resets req->length = 0 and returns active instead of the error code, causing the do-while loop in f_midi_transmit() to keep spinning under midi->transmit_lock until the substream is drained. Fix this by acquiring midi->transmit_lock in f_midi_disable() while releasing IN requests from in_req_fifo, and returning the error code from f_midi_do_transmit() when usb_ep_queue() fails so f_midi_transmit() aborts immediately and drops active substreams. Fixes: e1e3d7ec5da3 ("usb: gadget: f_midi: pre-allocate IN requests") Cc: stable Signed-off-by: Sonali Pradhan Link: https://patch.msgid.link/20261028074821.579450-1-sonalipradhan@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_midi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index 63fb6ee70a3d..48cda34399e8 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -420,6 +420,7 @@ static void f_midi_disable(struct usb_function *f) struct f_midi *midi = func_to_midi(f); struct usb_composite_dev *cdev = f->config->cdev; struct usb_request *req = NULL; + unsigned long flags; DBG(cdev, "disable\n"); @@ -431,8 +432,10 @@ static void f_midi_disable(struct usb_function *f) usb_ep_disable(midi->out_ep); /* release IN requests */ + spin_lock_irqsave(&midi->transmit_lock, flags); while (kfifo_get(&midi->in_req_fifo, &req)) free_ep_req(midi->in_ep, req); + spin_unlock_irqrestore(&midi->transmit_lock, flags); f_midi_drop_out_substreams(midi); } @@ -661,6 +664,7 @@ static int f_midi_do_transmit(struct f_midi *midi, struct usb_ep *ep) ERROR(midi, "%s failed to queue req: %d\n", midi->in_ep->name, err); req->length = 0; /* Re-use request next time. */ + return err; } else { /* Upon success, put request at the back of the queue. */ kfifo_skip(&midi->in_req_fifo); From 78585f90feb3bbaf3b1c642294c8c47e451dc3cf Mon Sep 17 00:00:00 2001 From: Cosmin Tanislav Date: Mon, 17 Aug 2026 22:26:38 +0300 Subject: [PATCH 26/45] usb: gadget: f_ncm: restart the TX timer if the TX freelist is empty ncm_wrap_ntb() aggregates datagrams into a pending NTB, which is sent either when it becomes full, or after 300us since the NTB was started, using ndo_start_xmit() (eth_start_xmit()). ndo_start_xmit() returns NETDEV_TX_BUSY when the TX freelist is empty. For regular packets this is fine since the networking core will requeue them, but for timer-flushed packets there is no logic to handle this situation, and HRTIMER_NORESTART is returned from ncm_tx_timeout() without checking eth_start_xmit()'s return value. Under sustained TX saturation the request freelist is empty most of the time. Since the timer is never restarted, small packets keep getting accumulated into the NTB, until either TX_MAX_NUM_DPE packets are stored or NTB_DEFAULT_IN_SIZE is reached, which is an unknown amount of time. Check the return value of ndo_start_xmit() and restart the timer after another 300us. Cc: stable Fixes: 6d3865f9d41f ("usb: gadget: NCM: Add transmit multi-frame.") Signed-off-by: Cosmin Tanislav Tested-by: Vladyslav Tymoshchuk Tested-by: Leonardo Costa Reported-by: Hiago De Franco Closes: https://lore.kernel.org/all/20231204183751.64202-1-hiagofranco@gmail.com/ Link: https://patch.msgid.link/20260817192638.437798-1-cosmin-gabriel.tanislav.xa@renesas.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_ncm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 500c9c19c78b..ab6da3ef8783 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1148,6 +1148,7 @@ static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data) { struct f_ncm *ncm = container_of(data, struct f_ncm, task_timer); struct net_device *netdev = READ_ONCE(ncm->netdev); + netdev_tx_t ret; if (netdev) { /* XXX This allowance of a NULL skb argument to ndo_start_xmit @@ -1158,7 +1159,11 @@ static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data) * * This will call directly into u_ether's eth_start_xmit() */ - netdev->netdev_ops->ndo_start_xmit(NULL, netdev); + ret = netdev->netdev_ops->ndo_start_xmit(NULL, netdev); + if (ret == NETDEV_TX_BUSY) { + hrtimer_forward_now(data, TX_TIMEOUT_NSECS); + return HRTIMER_RESTART; + } } return HRTIMER_NORESTART; } From ca783a2d55b3361493917ad4a3573715ba902503 Mon Sep 17 00:00:00 2001 From: Hui Peng Date: Wed, 30 Sep 2026 07:52:47 +0000 Subject: [PATCH 27/45] USB: serial: garmin_gps: validate packet data length in nat_receive() In nat_receive() (called from garmin_write() when userspace writes to /dev/ttyUSBn in MODE_NATIVE mode), while garmin_data_p->insize is less than GARMIN_PKTHDR_LENGTH (12), the loop copies up to 12 bytes into garmin_data_p->inbuffer. Once garmin_data_p->insize reaches GARMIN_PKTHDR_LENGTH, nat_receive() computes the total packet size as: len = GARMIN_PKTHDR_LENGTH + getDataLength(garmin_data_p->inbuffer); Because getDataLength() returns a signed int from __le32_to_cpup(), a 12-byte header with a negative 32-bit length field (such as 0xfffffff5, i.e., -11) causes len to underflow to a small positive value (12 + (-11) = 1) without any bounds check at that point. Then garmin_data_p->insize >= len (12 >= 1) evaluates to true and nat_receive() calls garmin_write_bulk(port, inbuffer, 1, 0), which allocates a 1-byte slab buffer via kmemdup() and immediately reads 4 bytes from it in getLayerId(buffer) (and again in garmin_write_bulk_callback() when the URB completes): BUG: KASAN: slab-out-of-bounds in garmin_write_bulk.constprop.0+0x3eb/0x500 Read of size 4 at addr ffff888002cc0ba0 by task init/1 Call Trace: dump_stack_lvl+0x70/0xa0 print_report+0x153/0x4c6 kasan_report+0xf1/0x120 garmin_write_bulk.constprop.0+0x3eb/0x500 garmin_write+0x60f/0x1450 serial_write+0x123/0x200 n_tty_write+0x8ea/0xeb0 file_tty_write.isra.0+0x44f/0x7a0 vfs_write+0x671/0xd20 Validate the unsigned 32-bit data length (dlen >= GPS_IN_BUFSIZ - GARMIN_PKTHDR_LENGTH, matching the existing len >= GPS_IN_BUFSIZ bound) in nat_receive() as soon as the 12-byte header is present, resetting insize and returning -EINVPKT on invalid lengths so garmin_write_bulk() is only ever called with a full valid packet header (12 <= len < GPS_IN_BUFSIZ). Tested in QEMU against Linux 7.3.0-rc3 by emulating a Garmin USB GPS device (091e:0003) via dummy_hcd + raw-gadget, switching /dev/ttyUSB0 to MODE_NATIVE via PRIV_PKTID_SET_MODE, and writing a 12-byte native packet with data length 0xfffffff5: on the unfixed kernel this triggers KASAN slab-out-of-bounds reads in garmin_write_bulk() and garmin_write_bulk_callback(), whereas on the fixed kernel nat_receive() rejects the packet with -EINVPKT and 0 KASAN faults. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Hui Peng [ johan: move comment and dev_dbg(); add comment about redundant check ] Signed-off-by: Johan Hovold --- drivers/usb/serial/garmin_gps.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 8020149f5658..40df6f14e045 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -746,11 +746,7 @@ static int nat_receive(struct garmin_data *garmin_data_p, len = GARMIN_PKTHDR_LENGTH; if (len >= GPS_IN_BUFSIZ) { - /* seems to be an invalid packet, ignore rest - of input */ - dev_dbg(&garmin_data_p->port->dev, - "%s - packet size too large: %d\n", - __func__, len); + /* should never end up here given the dlen check below */ garmin_data_p->insize = 0; count = 0; result = -EINVPKT; @@ -769,8 +765,17 @@ static int nat_receive(struct garmin_data *garmin_data_p, /* do we have a complete packet ? */ if (garmin_data_p->insize >= GARMIN_PKTHDR_LENGTH) { - len = GARMIN_PKTHDR_LENGTH+ - getDataLength(garmin_data_p->inbuffer); + u32 dlen = getDataLength(garmin_data_p->inbuffer); + + if (dlen >= GPS_IN_BUFSIZ - GARMIN_PKTHDR_LENGTH) { + /* invalid packet, ignore rest of input */ + dev_dbg(&garmin_data_p->port->dev, "%s - invalid length: %u\n", + __func__, dlen); + garmin_data_p->insize = 0; + result = -EINVPKT; + break; + } + len = GARMIN_PKTHDR_LENGTH + dlen; if (garmin_data_p->insize >= len) { garmin_write_bulk(garmin_data_p->port, garmin_data_p->inbuffer, From a3d43b39032cc5565a5693a10c581844342372cd Mon Sep 17 00:00:00 2001 From: Tristan Madani Date: Mon, 19 Oct 2026 10:38:49 +0000 Subject: [PATCH 28/45] USB: serial: sierra: validate URB length in instat callback sierra_instat_callback() reads request fields and one byte past the usb_ctrlrequest header without first checking that urb->actual_length is large enough. A short USB interrupt transfer could cause an out-of-bounds read. Add two length checks matching the pattern already present in the option driver (option_instat_callback): one for the request header before accessing bRequestType, and one for the line-state data byte inside the serial-state notification handler. Use dev_err() since failing these checks causes the interrupt URB not to be resubmitted. Fixes: 033a3fb980b041 ("USB: Sierra Wireless driver update") Cc: stable@vger.kernel.org Signed-off-by: Tristan Madani [ johan: use sizeof(*req_pkt) consistently ] Signed-off-by: Johan Hovold --- drivers/usb/serial/sierra.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c index f2cc7f364d20..c6aa5dfe468b 100644 --- a/drivers/usb/serial/sierra.c +++ b/drivers/usb/serial/sierra.c @@ -575,12 +575,24 @@ static void sierra_instat_callback(struct urb *urb) __func__); return; } + if (urb->actual_length < sizeof(*req_pkt)) { + dev_err(&port->dev, "%s: short transfer\n", + __func__); + return; + } if ((req_pkt->bRequestType == 0xA1) && (req_pkt->bRequest == 0x20)) { int old_dcd_state; - unsigned char signals = *((unsigned char *) - urb->transfer_buffer + - sizeof(struct usb_ctrlrequest)); + unsigned char signals; + + if (urb->actual_length < sizeof(*req_pkt) + 1) { + dev_err(&port->dev, + "%s: short interrupt transfer\n", + __func__); + return; + } + signals = *((unsigned char *)urb->transfer_buffer + + sizeof(*req_pkt)); dev_dbg(&port->dev, "%s: signal x%x\n", __func__, signals); From 0e0b1fcfb80c0490bda7f7eb633ebb5e431c2e16 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Mon, 19 Oct 2026 14:34:12 +0200 Subject: [PATCH 29/45] USB: serial: upd78f0730: fix NULL-deref on hangup The port tty pointer is cleared on hangup before deasserting the modem control signals and should not be used in the dtr_rts() callback. Factor out a new upd78f0730_port_tiocmset() helper that can be used in upd78f0730_dtr_rts() to avoid dereferencing a NULL-pointer on hangup (e.g. on disconnect). This issue was flagged by an LLM. Fixes: ea534e0b4047 ("USB: serial: add uPD78F0730 USB to Serial Adaptor Driver") Cc: stable@vger.kernel.org # 4.11 Cc: Maksim Salau Signed-off-by: Johan Hovold --- drivers/usb/serial/upd78f0730.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/upd78f0730.c b/drivers/usb/serial/upd78f0730.c index 78c4d3c19a8e..f2189b994ed7 100644 --- a/drivers/usb/serial/upd78f0730.c +++ b/drivers/usb/serial/upd78f0730.c @@ -201,10 +201,9 @@ static int upd78f0730_tiocmget(struct tty_struct *tty) return res; } -static int upd78f0730_tiocmset(struct tty_struct *tty, +static int upd78f0730_port_tiocmset(struct usb_serial_port *port, unsigned int set, unsigned int clear) { - struct usb_serial_port *port = tty->driver_data; struct upd78f0730_port_private *private; struct upd78f0730_set_dtr_rts request; struct device *dev = &port->dev; @@ -238,6 +237,13 @@ static int upd78f0730_tiocmset(struct tty_struct *tty, return res; } +static int upd78f0730_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) +{ + struct usb_serial_port *port = tty->driver_data; + + return upd78f0730_port_tiocmset(port, set, clear); +} + static int upd78f0730_break_ctl(struct tty_struct *tty, int break_state) { struct upd78f0730_port_private *private; @@ -267,7 +273,6 @@ static int upd78f0730_break_ctl(struct tty_struct *tty, int break_state) static void upd78f0730_dtr_rts(struct usb_serial_port *port, int on) { - struct tty_struct *tty = port->port.tty; unsigned int set = 0; unsigned int clear = 0; @@ -276,7 +281,7 @@ static void upd78f0730_dtr_rts(struct usb_serial_port *port, int on) else clear = TIOCM_DTR | TIOCM_RTS; - upd78f0730_tiocmset(tty, set, clear); + upd78f0730_port_tiocmset(port, set, clear); } static speed_t upd78f0730_get_baud_rate(struct tty_struct *tty) From ae22e9b6412e5dc99e1cf8bd13c6176d44c7d42e Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:19 +0200 Subject: [PATCH 30/45] USB: serial: io_edgeport: fix NULL-deref on early status The driver submits the interrupt-in URB during probe or on first port open, which on completion may submit the bulk-in URB before all ports have been opened and their waitqueues have been initialised. If a (malicious) device sends a status message for a port that has not yet been opened this may lead to a NULL-pointer dereference in the bulk-in completion handler when attempting to wakeup blocked tasks. Move waitqueue initialisation from open() to port_probe() to address this. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+763813d65c7e18c1b6d5@syzkaller.appspotmail.com Link: https://lore.kernel.org/6a8818d8.ae6ddae5.3da009.0031.GAE@google.com Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index eaa8f00716c8..cdf41e86ba44 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -877,11 +877,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) } } - /* initialize our wait queues */ - init_waitqueue_head(&edge_port->wait_open); - init_waitqueue_head(&edge_port->wait_chase); - init_waitqueue_head(&edge_port->wait_command); - /* initialize our port settings */ edge_port->txCredits = 0; /* Can't send any data yet */ /* Must always set this bit to enable ints! */ @@ -2965,6 +2960,11 @@ static int edge_port_probe(struct usb_serial_port *port) return -ENOMEM; spin_lock_init(&edge_port->ep_lock); + + init_waitqueue_head(&edge_port->wait_open); + init_waitqueue_head(&edge_port->wait_chase); + init_waitqueue_head(&edge_port->wait_command); + edge_port->port = port; usb_set_serial_port_data(port, edge_port); From 839ff5fa30995c40cd5fba15fd976ad63416738a Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:20 +0200 Subject: [PATCH 31/45] USB: serial: io_edgeport: fix potential close() use-after-free Add the missing open check on write() and locking when updating the port status during close() to prevent a racing interrupt completion handler from trying to submit more data for the port while its write URB and FIFO are being deallocated. This issue was flagged by Sashiko when reviewing a related fix. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Link: https://sashiko.dev/#/patchset/20260714101316.823942-1-shpark061104%40gmail.com?part=1 Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index cdf41e86ba44..a5011fa91ee7 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -1085,7 +1085,9 @@ static void edge_close(struct usb_serial_port *port) /* port->close = true; */ edge_port->closePending = false; + spin_lock_irq(&edge_port->ep_lock); edge_port->open = false; + spin_unlock_irq(&edge_port->ep_lock); edge_port->openPending = false; usb_kill_urb(edge_port->write_urb); @@ -1127,6 +1129,12 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, spin_lock_irqsave(&edge_port->ep_lock, flags); + /* avoid accessing freed fifo if tty_wakeup() races with close() */ + if (!edge_port->open) { + spin_unlock_irqrestore(&edge_port->ep_lock, flags); + return 0; + } + /* calculate number of bytes to put in fifo */ copySize = min_t(unsigned int, count, (edge_port->txCredits - fifo->count)); From a0403880a0a638f189e5187068244d9fd5bc8d4d Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:21 +0200 Subject: [PATCH 32/45] USB: serial: io_edgeport: fix potential NULL-deref at open Do not mark the port as open until after the write FIFO has been allocated and initialised to prevent a racing interrupt completion from attempting to send stale data and dereference the FIFO buffer pointer. Note that the open flag defaults to false and is cleared on close() so there is no need to reinitialise it on every open(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index a5011fa91ee7..e8e641e9a197 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -885,9 +885,7 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) /* send a open port command */ edge_port->openPending = true; - edge_port->open = false; response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0); - if (response < 0) { dev_err(dev, "%s - error sending open port command\n", __func__); edge_port->openPending = false; @@ -897,8 +895,7 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) /* now wait for the port to be completely opened */ wait_event_timeout(edge_port->wait_open, !edge_port->openPending, OPEN_TIMEOUT); - - if (!edge_port->open) { + if (edge_port->openPending) { /* open timed out */ dev_dbg(dev, "%s - open timeout\n", __func__); edge_port->openPending = false; @@ -926,6 +923,10 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) return -ENOMEM; } + spin_lock_irq(&edge_port->ep_lock); + edge_port->open = true; + spin_unlock_irq(&edge_port->ep_lock); + dev_dbg(dev, "%s - Initialize TX fifo to %d bytes\n", __func__, edge_port->maxTxCredits); @@ -1818,7 +1819,6 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial, /* we have completed the open */ edge_port->openPending = false; - edge_port->open = true; wake_up(&edge_port->wait_open); return; } From febadc65a4ef8d08a12e76d6ec50834d72cc0e59 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:22 +0200 Subject: [PATCH 33/45] USB: serial: io_edgeport: move initial termios update to open() Explicitly update the terminal settings on open() instead of doing so from the interrupt completion handler when receiving an open command response, which in theory can be received after a failed open attempt. Note that this will be used to fix a FIFO corruption issue and also allows for switching to synchronous commands. Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 64 +++++--------------------------- 1 file changed, 10 insertions(+), 54 deletions(-) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index e8e641e9a197..cdcff02c435b 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -281,8 +281,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command, __u8 param); static int calc_baud_rate_divisor(struct device *dev, int baud_rate, int *divisor); -static void change_port_settings(struct tty_struct *tty, - struct edgeport_port *edge_port, +static void edge_set_termios(struct tty_struct *tty, struct usb_serial_port *port, const struct ktermios *old_termios); static int send_cmd_write_uart_register(struct edgeport_port *edge_port, __u8 regNum, __u8 regValue); @@ -923,6 +922,9 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) return -ENOMEM; } + if (tty) + edge_set_termios(tty, port, NULL); + spin_lock_irq(&edge_port->ep_lock); edge_port->open = true; spin_unlock_irq(&edge_port->ep_lock); @@ -1443,30 +1445,6 @@ static void edge_unthrottle(struct tty_struct *tty) } -/***************************************************************************** - * SerialSetTermios - * this function is called by the tty driver when it wants to change - * the termios structure - *****************************************************************************/ -static void edge_set_termios(struct tty_struct *tty, - struct usb_serial_port *port, - const struct ktermios *old_termios) -{ - struct edgeport_port *edge_port = usb_get_serial_port_data(port); - - if (edge_port == NULL) - return; - - if (!edge_port->open) { - dev_dbg(&port->dev, "%s - port not opened\n", __func__); - return; - } - - /* change the port settings to the new ones specified */ - change_port_settings(tty, edge_port, old_termios); -} - - /***************************************************************************** * get_lsr_info - get line status register info * @@ -1756,7 +1734,6 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial, { struct usb_serial_port *port; struct edgeport_port *edge_port; - struct tty_struct *tty; struct device *dev; __u8 code = edge_serial->rxStatusCode; @@ -1808,15 +1785,6 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial, __func__, edge_serial->rxPort, byte2, edge_port->txCredits); handle_new_msr(edge_port, byte2); - /* send the current line settings to the port so we are - in sync with any further termios calls */ - tty = tty_port_tty_get(&edge_port->port->port); - if (tty) { - change_port_settings(tty, - edge_port, &tty->termios); - tty_kref_put(tty); - } - /* we have completed the open */ edge_port->openPending = false; wake_up(&edge_port->wait_open); @@ -2328,18 +2296,12 @@ static int send_cmd_write_uart_register(struct edgeport_port *edge_port, } -/***************************************************************************** - * change_port_settings - * This routine is called to set the UART on the device to match the - * specified new settings. - *****************************************************************************/ - -static void change_port_settings(struct tty_struct *tty, - struct edgeport_port *edge_port, const struct ktermios *old_termios) +static void edge_set_termios(struct tty_struct *tty, struct usb_serial_port *port, + const struct ktermios *old_termios) { - struct device *dev = &edge_port->port->dev; - struct edgeport_serial *edge_serial = - usb_get_serial_data(edge_port->port->serial); + struct edgeport_serial *edge_serial = usb_get_serial_data(port->serial); + struct edgeport_port *edge_port = usb_get_serial_port_data(port); + struct device *dev = &port->dev; int baud; unsigned cflag; __u8 mask = 0xff; @@ -2350,12 +2312,6 @@ static void change_port_settings(struct tty_struct *tty, __u8 txFlow; int status; - if (!edge_port->open && - !edge_port->openPending) { - dev_dbg(dev, "%s - port not opened\n", __func__); - return; - } - cflag = tty->termios.c_cflag; switch (cflag & CSIZE) { @@ -2489,7 +2445,7 @@ static void change_port_settings(struct tty_struct *tty, dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud); status = send_cmd_write_baud_rate(edge_port, baud); - if (status == -1) { + if (status == -1 && old_termios) { /* Speed change was not possible - put back the old speed */ baud = tty_termios_baud_rate(old_termios); tty_encode_baud_rate(tty, baud, baud); From 270f76c3b88c9cc3d6ca58c5c0c0f34c2373b27c Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:23 +0200 Subject: [PATCH 34/45] USB: serial: io_edgeport: fix potential fifo corruption The device buffer size is determined during open() and the driver allocates a TX FIFO of corresponding size. Add the missing sanity check to prevent memory corruption in case a malicious device sends a second open response with a different buffer size. This issue was flagged by Sashiko when reviewing a related fix. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Link: https://sashiko.dev/#/patchset/20260714101316.823942-1-shpark061104%40gmail.com?part=1 Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index cdcff02c435b..b8fbcc8908d1 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -877,13 +877,17 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) } /* initialize our port settings */ + spin_lock_irq(&edge_port->ep_lock); edge_port->txCredits = 0; /* Can't send any data yet */ + edge_port->maxTxCredits = 0; + edge_port->openPending = true; + spin_unlock_irq(&edge_port->ep_lock); + /* Must always set this bit to enable ints! */ edge_port->shadowMCR = MCR_MASTER_IE; edge_port->chaseResponsePending = false; /* send a open port command */ - edge_port->openPending = true; response = send_iosp_ext_cmd(edge_port, IOSP_CMD_OPEN_PORT, 0); if (response < 0) { dev_err(dev, "%s - error sending open port command\n", __func__); @@ -1736,6 +1740,7 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial, struct edgeport_port *edge_port; struct device *dev; __u8 code = edge_serial->rxStatusCode; + unsigned long flags; /* switch the port pointer to the one being currently talked about */ if (edge_serial->rxPort >= edge_serial->serial->num_ports) @@ -1779,6 +1784,12 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial, } if (code == IOSP_STATUS_OPEN_RSP) { + spin_lock_irqsave(&edge_port->ep_lock, flags); + /* reject stray open responses to avoid FIFO corruption */ + if (!edge_port->openPending) { + spin_unlock_irqrestore(&edge_port->ep_lock, flags); + return; + } edge_port->txCredits = GET_TX_BUFFER_SIZE(byte3); edge_port->maxTxCredits = edge_port->txCredits; dev_dbg(dev, "%s - Port %u Open Response Initial MSR = %02x TxBufferSize = %d\n", @@ -1787,6 +1798,8 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial, /* we have completed the open */ edge_port->openPending = false; + spin_unlock_irqrestore(&edge_port->ep_lock, flags); + wake_up(&edge_port->wait_open); return; } From 50613e6380db7a904ef15c60ed0c436baf308f0a Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:24 +0200 Subject: [PATCH 35/45] USB: serial: io_edgeport: fix potential use-after-free on disconnect The driver submits command URBs asynchronously but fails to stop them on disconnect, something which could lead to a use-after-free when accessing driver data in the completion handler after a port has been unbound. Add an URB anchor to track and kill outstanding command URBs on disconnect. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index b8fbcc8908d1..0fe7495c47f4 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -225,6 +225,7 @@ struct edgeport_serial { __u8 rxStatusParam; /* the receive status parameter */ __s16 rxBytesRemaining; /* the number of port bytes left to read */ struct usb_serial *serial; /* loop back to the owner of this object */ + struct usb_anchor cmd_anchor; }; /* baud rate information */ @@ -261,9 +262,6 @@ static const struct divisor_table_entry divisor_table[] = { { 230400, 1}, }; -/* Number of outstanding Command Write Urbs */ -static atomic_t CmdUrbs = ATOMIC_INIT(0); - /* function prototypes */ @@ -776,11 +774,6 @@ static void edge_bulk_out_cmd_callback(struct urb *urb) struct device *dev = &urb->dev->dev; int status = urb->status; - atomic_dec(&CmdUrbs); - dev_dbg(dev, "%s - FREE URB %p (outstanding %d)\n", __func__, urb, - atomic_read(&CmdUrbs)); - - /* clean up the transfer buffer */ kfree(urb->transfer_buffer); @@ -2127,24 +2120,21 @@ static int write_cmd_usb(struct edgeport_port *edge_port, if (!urb) return -ENOMEM; - atomic_inc(&CmdUrbs); - dev_dbg(dev, "%s - ALLOCATE URB %p (outstanding %d)\n", - __func__, urb, atomic_read(&CmdUrbs)); - usb_fill_bulk_urb(urb, edge_serial->serial->dev, usb_sndbulkpipe(edge_serial->serial->dev, edge_serial->bulk_out_endpoint), buffer, length, edge_bulk_out_cmd_callback, edge_port); edge_port->commandPending = true; + usb_anchor_urb(urb, &edge_serial->cmd_anchor); status = usb_submit_urb(urb, GFP_ATOMIC); if (status) { /* something went wrong */ dev_err(dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __func__, status); + usb_unanchor_urb(urb); usb_free_urb(urb); - atomic_dec(&CmdUrbs); return status; } @@ -2696,6 +2686,7 @@ static int edge_startup(struct usb_serial *serial) spin_lock_init(&edge_serial->es_lock); edge_serial->serial = serial; + init_usb_anchor(&edge_serial->cmd_anchor); usb_set_serial_data(serial, edge_serial); /* get the name for the device from the device */ @@ -2900,6 +2891,8 @@ static void edge_disconnect(struct usb_serial *serial) { struct edgeport_serial *edge_serial = usb_get_serial_data(serial); + usb_kill_anchored_urbs(&edge_serial->cmd_anchor); + if (edge_serial->is_epic) { usb_kill_urb(edge_serial->interrupt_read_urb); usb_kill_urb(edge_serial->read_urb); From 6e4629504d7e5a22dd26f3b262f0a0f80e3cad6a Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Fri, 23 Oct 2026 14:15:25 +0200 Subject: [PATCH 36/45] USB: serial: io_edgeport: serialise MCR accesses Add a mutex to serialise modem control register updates to prevent concurrent tasks from interfering with each other. Note that the register updates are currently asynchronous so a task may read back a value which has not yet taken effect. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold --- drivers/usb/serial/io_edgeport.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c index 0fe7495c47f4..0fd68faa8427 100644 --- a/drivers/usb/serial/io_edgeport.c +++ b/drivers/usb/serial/io_edgeport.c @@ -168,6 +168,7 @@ struct edgeport_port { struct urb *write_urb; /* write URB for this port */ bool write_in_progress; /* 'true' while a write URB is outstanding */ spinlock_t ep_lock; + struct mutex mutex; __u8 shadowLCR; /* last LCR value received */ __u8 shadowMCR; /* last MCR value received */ @@ -877,7 +878,10 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port) spin_unlock_irq(&edge_port->ep_lock); /* Must always set this bit to enable ints! */ + mutex_lock(&edge_port->mutex); edge_port->shadowMCR = MCR_MASTER_IE; + mutex_unlock(&edge_port->mutex); + edge_port->chaseResponsePending = false; /* send a open port command */ @@ -1398,9 +1402,11 @@ static void edge_throttle(struct tty_struct *tty) /* if we are implementing RTS/CTS, toggle that line */ if (C_CRTSCTS(tty)) { + mutex_lock(&edge_port->mutex); edge_port->shadowMCR &= ~MCR_RTS; status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); + mutex_unlock(&edge_port->mutex); if (status != 0) return; } @@ -1435,9 +1441,11 @@ static void edge_unthrottle(struct tty_struct *tty) } /* if we are implementing RTS/CTS, toggle that line */ if (C_CRTSCTS(tty)) { + mutex_lock(&edge_port->mutex); edge_port->shadowMCR |= MCR_RTS; send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); + mutex_unlock(&edge_port->mutex); } } @@ -1478,6 +1486,7 @@ static int edge_tiocmset(struct tty_struct *tty, struct edgeport_port *edge_port = usb_get_serial_port_data(port); unsigned int mcr; + mutex_lock(&edge_port->mutex); mcr = edge_port->shadowMCR; if (set & TIOCM_RTS) mcr |= MCR_RTS; @@ -1496,6 +1505,7 @@ static int edge_tiocmset(struct tty_struct *tty, edge_port->shadowMCR = mcr; send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); + mutex_unlock(&edge_port->mutex); return 0; } @@ -1509,6 +1519,7 @@ static int edge_tiocmget(struct tty_struct *tty) unsigned int mcr; msr = edge_port->shadowMSR; + mutex_lock(&edge_port->mutex); mcr = edge_port->shadowMCR; result = ((mcr & MCR_DTR) ? TIOCM_DTR: 0) /* 0x002 */ | ((mcr & MCR_RTS) ? TIOCM_RTS: 0) /* 0x004 */ @@ -1516,6 +1527,7 @@ static int edge_tiocmget(struct tty_struct *tty) | ((msr & EDGEPORT_MSR_CD) ? TIOCM_CAR: 0) /* 0x040 */ | ((msr & EDGEPORT_MSR_RI) ? TIOCM_RI: 0) /* 0x080 */ | ((msr & EDGEPORT_MSR_DSR) ? TIOCM_DSR: 0); /* 0x100 */ + mutex_unlock(&edge_port->mutex); return result; } @@ -2430,12 +2442,14 @@ static void edge_set_termios(struct tty_struct *tty, struct usb_serial_port *por return; /* set up the MCR register and send it to the EdgePort */ + mutex_lock(&edge_port->mutex); edge_port->shadowMCR = MCR_MASTER_IE; if (cflag & CBAUD) edge_port->shadowMCR |= (MCR_DTR | MCR_RTS); status = send_cmd_write_uart_register(edge_port, MCR, edge_port->shadowMCR); + mutex_unlock(&edge_port->mutex); if (status != 0) return; @@ -2930,6 +2944,7 @@ static int edge_port_probe(struct usb_serial_port *port) return -ENOMEM; spin_lock_init(&edge_port->ep_lock); + mutex_init(&edge_port->mutex); init_waitqueue_head(&edge_port->wait_open); init_waitqueue_head(&edge_port->wait_chase); From f184ae84a5d19554d980a918a9c8baaef87ac301 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Tue, 27 Oct 2026 15:31:26 +0100 Subject: [PATCH 37/45] USB: serial: oti6858: fix the teardown order in close The driver passes a baton around: the completion handler of the interrupt urb either resubmits the urb, submits the read urb or schedules one of the two delayed works, and the works and the bulk completion handlers submit the interrupt urb again. oti6858_close() cancels the works first and kills the urbs afterwards. An interrupt urb that completes in between schedules a work again: oti6858_close() cancel_delayed_work_sync(setup) cancel_delayed_work_sync(write) oti6858_read_int_callback() schedule_delayed_work(setup) usb_kill_urb(interrupt_in_urb) /* not in flight */ setup_line() usb_submit_urb(interrupt_in_urb) The port is now closed with the baton still going round. The next open fails because the interrupt urb is already submitted, and if the device is unplugged, oti6858_port_remove() frees the private data while a work may be pending or running. Poison the interrupt urb first: that waits for the handler and makes all further submissions fail, so nothing schedules the works any more. Then cancel the works, after which only the bulk urbs are left, kill those, and make the interrupt urb usable again for the next open. Don't print an error for the submissions that fail with -EPERM in this window, as oti6858_read_bulk_callback() already does. Fixes: 49cdee0ed0fc ("USB: oti6858 usb-serial driver (in Nokia CA-42 cable)") Cc: stable Cc: Johan Hovold Signed-off-by: Josef Bacik Signed-off-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/oti6858.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index c6364e8ff71f..005fe19c3cd4 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c @@ -248,7 +248,7 @@ static void setup_line(struct work_struct *work) dev_dbg(&port->dev, "%s(): submitting interrupt urb\n", __func__); result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); - if (result != 0) { + if (result != 0 && result != -EPERM) { dev_err(&port->dev, "%s(): usb_submit_urb() failed with error %d\n", __func__, result); } @@ -300,7 +300,7 @@ static void send_data(struct work_struct *work) dev_dbg(&port->dev, "%s(): submitting interrupt urb\n", __func__); result = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO); - if (result != 0) { + if (result != 0 && result != -EPERM) { dev_err(&port->dev, "%s(): usb_submit_urb() failed with error %d\n", __func__, result); } @@ -561,6 +561,13 @@ static void oti6858_close(struct usb_serial_port *port) dev_dbg(&port->dev, "%s(): after buf_clear()\n", __func__); + /* + * The interrupt urb schedules the works, and the works and the bulk + * urbs resubmit the interrupt urb: keep it from being submitted until + * all of them are gone. + */ + usb_poison_urb(port->interrupt_in_urb); + /* cancel scheduled setup */ cancel_delayed_work_sync(&priv->delayed_setup_work); cancel_delayed_work_sync(&priv->delayed_write_work); @@ -569,7 +576,8 @@ static void oti6858_close(struct usb_serial_port *port) dev_dbg(&port->dev, "%s(): shutting down urbs\n", __func__); usb_kill_urb(port->write_urb); usb_kill_urb(port->read_urb); - usb_kill_urb(port->interrupt_in_urb); + + usb_unpoison_urb(port->interrupt_in_urb); } static int oti6858_tiocmset(struct tty_struct *tty, @@ -826,7 +834,7 @@ static void oti6858_write_bulk_callback(struct urb *urb) /* schedule the interrupt urb if we are still open */ dev_dbg(&port->dev, "%s(): submitting interrupt urb\n", __func__); result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); - if (result != 0) { + if (result != 0 && result != -EPERM) { dev_err(&port->dev, "%s(): failed submitting int urb," " error %d\n", __func__, result); } From ab89a9dab02d9553eb0cc27fd3e4a4998acbc8e9 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 29 Oct 2026 11:18:28 +0100 Subject: [PATCH 38/45] USB: serial: garmin_gps: fix deadlock on reset request The garmin_gps driver has a reset feature that is supposed to reset the device when writing a private reset request packet. The reset is however done synchronously from the write() callback (and without holding the required device lock) which leads to a deadlock in the line discipline when hanging up the port as part of disconnect. Switch to using the asynchronous reset interface while dropping the redundant and synchronous stopping of the interrupt urb (write() callbacks are supposed to be atomic and USB core, USB serial core and the driver itself will unlink and kill all URBs during disconnect). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Josef Bacik Link: https://lore.kernel.org/2026102733-prayer-drainer-56f3@gregkh Cc: stable@vger.kernel.org Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold --- drivers/usb/serial/garmin_gps.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 40df6f14e045..a7c18a8fdf59 100644 --- a/drivers/usb/serial/garmin_gps.c +++ b/drivers/usb/serial/garmin_gps.c @@ -823,10 +823,9 @@ static void priv_status_resp(struct usb_serial_port *port) * Garmin specific driver functions ******************************************************************************/ -static int process_resetdev_request(struct usb_serial_port *port) +static void process_resetdev_request(struct usb_serial_port *port) { unsigned long flags; - int status; struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); spin_lock_irqsave(&garmin_data_p->lock, flags); @@ -835,13 +834,8 @@ static int process_resetdev_request(struct usb_serial_port *port) garmin_data_p->serial_num = 0; spin_unlock_irqrestore(&garmin_data_p->lock, flags); - usb_kill_urb(port->interrupt_in_urb); - dev_dbg(&port->dev, "%s - usb_reset_device\n", __func__); - status = usb_reset_device(port->serial->dev); - if (status) - dev_dbg(&port->dev, "%s - usb_reset_device failed: %d\n", - __func__, status); - return status; + dev_dbg(&port->dev, "%s - usb_queue_reset_device\n", __func__); + usb_queue_reset_device(port->serial->interface); } From 6895dbdc19d927a2872bd4f111e1911874d5dce4 Mon Sep 17 00:00:00 2001 From: Yiyu Zhou Date: Thu, 29 Oct 2026 22:43:24 +0200 Subject: [PATCH 39/45] xhci: give back TDs and clean up ep0 after disconnect Fix a regression in v7.3 introduced by the commits in the Fixes tags. Those patches avoid endpoint recovery and rapid state changes after the root port link is lost. This caused a regression in device enumeration. It turns out that a subset of USB HID devices briefly disconnect during enumeration. USB core manages to resuscitate these devices without reallocating them, and thus continue using the same udev, xhci vdev and default control endpoint (ep0) of the device. xhci didn't give back or clean up halted TDs behind disconnected ports as it assumed that the disconnect cancels all URBs, and drops and frees all endpoints. This is not the case, so cancel and give back TDs on halted endpoint behind disconnected ports, make sure ep0 is cleared and in a proper state to continue working even after a link error or disconnect is detected. Also prevent new URBs until device is reset. One issue related to the TDs not being given back was seen on a PFU HHKB Professional HYBRID Type-S keyboard (04fe:0021). It drops off the bus about 300 ms after its first enumeration, while usbhid is still probing its third interface. The probe runs in hub_wq, so the disconnect is not handled until the probe returns. On a root port the HID descriptor request and its four retries in hid_get_class_descriptor() each wait for the full 5 second USB_CTRL_GET_TIMEOUT: [57685.006036] usb 3-2: new full-speed USB device number 24 using xhci_hcd ... [57685.291304] hid-generic 0003:04FE:0021.0017: input,hidraw1: USB HID v1.11 Keyboard [PFU Limited HHKB-Hybrid] on usb-0000:00:14.0-2/input1 [57711.221083] usbhid 3-2:1.2: can't add hid device: -110 [57711.221613] usbhid 3-2:1.2: probe with driver usbhid failed with error -110 [57711.221842] usb 3-2: USB disconnect, device number 24 [mn: merge EP_DROP_PENDING and link_inactive checks in xhci_urb_enqueue(), return TDs and clean up ep0 on disconnect, rewrite commit message] Fixes: 042aad8d0db6 ("xhci: prevent endpoint recovery after roothub disconnect") Fixes: 7e0ef4332ed9 ("xhci: avoid xHC endpoint changes after disconnect or link error.") Cc: stable Closes: https://lore.kernel.org/all/20261010071811.20483-1-yiyu@yiyuzhou.io/ Closes: https://lore.kernel.org/linux-usb/4MjB9K-2SoiA85WbI9iEig@dsine.de/ Tested-by: Yiyu Zhou Tested-by: Dennis Wissel Signed-off-by: Yiyu Zhou Co-developed-by: Mathias Nyman Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261029204324.658845-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-ring.c | 73 ++++++++++++++++++++++++++++++------ drivers/usb/host/xhci.c | 13 ++++--- 2 files changed, 69 insertions(+), 17 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index c23434001e9c..a1fa188680f5 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -65,6 +65,7 @@ static int queue_command(struct xhci_hcd *xhci, struct xhci_command *cmd, u32 field1, u32 field2, u32 field3, u32 field4, bool command_must_succeed); +static void xhci_kill_endpoint_urbs(struct xhci_hcd *xhci, int slot_id, int ep_index); /* * Returns zero if the TRB isn't in this segment, otherwise it returns the DMA @@ -962,6 +963,24 @@ static void xhci_giveback_invalidated_tds(struct xhci_hcd *xhci, struct xhci_vir } } +static void xhci_cancel_ring_tds(struct xhci_hcd *xhci, struct xhci_virt_ep *ep, + struct xhci_ring *ring, int td_status) +{ + struct xhci_td *tmp_td; + struct xhci_td *td; + + /* Add all TDs on ring to cancelled td list */ + list_for_each_entry_safe(td, tmp_td, &ring->td_list, td_list) { + if (list_empty(&td->cancelled_td_list)) { + list_add_tail(&td->cancelled_td_list, + &ep->cancelled_td_list); + td->cancel_status = TD_DIRTY; + if (!td->status) + td->status = td_status; + } + } +} + static int xhci_reset_halted_ep(struct xhci_hcd *xhci, unsigned int slot_id, unsigned int ep_index, enum xhci_ep_reset_type reset_type) { @@ -993,33 +1012,64 @@ static int xhci_handle_halted_endpoint(struct xhci_hcd *xhci, { struct xhci_port *rhub_port = ep->vdev->rhub_port; unsigned int slot_id = ep->vdev->slot_id; + bool disconnected = false; + struct xhci_ring *ring; int err; - /* - * Avoid resetting endpoint if link is inactive or device disconnected. - * Can cause host hang. - * Device will be reset to recover an inactive link, so don't do anything - */ + /* link is inactive or device disconnected */ if (rhub_port->link_inactive || !rhub_port->connected) { ep->ep_state |= EP_DROP_PENDING; - return -ENODEV; + disconnected = true; + if (!td && ep->ep_index != 0) { + xhci_kill_endpoint_urbs(xhci, slot_id, ep->ep_index); + return -ENODEV; + } } - /* add td to cancelled list and let reset ep handler take care of it */ - if (reset_type == EP_HARD_RESET) { - ep->ep_state |= EP_HARD_CLEAR_TOGGLE; + /* Add halted td to cancelled list and let reset ep handler take care of it */ + if (reset_type == EP_HARD_RESET || disconnected) { if (td && list_empty(&td->cancelled_td_list)) { list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); td->cancel_status = TD_HALTED; + if (disconnected && !td->status) + td->status = -EPROTO; } } + /* + * Avoid resetting non-ep0 endpoints if link is inactive or device + * disconnected. Can cause host hang. + * Endpoints other than ep0 won't restart before the device is reset or + * the endpoint is dropped, so cancel all TDs, and give back non-ep0 TDs + * now instead of letting them time out. Ep0 can survive a short device + * disconnect during enumeration so reset ep0 normally and clean it up. + */ + if (disconnected) { + ring = td ? xhci_urb_to_transfer_ring(xhci, td->urb) : ep->ring; + xhci_cancel_ring_tds(xhci, ep, ring, -ESHUTDOWN); + if (ep->ep_index != 0) { + xhci_dbg(xhci, "Not resetting ep %u slot %u after disconnect\n", + ep->ep_index, slot_id); + + xhci_process_cancelled_tds(xhci, ep); + xhci_kill_endpoint_urbs(xhci, slot_id, ep->ep_index); + return -ENODEV; + } + /* hard-reset a halted disconnected ep0 */ + xhci_dbg(xhci, "Reset and clean up ep0 slot %u after disconnect\n", + slot_id); + reset_type = EP_HARD_RESET; + } + if (ep->ep_state & EP_HALTED) { xhci_dbg(xhci, "Reset ep command for ep_index %d already pending\n", ep->ep_index); return 0; } + if (reset_type == EP_HARD_RESET) + ep->ep_state |= EP_HARD_CLEAR_TOGGLE; + err = xhci_reset_halted_ep(xhci, slot_id, ep->ep_index, reset_type); if (err) return err; @@ -1070,8 +1120,9 @@ static int xhci_invalidate_cancelled_tds(struct xhci_hcd *xhci, struct xhci_virt continue; } - /* device disconnected or link error, ep will be dropped */ - if (ep->ep_state & EP_DROP_PENDING) { + /* device disconnected or link error, non-ep0 endpoints will be dropped */ + if (ep->ep_state & EP_DROP_PENDING && ep->ep_index != 0) { + td_to_noop(xhci, ep, td, false); td->cancel_status = TD_CLEARED; continue; } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 30ac1bc4559b..b50a582be1fb 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1665,12 +1665,6 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag goto free_priv; } - if (xhci->devs[slot_id]->rhub_port->link_inactive) { - xhci_dbg(xhci, "Can't queue urb, port error, link inactive\n"); - ret = -ENODEV; - goto free_priv; - } - if (xhci->xhc_state & XHCI_STATE_DYING) { xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for non-responsive xHCI host.\n", urb->ep->desc.bEndpointAddress, urb); @@ -1680,6 +1674,13 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag ep_state = &xhci->devs[slot_id]->eps[ep_index].ep_state; + if (xhci->devs[slot_id]->rhub_port->link_inactive || + *ep_state & EP_DROP_PENDING) { + xhci_dbg(xhci, "Can't queue urb, port disconnect or link inactive\n"); + ret = -ENODEV; + goto free_priv; + } + if (*ep_state & (EP_GETTING_STREAMS | EP_GETTING_NO_STREAMS)) { xhci_warn(xhci, "WARN: Can't enqueue URB, ep in streams transition state %x\n", *ep_state); From b8320a8b5650096873ae8c0377b8fa1226b15fe0 Mon Sep 17 00:00:00 2001 From: Jacob Riff Date: Fri, 30 Oct 2026 20:24:00 -0700 Subject: [PATCH 40/45] usb: typec: ucsi: retry init only while the PPM is not ready Commit 254261381538 ("usb: typec: ucsi: retry init when the PPM answers early commands incorrectly") makes ucsi_init_work() retry ucsi_init() on -ENODEV and -EINVAL, a hundred times over ten seconds, to cover a PPM that is not ready to answer commands correctly for a short window during boot. It catches more than that. ucsi_register_port() also fails with -ENODEV when no USB role switch is available, and logs that at error level, so every retry runs it again and logs it again. Where a machine without a usable role switch used to log ucsi_acpi USBC000:00: error -ENODEV: con1: failed to get usb role switch ucsi_acpi USBC000:00: error -ENODEV: PPM init failed it now logs a hundred and one copies of the first line, followed by "PPM init failed, stop trying", on every boot, and the retries can never succeed there. Have ucsi_init() report the two not-ready cases as -EAGAIN instead: GET_CAPABILITY reporting zero connectors, and the PPM rejecting a standard command (-EINVAL from ucsi_read_error(), the only -EINVAL expected once the PPM reset has succeeded). Retry only -EAGAIN and, as before that commit, -EPROBE_DEFER. Every other error is reported once and init stops, as it did before. Also give -EAGAIN its own budget. The hundred retries over ten seconds belong to the USB role switch wait. On the machine the retry was written for, every observed failure recovered on the first or second retry, so ten retries over one second is plenty. A PPM that permanently rejects a command now logs "possible UCSI driver bug" up to eleven times in that second, on hardware where init already failed before. Fixes: 254261381538 ("usb: typec: ucsi: retry init when the PPM answers early commands incorrectly") Reported-by: Linus Torvalds Closes: https://lore.kernel.org/r/CAHk-=wjGk9rBTphk1OAwcqGAE1__KJgMr3B-8X4hKFPX8Wm=BQ@mail.gmail.com Signed-off-by: Jacob Riff Link: https://patch.msgid.link/20261031032400.38349-1-jacob@riff.dk Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/ucsi/ucsi.c | 37 +++++++++++++++++++++++++---------- drivers/usb/typec/ucsi/ucsi.h | 1 + 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 2f9adf4f8bde..9e453d216c16 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -2106,7 +2106,7 @@ static int ucsi_init(struct ucsi *ucsi) goto err_reset; if (!ucsi->cap.num_connectors) { - ret = -ENODEV; + ret = -EAGAIN; goto err_reset; } /* Check if reserved bit set. This is out of spec but happens in buggy FW */ @@ -2172,6 +2172,16 @@ err_unregister: err_reset: memset(&ucsi->cap, 0, sizeof(ucsi->cap)); ucsi_reset_ppm(ucsi); + + /* + * The only -EINVAL expected on this path is ucsi_read_error()'s: + * the PPM rejected a standard command. Some PPMs do that, or + * report zero connectors above, for a short while after boot + * before they are ready. Report both as -EAGAIN so that + * ucsi_init_work() can retry them, and only them. + */ + if (ret == -EINVAL) + ret = -EAGAIN; err: return ret; } @@ -2249,16 +2259,23 @@ static void ucsi_init_work(struct work_struct *work) } /* - * On some platforms the PPM is not ready to answer commands - * correctly for a short window during boot: standard commands are - * rejected or GET_CAPABILITY reports zero connectors, seen as - * -EINVAL or -ENODEV from ucsi_init(), and a retry moments later - * succeeds (observed on Lenovo ThinkPad X1 Carbon Gen 14, where - * this affects roughly half of all boots). Retry those like the - * USB role switch wait instead of giving up on the first attempt. + * -EPROBE_DEFER: the USB role switch is not registered yet. Wait + * up to ten seconds for it. + * + * -EAGAIN: the PPM is not ready to answer commands correctly yet. + * On some platforms that lasts for a short window during boot + * (observed on Lenovo ThinkPad X1 Carbon Gen 14, where it affects + * roughly half of all boots and a retry moments later succeeds). + * One second is plenty for that. + * + * Anything else is not going to change with a retry, so report it + * once and stop. */ - if (ret == -EPROBE_DEFER || ret == -ENODEV || ret == -EINVAL) { - if (ucsi->work_count++ < UCSI_ROLE_SWITCH_WAIT_COUNT) { + if (ret == -EPROBE_DEFER || ret == -EAGAIN) { + int limit = ret == -EPROBE_DEFER ? UCSI_ROLE_SWITCH_WAIT_COUNT : + UCSI_PPM_READY_WAIT_COUNT; + + if (ucsi->work_count++ < limit) { dev_dbg(ucsi->dev, "PPM init failed (%pe), retrying\n", ERR_PTR(ret)); queue_delayed_work(system_dfl_long_wq, &ucsi->work, diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 1996f04ed5e6..140d34e90c7c 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -491,6 +491,7 @@ struct ucsi { #define UCSI_ROLE_SWITCH_RETRY_PER_HZ 10 #define UCSI_ROLE_SWITCH_INTERVAL (HZ / UCSI_ROLE_SWITCH_RETRY_PER_HZ) #define UCSI_ROLE_SWITCH_WAIT_COUNT (10 * UCSI_ROLE_SWITCH_RETRY_PER_HZ) +#define UCSI_PPM_READY_WAIT_COUNT (1 * UCSI_ROLE_SWITCH_RETRY_PER_HZ) /* PPM Communication lock */ struct mutex ppm_lock; From bb261776d1a29768b8fd84eb4f42d99dafa29c93 Mon Sep 17 00:00:00 2001 From: Mathias Nyman Date: Thu, 5 Nov 2026 19:51:02 +0200 Subject: [PATCH 41/45] xhci: keep port link_inactive and connected flags in sync when polled Update port 'link_inactive' and 'connected' flags even if xHC isn't generating port change events. xHC only generates port change events on port changes after old port change bits are cleared. Hub driver is often kept up to date by polling the port status. Sashiko reported a possible case where all port changes after a port reset take place before hub driver clears the reset change bit. This way the port can end up connected and fully running with link in u0 without a port event clearing the 'link_inactive' or setting the 'connected' flags. A protocol STALL in this state would set EP_DROP_PENDING, and prevent all future URBs for the endpoint. Fix this by also updating the flags during get_port_status(), when hub driver is polling the port state. Fixes: 6895dbdc19d9 ("xhci: give back TDs and clean up ep0 after disconnect") Link: https://lore.kernel.org/linux-usb/sashiko-outbox-190046@kernel.org/ Cc: stable Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261105175106.241182-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-hub.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index 470bafe1802b..55430b673f1e 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1166,6 +1166,12 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd, struct xhci_bus_state *bus_ if (portsc & PORT_RESET) status |= USB_PORT_STAT_RESET; + /* track connect and link error status when hub is polling */ + if (!(portsc & PORT_RESET)) { + port->link_inactive = (portsc & PORT_PLS_MASK) == XDEV_INACTIVE; + port->connected = !!(portsc & PORT_CONNECT); + } + /* USB2 and USB3 specific bits, including Port Link State */ if (hcd->speed >= HCD_USB3) xhci_get_usb3_port_status(port, &status, portsc); From 2f2fe3201029ffc215b46ac40a0a9587715bc43a Mon Sep 17 00:00:00 2001 From: Xu Rao Date: Thu, 5 Nov 2026 19:51:03 +0200 Subject: [PATCH 42/45] usb: xhci: disable the correct slot on alloc_dev failure xhci_alloc_dev() stores the Slot ID returned by the Enable Slot command in the local slot_id variable. udev->slot_id is updated only after xhci_alloc_virt_device() succeeds. If endpoint resource reservation or virtual device allocation fails before that update, the error path passes udev->slot_id to xhci_disable_and_free_slot(). During initial enumeration this is slot 0. When reallocating a device whose virtual device is missing or belongs to another usb_device, udev->slot_id may contain a stale Slot ID. The newly enabled slot can therefore remain active, or the wrong slot can be disabled. Pass slot_id, which identifies the slot enabled by this invocation. xhci_disable_and_free_slot() already handles a missing xhci->devs entry. Fixes: 3ffbba9511b4 ("USB: xhci: Allocate and address USB devices") Cc: stable@vger.kernel.org Signed-off-by: Xu Rao Reviewed-by: Niklas Neronin Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261105175106.241182-3-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index b50a582be1fb..94da0268b7b3 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4301,7 +4301,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) return 1; disable_slot: - xhci_disable_and_free_slot(xhci, udev->slot_id); + xhci_disable_and_free_slot(xhci, slot_id); return 0; } From 5550405351199fe78f4a3cd606c07f5ad7220e1b Mon Sep 17 00:00:00 2001 From: Rishabh Jain Date: Thu, 5 Nov 2026 19:51:04 +0200 Subject: [PATCH 43/45] usb: pci-quirks: always assert xHCI OS ownership The xHCI ownership protocol requires the OS driver to assert the HC OS Owned semaphore before using the host controller, then wait for HC BIOS Owned to clear if firmware owns it. quirk_usb_handoff_xhci() currently asserts OS Owned only when BIOS Owned is already set. If firmware leaves BIOS Owned clear, Linux uses the xHC while both ownership semaphores remain clear. The timeout fallback also clears BIOS Owned using the original register value, which can clear OS Owned at the same time. On an AMD PROM21 xHCI controller (1022:43fc), this caused every S3 resume to terminate Controller Restore State with USBSTS 0x401. Linux then reset the host controller, both root hubs and the USB Bluetooth adapter. The controller entered resume ready and halted with USBSTS 0x1. Endpoint state, 100 ms save/restore delays, scratchpads, the DCBAA, device contexts and command, event and transfer rings were verified not to cause the restore error. Across four S3 cycles, asserting only HC OS Owned changed USBLEGSUP from 0x00000801 to 0x01000801 and eliminated the restore failure. Testing included the unmodified 7.1.8-ogc1.1.fc44.x86_64 distribution kernel using a test module that set the HC OS Owned semaphore. The same test was repeated after review with the same result. Clearing USBLEGCTLSTS was independently verified to be unnecessary. Always assert OS Owned for controllers using the standard xHCI handoff, and leave the existing TI/Renesas forced handoff unchanged. Keep OS Owned asserted after the standard handoff, including when forcing BIOS Owned clear after a timeout, to prevent firmware from reclaiming the controller during subsequent suspends. Fixes: 66d4eadd8d06 ("USB: xhci: BIOS handoff and HW initialization.") Cc: stable@vger.kernel.org Reviewed-by: Mario Limonciello (AMD) Tested-by: McKenna Fan Tested-by: Quinn Schive Tested-by: Bruno Filipe Tested-by: Maciej Zonski Signed-off-by: Rishabh Jain Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261105175106.241182-4-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/pci-quirks.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c index f670e7aab984..1dbfd697a582 100644 --- a/drivers/usb/host/pci-quirks.c +++ b/drivers/usb/host/pci-quirks.c @@ -1195,10 +1195,11 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev) && pdev->device == 0x0014)) { val = (val | XHCI_HC_OS_OWNED) & ~XHCI_HC_BIOS_OWNED; writel(val, base + ext_cap_offset); - } - - /* If the BIOS owns the HC, signal that the OS wants it, and wait */ - if (val & XHCI_HC_BIOS_OWNED) { + } else { + /* + * Perform the standard handoff and leave OS ownership set to + * keep the BIOS at bay during subsequent suspends. + */ writel(val | XHCI_HC_OS_OWNED, base + ext_cap_offset); /* Wait for 1 second with 10 microsecond polling interval */ @@ -1210,7 +1211,9 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev) dev_warn(&pdev->dev, "xHCI BIOS handoff failed (BIOS bug ?) %08x\n", val); - writel(val & ~XHCI_HC_BIOS_OWNED, base + ext_cap_offset); + writel((val | XHCI_HC_OS_OWNED) & + ~XHCI_HC_BIOS_OWNED, + base + ext_cap_offset); } } From d1ec1859f3b8641e3e5c5953cc7dd8e63b54339f Mon Sep 17 00:00:00 2001 From: Niklas Neronin Date: Thu, 5 Nov 2026 19:51:05 +0200 Subject: [PATCH 44/45] usb: xhci: clear stale bandwidth data after hibernation Controllers using software managed bandwidth accounting maintain periodic endpoint bandwidth information in struct 'xhci_interval_bw_table'. Each root hub port owns a bandwidth table and a list of TT bandwidth domains, where each TT has its own bandwidth table. Virtual devices reference the bandwidth table of their current bandwidth domain through 'bw_table' or 'tt_info'. Historically, resume from S4 reinitialized the entire xHCI driver state, which implicitly cleared all bandwidth accounting data. After the hibernation resume path was optimized to preserve parts of the driver state, virtual devices and TT bandwidth information were freed and recreated, but the root hub bandwidth tables were left intact. As a result, stale bandwidth accounting data could remain in the root hub bandwidth tables across hibernation resume, leading to incorrect bandwidth calculations after devices were rediscovered. Fix this by resetting all bandwidth accounting data in xhci_rh_bw_cleanup() so that resume starts with a clean bandwidth state, and resetting the total active endpoints count. Fixes: 2a70e5dc0301 ("usb: xhci: optimize resuming from S4 (suspend-to-disk)") Reported-by: Harald Judt Link: https://bugzilla.kernel.org/show_bug.cgi?id=222071 Suggested-by: Lovekesh Solanki Tested-by: Harald Judt Cc: stable Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261105175106.241182-5-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci-mem.c | 16 +++++++++++++++- drivers/usb/host/xhci.c | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index af8d4b74c4ba..75577f441cdd 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1903,24 +1903,38 @@ EXPORT_SYMBOL_GPL(xhci_remove_secondary_interrupter); void xhci_rh_bw_cleanup(struct xhci_hcd *xhci) { struct xhci_root_port_bw_info *rh_bw; + struct xhci_interval_bw_table *bw_table; + struct xhci_interval_bw *interval_bw; struct xhci_tt_bw_info *tt_info, *tt_next; struct list_head *eps, *ep, *ep_next; for (int i = 0; i < xhci->max_ports; i++) { rh_bw = &xhci->rh_bw[i]; + rh_bw->num_active_tts = 0; /* Clear and free all TT bandwidth entries */ list_for_each_entry_safe(tt_info, tt_next, &rh_bw->tts, tt_list) { list_del(&tt_info->tt_list); kfree(tt_info); } + bw_table = &rh_bw->bw_table; + bw_table->interval0_esit_payload = 0; + bw_table->bw_used = 0; + bw_table->ss_bw_in = 0; + bw_table->ss_bw_out = 0; + /* Clear per-interval endpoint lists */ for (int j = 0; j < XHCI_MAX_INTERVAL; j++) { - eps = &rh_bw->bw_table.interval_bw[j].endpoints; + interval_bw = &bw_table->interval_bw[j]; + eps = &interval_bw->endpoints; + interval_bw->num_packets = 0; list_for_each_safe(ep, ep_next, eps) list_del_init(ep); + interval_bw->overhead[LS_OVERHEAD_TYPE] = 0; + interval_bw->overhead[FS_OVERHEAD_TYPE] = 0; + interval_bw->overhead[HS_OVERHEAD_TYPE] = 0; } } } diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 94da0268b7b3..a762dd010e8d 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1185,6 +1185,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool power_lost, bool is_auto_resume) for (int i = xhci->max_slots; i > 0; i--) xhci_free_virt_devices_depth_first(xhci, i); + xhci->num_active_eps = 0; xhci_rh_bw_cleanup(xhci); xhci->cmd_ring_reserved_trbs = 0; From 3149e8b3237f58d4dd440fc64c45c93404c4b064 Mon Sep 17 00:00:00 2001 From: Niklas Neronin Date: Thu, 5 Nov 2026 19:51:06 +0200 Subject: [PATCH 45/45] usb: xhci: fix 'num_active_eps' accounting on allocation failure For controllers affected by XHCI_EP_LIMIT_QUIRK, endpoint resources for the default control endpoint are accounted before the virtual device is allocated. If xhci_alloc_virt_device() fails, the slot is disabled and cleanup is handled through the Disable Slot completion path. However, because no virtual device is installed in 'xhci->devs', the endpoint accounting is never released and 'num_active_eps' remains incremented. As a result, each allocation failure leaks one endpoint from the driver's accounting. Fix this by undoing the endpoint reservation when virtual device allocation fails. Signed-off-by: Niklas Neronin Signed-off-by: Mathias Nyman Link: https://patch.msgid.link/20261105175106.241182-6-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index a762dd010e8d..fc1b0a6b0429 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -4280,6 +4280,11 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev) */ if (!xhci_alloc_virt_device(xhci, slot_id, udev, GFP_NOIO)) { xhci_warn(xhci, "Could not allocate xHCI USB device data structures\n"); + if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) { + spin_lock_irqsave(&xhci->lock, flags); + xhci->num_active_eps -= 1; + spin_unlock_irqrestore(&xhci->lock, flags); + } goto disable_slot; } vdev = xhci->devs[slot_id];