From: sashiko-bot@kernel.org
To: "Qianhui Xu" <xiaqinghuan@mail.ustc.edu.cn>
Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 2/3] usb: roles: look up role switches attached to a graph endpoint
Date: Mon, 26 Oct 2026 12:59:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-185254@kernel.org> (raw)
In-Reply-To: <20261026123211.243224-3-xiaqinghuan@mail.ustc.edu.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] usb: roles: propagate -EPROBE_DEFER from usb_role_switch_at_endpoint()
--
commit 9ff4dd8101d254581dbf9332fc352de1c83d6e87
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
usb: roles: look up role switches attached to a graph endpoint
This patch adds usb_role_switch_at_endpoint() to look up a USB role switch
registered on a remote OF graph endpoint and calls it from
usb_role_switch_get() and fwnode_usb_role_switch_get() after checking the
caller's parent node.
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index edec139b68b52..fc739fd61f033 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -157,6 +157,42 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)
> return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
> }
>
> +/*
> + * Look up a role switch registered against the remote endpoint of one of the
> + * caller's OF graph endpoints. This is how a connector endpoint that shares a
> + * USB data bus with another connector (for example two Type-C receptacles on a
> + * single DWC3 controller, selected by a GPIO mux) finds its own role switch.
> + */
> +static struct usb_role_switch *
> +usb_role_switch_at_endpoint(struct fwnode_handle *fwnode)
> +{
> + struct fwnode_handle *ep, *remote, *parent;
> + struct usb_role_switch *sw;
> + bool available;
> +
> + fwnode_graph_for_each_endpoint(fwnode, ep) {
> + parent = fwnode_graph_get_remote_port_parent(ep);
> + if (!parent)
> + continue;
> + available = fwnode_device_is_available(parent);
> + fwnode_handle_put(parent);
> + if (!available)
> + continue;
> +
> + remote = fwnode_graph_get_remote_endpoint(ep);
> + if (!remote)
> + continue;
> + sw = usb_role_switch_match(remote, "usb-role-switch", NULL);
> + fwnode_handle_put(remote);
> + if (!IS_ERR_OR_NULL(sw)) {
> + fwnode_handle_put(ep);
> + return sw;
> + }
[Severity: High]
Should this check be if (sw) instead of if (!IS_ERR_OR_NULL(sw)) so that
probe deferral is propagated to the caller?
In drivers/usb/roles/class.c, usb_role_switch_match() returns NULL when the
remote endpoint does not have the "usb-role-switch" property, and returns
ERR_PTR(-EPROBE_DEFER) when the property is present on the endpoint node
but the role switch device has not been registered yet:
drivers/usb/roles/class.c:usb_role_switch_match() {
if (id && !fwnode_property_present(fwnode, id))
return NULL;
dev = class_find_device_by_fwnode(&role_class, fwnode);
return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
}
Because usb_role_switch_at_endpoint() checks !IS_ERR_OR_NULL(sw),
ERR_PTR(-EPROBE_DEFER) is ignored when a connector consumer calls
usb_role_switch_get() or fwnode_usb_role_switch_get() before the USB
controller driver registers the endpoint role switch.
usb_role_switch_at_endpoint() then returns NULL, and both
usb_role_switch_get() and fwnode_usb_role_switch_get() fall through to
connection matching (which checks the remote port parent node rather than
the endpoint node) and ultimately return NULL instead of
ERR_PTR(-EPROBE_DEFER), causing consumer drivers to treat the role switch
as absent rather than deferring probe.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026123211.243224-1-xiaqinghuan@mail.ustc.edu.cn?part=2
next prev parent reply other threads:[~2026-10-26 12:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:32 [PATCH v4 0/3] usb: dwc3: support two connectors sharing one HS data bus Qianhui Xu
2026-10-26 12:32 ` [PATCH v4 1/3] dt-bindings: usb: snps,dwc3: describe two connectors sharing one HS bus Qianhui Xu
2026-10-26 12:50 ` sashiko-bot
2026-10-26 12:32 ` [PATCH v4 2/3] usb: roles: look up role switches attached to a graph endpoint Qianhui Xu
2026-10-26 12:59 ` sashiko-bot [this message]
2026-10-26 12:32 ` [PATCH v4 3/3] usb: dwc3: support two connectors sharing one HS data bus Qianhui Xu
2026-10-26 13:20 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-185254@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xiaqinghuan@mail.ustc.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.