Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Elson Serrao" <elson.serrao@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 5/9] usb: misc: qcom_eud: improve enable_store API
Date: Mon, 03 Aug 2026 03:25:43 +0000	[thread overview]
Message-ID: <20260803032544.46D6C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260803031534.2942628-6-elson.serrao@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the sysfs store handlers (`enable_store` and `port_store`) lack synchronization, exposing a critical TOCTOU race and hardware state corruption. While this patch attempts to avoid redundant hardware operations by adding a check `if (chip->enabled == enable)`, the check is performed without a lock. If multiple threads concurrently write '1' to the `enable` attribute, both can observe `chip->enabled == false`, bypass the check, and invoke `enable_eud()` simultaneously. This results in duplicate unsynchronized MMIO writes and unbalanced calls to `phy_init()` and `phy_power_on()`, permanently leaking PHY internal power/init reference counts. Furthermore, because `port_store` is also unprotected, a concurrent write to `port` can modify `chip->port_idx` while `enable_eud()` is executing. This can cause the driver to enable the PHY on one port but later disable the PHY on the other port, leading to permanent hardware resource leaks and corrupted PHY state.
--

--- Patch [5]: [PATCH v5 5/9] usb: misc: qcom_eud: improve enable_store API ---
commit daa70bf1af36bae927820d34ca275135da4718d1
Author: Elson Serrao <elson.serrao@oss.qualcomm.com>

usb: misc: qcom_eud: improve enable_store API

This commit adds a state check to enable_store() to skip redundant 
operations when the EUD is already in the desired state. It also 
improves error handling by explicitly logging failures.

> diff --git a/drivers/usb/misc/qcom_eud.c b/drivers/usb/misc/qcom_eud.c
> --- a/drivers/usb/misc/qcom_eud.c
> +++ b/drivers/usb/misc/qcom_eud.c
> @@ -162,18 +162,27 @@ static ssize_t enable_store(struct device *dev,
>  	if (kstrtobool(buf, &enable))
>  		return -EINVAL;
>  
> +	/* Skip operation if already in desired state */
> +	if (chip->enabled == enable)
> +		return count;
> +
>  	if (enable) {
>  		ret = enable_eud(chip);

[Severity: High]
This isn't a bug introduced by this patch, but does the lack of 
synchronization in this sysfs store handler expose a race condition?

If multiple threads concurrently write to the enable attribute, could both
observe chip->enabled == false, bypass this new check, and invoke
enable_eud() simultaneously?

Would this result in duplicate unsynchronized MMIO writes and unbalanced
calls to phy_init() and phy_power_on(), permanently leaking PHY internal
power and initialization reference counts?

Furthermore, because port_store() is also unprotected, can a concurrent
write to port modify chip->port_idx while enable_eud() is executing?

drivers/usb/misc/qcom_eud.c:port_store() {
...
	/* Port selection must be done before enabling EUD */
	if (chip->enabled)
		return -EBUSY;

	writel(port, chip->base + EUD_REG_PORT_SEL);
	chip->port_idx = port;
...
}

Could this interleaving cause the driver to enable the PHY on one port but
later disable the PHY on the other port, leading to corrupted hardware state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260803031534.2942628-1-elson.serrao@oss.qualcomm.com?part=5

  reply	other threads:[~2026-08-03  3:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03  3:15 [PATCH v5 0/9] Improve Qualcomm EUD driver and platform support Elson Serrao
2026-08-03  3:15 ` [PATCH v5 1/9] dt-bindings: soc: qcom: eud: Add per-path child nodes for UTMI routing Elson Serrao
2026-08-03  3:23   ` sashiko-bot
2026-08-03  3:15 ` [PATCH v5 2/9] usb: misc: qcom_eud: add sysfs attribute for port selection Elson Serrao
2026-08-03  3:25   ` sashiko-bot
2026-08-03  3:15 ` [PATCH v5 3/9] usb: misc: qcom_eud: add per-path High-Speed PHY control Elson Serrao
2026-08-03  3:28   ` sashiko-bot
2026-08-03  3:15 ` [PATCH v5 4/9] usb: misc: qcom_eud: add per-path role switch support Elson Serrao
2026-08-03  3:30   ` sashiko-bot
2026-08-03  9:37   ` Peter Chen
2026-08-03  3:15 ` [PATCH v5 5/9] usb: misc: qcom_eud: improve enable_store API Elson Serrao
2026-08-03  3:25   ` sashiko-bot [this message]
2026-08-03  3:15 ` [PATCH v5 6/9] usb: misc: qcom_eud: add role-based EUD control Elson Serrao
2026-08-03  3:27   ` sashiko-bot
2026-08-03  9:50   ` Peter Chen
2026-08-03  3:15 ` [PATCH v5 7/9] usb: misc: qcom_eud: fix virtual attach/detach event handling Elson Serrao
2026-08-03  3:26   ` sashiko-bot
2026-08-03  3:15 ` [PATCH v5 8/9] arm64: dts: qcom: kodiak: Describe EUD UTMI path using child node Elson Serrao
2026-08-03  3:54   ` sashiko-bot
2026-08-03  3:15 ` [PATCH v5 9/9] arm64: dts: qcom: Map USB connector to EUD on Kodiak boards Elson Serrao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260803032544.46D6C1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=elson.serrao@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox