devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Elson Serrao" <elson.serrao@oss.qualcomm.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v6 6/9] usb: misc: qcom_eud: add role-based EUD control
Date: Tue, 11 Aug 2026 21:54:06 +0000	[thread overview]
Message-ID: <20260811215406.7FD161F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260811213610.2956147-7-elson.serrao@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Incorrect devres ordering causes a use-after-unmap vulnerability during driver removal.
- [Medium] Missing rollback on downstream USB role switch failure causes permanent state desynchronization and PHY power leak.
--

--- Patch [6]: [PATCH v6 6/9] usb: misc: qcom_eud: add role-based EUD control ---
commit bc0de19142343d10fe6a60512025d0e334d88fb3
Author: Elson Serrao <elson.serrao@oss.qualcomm.com>

usb: misc: qcom_eud: add role-based EUD control

EUD functions by presenting itself as a USB device to the host PC and is
therefore only applicable when the port operates in device role. This patch
updates the driver to treat EUD as usable only in device role, modifying the
role-switch callback to enable or disable EUD accordingly.

> diff --git a/drivers/usb/misc/qcom_eud.c b/drivers/usb/misc/qcom_eud.c
> index e83a4402e4b84..538e070cc140a 100644
> --- a/drivers/usb/misc/qcom_eud.c
> +++ b/drivers/usb/misc/qcom_eud.c
[ ... ]
> @@ -304,7 +323,30 @@ static irqreturn_t handle_eud_irq_thread(int irq, void *data)
>  static int eud_role_switch_set(struct usb_role_switch *sw, enum usb_role role)
>  {
>  	struct eud_path *path = usb_role_switch_get_drvdata(sw);
> -	int ret;
> +	struct eud_chip *chip = path->chip;
> +	int ret = 0;
> +
> +	guard(mutex)(&chip->state_lock);
> +
> +	/*
> +	 * EUD is usable only in device role. Power it down for every other
> +	 * role to avoid keeping an unusable module 'ON'. chip->enabled
> +	 * preserves user's sysfs configuration and is not modified across
> +	 * role transitions.
> +	 */
> +	if (chip->enabled && path->num == chip->port_idx && role != path->curr_role) {
> +		if (role == USB_ROLE_DEVICE)
> +			ret = enable_eud(chip);
> +		else if (path->curr_role == USB_ROLE_DEVICE)
> +			ret = disable_eud(chip);
> +
> +		if (ret) {
> +			dev_err(chip->dev, "failed to %s EUD for role %s: %d\n",
> +				str_enable_disable(role == USB_ROLE_DEVICE),
> +				usb_role_string(role), ret);
> +			return ret;
> +		}
> +	}
>  
>  	/* Forward the role request to the USB controller */
>  	ret = usb_role_switch_set_role(path->controller_sw, role);

[Severity: Medium]
If the downstream controller rejects the role switch and returns an error,
does this leave the EUD hardware state out of sync?

Looking at eud_role_switch_set(), if we were transitioning to USB_ROLE_DEVICE,
we already called enable_eud(). If usb_role_switch_set_role() then fails,
the function returns without updating path->curr_role or rolling back the
physical enable:

    ret = usb_role_switch_set_role(path->controller_sw, role);
    if (ret) {
        dev_err(...);
        return ret;
    }

Since path->curr_role remains out of sync with the physical state, will future
transitions to USB_ROLE_NONE evaluate (role != path->curr_role) as false and
permanently skip calling disable_eud(), leaving the PHY powered on?

[ ... ]
> @@ -431,6 +473,8 @@ static int eud_probe(struct platform_device *pdev)
>  
>  	chip->dev = &pdev->dev;
>  
> +	mutex_init(&chip->state_lock);
> +
>  	for_each_child_of_node_scoped(np, child) {
>  		ret = eud_init_path(chip, child);
>  		if (ret)

[Severity: High]
Does registering the role switch here create a devres ordering issue with the
I/O memory mapping?

In eud_probe(), the USB role switch is registered via eud_init_path() before
chip->base is mapped via devm_platform_ioremap_resource() later in the probe
function.

Since devres callbacks run in strictly reverse order, during driver teardown
chip->base will be unmapped before the role switch is unregistered. If a
concurrent role switch event arrives during this window, eud_role_switch_set()
could see chip->enabled == true and call enable_eud(), which writes to the
already unmapped chip->base.

Could this lead to a panic or page fault during driver removal?

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

  reply	other threads:[~2026-08-11 21:54 UTC|newest]

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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20260811215406.7FD161F00A3A@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;
as well as URLs for NNTP newsgroup(s).