Devicetree
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wenst@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: "Chen-Yu Tsai" <wenst@chromium.org>,
	"Alan Stern" <stern@rowland.harvard.edu>,
	linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
	"Matthias Kaehlcke" <mka@chromium.org>,
	"Stephen Boyd" <swboyd@chromium.org>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"Johan Hovold" <johan@kernel.org>,
	"Mathias Nyman" <mathias.nyman@linux.intel.com>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Bjorn Andersson" <andersson@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 3/4] usb: misc: onboard_usb_dev: Create pdevs for secondary root hubs
Date: Fri,  4 Dec 2026 10:52:41 +0800	[thread overview]
Message-ID: <20261204025243.807657-4-wenst@chromium.org> (raw)
In-Reply-To: <20261204025243.807657-1-wenst@chromium.org>

onboard_dev_create_pdevs() previously skipped root hubs of secondary
(USB 3.x) HCDs because both the primary and secondary root hubs share
the same HCD device tree node, and usb_of_get_device_node() did not map
root hub port numbers to raw port numbers. Scanning both root hubs
would have queried the same 1..maxchild reg values twice; on the second
pass, of_platform_device_create() would reject the already-populated
(OF_POPULATED) device node and log a "failed to create platform device"
error.

Now that usb_of_get_device_node() resolves root hub port numbers via
usb_hcd_find_raw_port_number(), primary and secondary root hubs on xHCI
controllers map to disjoint raw port ranges. Returning early for
secondary root hubs means onboard_dev_create_pdevs() now only visits
the primary (USB 2.0) root hub's ports and never creates platform
devices for standalone USB 3.x onboard devices without a peer-hub
(such as USB 3.0 Ethernet or SATA bridges) attached directly to a
secondary root hub. On SuperSpeed-first xHCI controllers where raw
port 1 belongs to the secondary root hub, this would also regress any
such device at reg = <1> that previously matched the unmapped primary
root hub index.

No in-tree boards are broken by this change: all properly described
in-tree USB 3.x onboard devices attached directly to xHCI root hubs are
dual-speed hubs with a "peer-hub" property (whose platform device is
created via the USB 2.0 peer on the primary root hub), and the
USB 3.0-only non-hub devices supported by this driver have no in-tree
device tree users yet. The one outlier, meson-libretech-cottonwood.dtsi,
describes a GL3510 hub with only its USB 3.0 compatible ("usb5e3,626")
and no "peer-hub" property at reg = <1> (a USB 2.0 port on the Amlogic
G12B/SM1 DWC3 controller), so its platform device is still created via
the primary root hub.

Stop skipping secondary root hubs in onboard_dev_create_pdevs() and
update its kernel-doc comment to match. Dual-speed onboard hubs with a
"peer-hub" property are already deduplicated by the
!usb_hcd_is_primary_hcd(hcd) check inside the loop, and each root hub
tracks and destroys its own platform devices in its hub->onboard_devs
list.

This issue was flagged during a review by an AI coding agent
(Antigravity). The code change and commit message were drafted by the
agent and reviewed by me. Runtime-tested on MT8195 Cherry Dojo with a
dual-speed onboard hub (verifying no duplicate platform device is
created on the secondary root hub); the standalone USB 3.x device
(without peer-hub) path is compile-tested only.

Fixes: 8bc063641ceb ("usb: misc: Add onboard_usb_hub driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
 drivers/usb/misc/onboard_usb_dev_pdevs.c | 26 ++++++++----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/misc/onboard_usb_dev_pdevs.c b/drivers/usb/misc/onboard_usb_dev_pdevs.c
index cdb6949e18ec..5cbc8b632097 100644
--- a/drivers/usb/misc/onboard_usb_dev_pdevs.c
+++ b/drivers/usb/misc/onboard_usb_dev_pdevs.c
@@ -48,21 +48,16 @@ static bool of_is_onboard_usb_dev(struct device_node *np)
  *
  * Root hubs don't have dedicated device tree nodes, but use the node of their
  * HCD. The primary and secondary HCD are usually represented by a single DT
- * node. That means the root hubs of the primary and secondary HCD share the
- * same device tree node (the HCD node). As a result this function can be called
- * twice with the same DT node for root hubs. We only want to create a single
- * platform device for each physical onboard device, hence for root hubs the
- * loop is only executed for the root hub of the primary HCD. Since the function
- * scans through all child nodes it still creates pdevs for onboard devices
- * connected to the root hub of the secondary HCD if needed.
+ * node, so their root hubs share the same device tree node (the HCD node).
+ * Because usb_of_get_device_node() maps root hub port numbers to raw port
+ * numbers, each root hub only visits the child nodes connected to its own
+ * ports and creates platform devices for onboard devices attached to them.
  *
- * Further there must be only one platform device for onboard hubs with a peer
- * hub (the hub is a single physical device). To achieve this two measures are
- * taken: pdevs for onboard hubs with a peer are only created when the function
- * is called on behalf of the parent hub that is connected to the primary HCD
- * (directly or through other hubs). For onboard hubs connected to root hubs
- * the function processes the nodes of both peers. A platform device is only
- * created if the peer hub doesn't have one already.
+ * Further, there must be only one platform device for onboard hubs with a peer
+ * hub (the hub is a single physical device). To achieve this, pdevs for onboard
+ * hubs with a peer are only created when the function is called on behalf of a
+ * parent hub that is connected to the primary HCD (directly or through other
+ * hubs), and only if the peer hub doesn't have one already.
  */
 void onboard_dev_create_pdevs(struct usb_device *parent_hub, struct list_head *pdev_list)
 {
@@ -75,9 +70,6 @@ void onboard_dev_create_pdevs(struct usb_device *parent_hub, struct list_head *p
 	if (!parent_hub->dev.of_node)
 		return;
 
-	if (!parent_hub->parent && !usb_hcd_is_primary_hcd(hcd))
-		return;
-
 	for (i = 1; i <= parent_hub->maxchild; i++) {
 		np = usb_of_get_device_node(parent_hub, i);
 		if (!np)
-- 
2.56.1.915.g69d5ec7298-goog


  parent reply	other threads:[~2026-12-04  2:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:52 [PATCH 0/4] usb: of: Fix root-hub raw port lookups and graph handling Chen-Yu Tsai
2026-12-04  2:52 ` [PATCH 1/4] usb: of: Ignore 0-based or unnumbered OF graphs in usb_of_get_connect_type() Chen-Yu Tsai
2026-12-04  2:52 ` [PATCH 2/4] usb: of: Use raw port numbers for root hub OF lookups Chen-Yu Tsai
2026-12-04  3:10   ` sashiko-bot
2026-12-04  2:52 ` Chen-Yu Tsai [this message]
2026-12-04  2:52 ` [PATCH 4/4] usb: of: Check compatible string of device node Chen-Yu Tsai

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=20261204025243.807657-4-wenst@chromium.org \
    --to=wenst@chromium.org \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=mka@chromium.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rafal@milecki.pl \
    --cc=robh@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=swboyd@chromium.org \
    /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