From: sashiko-bot@kernel.org
To: "Arun Iyengar" <aiyengar1990@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v5 1/2] usb: core: Pair ports of different hubs through their connector
Date: Wed, 18 Nov 2026 05:13:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-220149@kernel.org> (raw)
In-Reply-To: <20261118-usb-port-pairing-v5-1-5f1a26789270@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: core: broken connector peer lookup in
usb_of_get_connector_peer()
- [Medium] usb: core: wrong connect_type fallback in
usb_hub_create_port_device()
--
commit b5e6aabc1813e83de610f267477e491f798833aa
Author: Arun Iyengar <aiyengar1990@gmail.com>
usb: core: Pair ports of different hubs through their connector
This commit pairs USB 2.0 and SuperSpeed ports belonging to different hubs
when they are linked to the same usb-connector node in the Device Tree, and
looks up root hub connect_type using the raw controller port number.
> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index a6ee20d8774e3..df789cef265c4 100644
> --- a/drivers/usb/core/of.c
> +++ b/drivers/usb/core/of.c
> @@ -145,6 +145,93 @@ enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub, int p
[ ... ]
> +struct device_node *usb_of_get_connector_peer(struct usb_device *hub, u32 port,
> + bool superspeed, u32 *peer_port)
> +{
> + struct device_node *np = hub->dev.of_node;
> + struct device_node *ep, *con, *remote, *peer = NULL;
> + u32 remote_port;
> +
> + if (!np || !of_graph_is_present(np))
> + return NULL;
> +
> + ep = of_graph_get_endpoint_by_regs(np, port, -1);
> + if (!ep)
> + return NULL;
> +
> + con = of_graph_get_remote_port_parent(ep);
> + of_node_put(ep);
> + if (!con)
> + return NULL;
> +
> + if (!usb_of_is_connector(con) || !of_device_is_available(con))
> + goto out;
> +
> + remote = usb_of_connector_remote(con, superspeed ? 1 : 0, &remote_port);
> + if (!remote)
> + goto out;
> + of_node_put(remote);
> + if (remote != np || remote_port != port)
> + goto out;
> +
> + /* Same-node peers are paired by port number */
> + peer = usb_of_connector_remote(con, superspeed ? 0 : 1, peer_port);
> + if (peer && (peer == np || !*peer_port ||
> + !of_device_is_available(peer))) {
> + of_node_put(peer);
> + peer = NULL;
> + }
> +out:
> + of_node_put(con);
> + return peer;
> +}
> +EXPORT_SYMBOL_GPL(usb_of_get_connector_peer);
> +
> /**
> * usb_of_get_interface_node() - get a USB interface node
> * @udev: USB device of interface
> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> index b4452b665f591..da7037bbbf57f 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -649,10 +649,44 @@ static int match_location(struct usb_device *peer_hdev, void *p)
> return 0;
> }
>
> +static u32 usb_port_graph_id(struct usb_device *hdev, int port1)
> +{
> + if (hdev->parent)
> + return port1;
> + return usb_hcd_find_raw_port_number(bus_to_hcd(hdev->bus), port1);
> +}
> +
> +struct usb_connector_peer {
> + struct usb_port *port_dev;
> + struct usb_port *peer;
> + struct device_node *np;
> + u32 port;
> +};
> +
> +static int match_connector_peer(struct usb_device *peer_hdev, void *p)
> +{
> + struct usb_connector_peer *cp = p;
> + struct usb_hub *peer_hub = usb_hub_to_struct_hub(peer_hdev);
> + int port1;
> +
> + if (!peer_hub || !peer_hdev->maxchild ||
> + peer_hdev->dev.of_node != cp->np ||
> + hub_is_superspeed(peer_hdev) == cp->port_dev->is_superspeed)
> + return 0;
> +
> + for (port1 = 1; port1 <= peer_hdev->maxchild; port1++) {
> + if (usb_port_graph_id(peer_hdev, port1) == cp->port) {
> + cp->peer = peer_hub->ports[port1 - 1];
> + break;
> + }
> + }
> + return 1;
> +}
> +
> /*
> * Find the peer port either via explicit platform firmware "location"
> - * data, the peer hcd for root hubs, or the upstream peer relationship
> - * for all other hubs.
> + * data, a DT connector, the peer hcd for root hubs, or the upstream peer
> + * relationship for all other hubs.
> */
> static void find_and_link_peer(struct usb_hub *hub, int port1)
> {
> @@ -660,6 +694,7 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
> struct usb_device *hdev = hub->hdev;
> struct usb_device *peer_hdev;
> struct usb_hub *peer_hub;
> + struct usb_connector_peer cp;
>
> /*
> * If location data is available then we can only peer this port
> @@ -671,7 +706,27 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
> /* we link the peer in match_location() if found */
> usb_for_each_dev(port_dev, match_location);
> return;
> - } else if (!hdev->parent) {
> + }
> +
> + cp.np = usb_of_get_connector_peer(hdev, usb_port_graph_id(hdev, port1),
> + port_dev->is_superspeed, &cp.port);
> + if (cp.np) {
> + bool found;
> +
> + cp.port_dev = port_dev;
> + cp.peer = NULL;
> + found = usb_for_each_dev(&cp, match_connector_peer);
> + of_node_put(cp.np);
> + if (cp.peer)
> + link_peers_report(port_dev, cp.peer);
> + /* Without the peer hub yet, wait for it */
> + if (cp.peer || !found) {
> + port_dev->connector_peer = true;
> + return;
> + }
> + }
[Severity: High]
Can a USB 2.0 hub port end up neither connector-peered nor default-peered when
connector port 1 points to a dwc3 controller using the standard snps,dwc3
binding (port@0 for High-Speed, port@1 for SuperSpeed) or to an intermediate
non-hub node such as a Type-C mux or PHY?
When find_and_link_peer() runs for a USB 2.0 port (superspeed == false),
usb_of_get_connector_peer() inspects connector port 1. Unlike a lookup from
the SuperSpeed side (where a dwc3 High-Speed endpoint at port@0 is filtered
out by !*peer_port), a dwc3 SuperSpeed endpoint at port@1 (as on
arch/arm64/boot/dts/rockchip/rk3576-lckfb-tspi-3m.dts, where usb_a_3_0 links
usb_hub port@1 to usb_drd1_dwc3 port@1) or a mux/PHY endpoint with reg >= 1
passes the !*peer_port check and is returned as cp.np with cp.port = 1.
In match_connector_peer(), a dwc3 SuperSpeed root hub port has
usb_port_graph_id() == 2 (from xhci_find_raw_port_number()), so it never
matches cp.port == 1, and a non-hub mux/PHY node never matches any usb_device
on usb_bus_type. Whenever the USB 2.0 hub probes before the SuperSpeed root
hub (or when cp.np is not a hub), found is false, so find_and_link_peer() sets
port_dev->connector_peer = true and returns early, skipping default peering
and preventing the peer from linking later.
[ ... ]
> @@ -766,7 +822,11 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
> return -ENOMEM;
> }
>
> - port_dev->connect_type = usb_of_get_connect_type(hdev, port1);
> + graph_id = usb_port_graph_id(hdev, port1);
> + port_dev->connect_type = usb_of_get_connect_type(hdev, graph_id);
> + /* dwc3 graphs give the SuperSpeed port port@1 */
> + if (port_dev->connect_type == USB_PORT_NOT_USED && graph_id != port1)
> + port_dev->connect_type = usb_of_get_connect_type(hdev, port1);
[Severity: Medium]
Does falling back to usb_of_get_connect_type(hdev, port1) misclassify a
SuperSpeed root hub port by matching the USB 2.0 child device or graph
endpoint at raw port 1?
On split-roothub controllers such as xHCI, the USB 2.0 and SuperSpeed root
hubs share hdev->dev.of_node, and child USB device nodes under the controller
use raw controller port numbers (so reg = <1> is High-Speed raw port 1). For
SuperSpeed root hub port 1 (port1 = 1, graph_id = 2), whenever
usb_of_get_connect_type(hdev, 2) returns USB_PORT_NOT_USED (either because the
DT uses dwc3 port@1 numbering or because SuperSpeed port 2 is unused), calling
usb_of_get_connect_type(hdev, 1) checks usb_of_get_device_node(hdev, 1) and
port@1:
drivers/usb/core/of.c:usb_of_get_connect_type() {
...
child = usb_of_get_device_node(hub, port1);
if (of_device_is_available(child))
connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED;
of_node_put(child);
return connect_type;
}
For example, on rk3576-lckfb-tspi-3m.dts, usb_drd1_dwc3 has both an onboard
USB 2.0 hub child node hub@1 (reg = <1>) and ports/port@1 for the external
SuperSpeed Type-A connector. The fallback matches hub@1 and marks the
external SuperSpeed port as USB_PORT_CONNECT_TYPE_HARD_WIRED, causing
set_usb_port_removable() to treat hotplugged SuperSpeed devices as fixed and
usb_dev_authorized() to auto-authorize them under
USB_DEVICE_AUTHORIZE_INTERNAL.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-usb-port-pairing-v5-0-5f1a26789270@gmail.com?part=1
next prev parent reply other threads:[~2026-11-18 5:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 4:34 [PATCH v5 0/2] usb: core: Pair ports of different host controllers through their connector Arun Iyengar via B4 Relay
2026-11-18 4:34 ` [PATCH v5 1/2] usb: core: Pair ports of different hubs " Arun Iyengar via B4 Relay
2026-11-18 5:13 ` sashiko-bot [this message]
2026-11-18 4:34 ` [PATCH v5 2/2] usb: hub: Retry SuperSpeed for a device stuck on its USB 2.0 peer Arun Iyengar via B4 Relay
2026-11-18 4:56 ` 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-220149@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=linux-usb@vger.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