From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796352799; b=u+5nMmz6KvdnLKrmSqJaz2n2DqJmLalpUgul7+r+ir24Grq7NB2UAlojjD0q+fMOv/Vy QT/Qj8nfN50quL/ZPxO3Ubofoxf/lLh+iYbRIThd747Jb7djm/gLGdrYcEAdo4Jk9NKiC tzoDxhs02P0GGSUWKoKTyYSOIherX8fxZSIPUPeOf7QhP+zgazVGpxyBtpitBJiprS3S7 zr41kswLW1CQtVQI7FLIqIUf8QZG94I4PGcY1uj2jw1Q/yf4Uv7PON92rA/bWHk0L1gLw ccxyFdfekUuuz6hCANh593/76wBaMSr2Zbz2BnD4NRvuR+Pa9FqmzWKwEJgL7aGtpUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796352799; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=aXOxEtEgmOMjiQFkRBFbiWf6gGBzYO1Y+o3o35tYRfU=; b=T5VgrULJH4I3s3wjgW5+wljAzW5AJYKcgQHdBjt8StICszdWcDmP5rU/oGfmB8rj94ev jH/WpHtuQ+m1raG6Ibj32Wg28Jh+6JaHnckGeHhZC2a6cnjaWtb8vRt2r5m+OPAD4FYPl A3tOaSYbvQ4rajra9weC0dpUXli80fNmtrN8IUWJhEkD8n4vRM5EDrwo1spIV8s+a6PH0 AM0lacHxBwNfojN6sSL7kSAszURQhcKInM6I0I+Lw9/ggmzmyd7+RKKn9isabgbacOWsC 88pEPpH13nJzb8GPM/sbJ9TmcdM0zX0ugN0RudYkqRu5vtXtrqFoELzdLgtzGtiYXMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=JhMWqjbU; arc=none smtp.remote-ip=209.85.210.179 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6F87606A32D for ; Fri, 4 Dec 2026 02:53:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A6F87606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=JhMWqjbU Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-8a594d313a3so113268b3a.1 for ; Thu, 03 Dec 2026 18:53:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796352797; x=1796957597; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aXOxEtEgmOMjiQFkRBFbiWf6gGBzYO1Y+o3o35tYRfU=; b=JhMWqjbUfSKPfxY6RENwpbF9FxJEDh6wvtxJ7FolLuSuJm+S4und6bZY3Ohp8GiiAa LINOUxRnwMgLkIQzpE/5BXh1h+cfrZZTCqr/cbBCoCnNiA8M8QZSHGNF2w2IaEAVDz5I YIwKOZyIutpvbui9ak4RTvbAKjAzT00xOjMN0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796352797; x=1796957597; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=aXOxEtEgmOMjiQFkRBFbiWf6gGBzYO1Y+o3o35tYRfU=; b=h8xhy8GmOq8Oy/YBavzXHcwiDPLwSEj6HGAEa1LIZ2tsx0VXYEIFFlyf6rvxBY492f 8fqgjzvwhdaukM+j8pgtLaiT5tcbJ++yGSM/UxvZmjPaCG4XFWOq1Q4NLqw5riK2tmRB Cl7pdlgTv40bt7UdoRmkvJndpVr0w7BzvSytmTwgtuZsCZ4ZuUCxhYkgl9Ztp4hJoByU DxdVmQhJRcOgbpcYlaa0QDWuI6pmF44HTGQNeNQOy9iSeuuu8NO0iXXUMlQXdMw7Naoj 0G0JXKbiDzq/+dda583rhFKIh9vw80/GSea7B/9/a3LzrKzzOD/GogxM6JrSm5C+vwll 5MBQ== X-Forwarded-Encrypted: i=1; AL+hErGBLlA0XC3B5+Rp1DGGvBeDAp6ieEe6ISCQXBmUQCtx48ZENTca8h9QuH+QnnaACBU1HLgL87h2T6mr@vger.kernel.org X-Gm-Message-State: APuU4Z/Sll6wDyzKz5oORCjCjzBtN9pTcXyw4Zn7/7NeEMkzp0lsLUfH xRNBivGwNWW0szl078VrWoqDN6VOO5Bjney9nL4QhScDp2HqeponYekjd3OlPm7Aig== X-Gm-Gg: AZFdTZc7bc1NjqXLggPOZz7CnO29PPOBDuvM/JQFKblz1Myvc+QObLr67TmRNQaGOYr puuKiY6yLi61TyuZAUb6pTNk6Hnr0wbc0iDDaVF45F/HOLjpaNmGyVRBKXg/hhUrsSMBUnxfKBG EJzikkXLW2Bq+ZdXP+D99U/LVasVloiGBwq0QynDw83BTzypTe9DU9ZOoe8hyCObOAUyVuubKrJ 46rbGHQo65S24lqu/Ecdo+zjJ5OQT2st/9DIEhJlcB5FKXNiYHRZc9DC2g3Pw5jhStLq8qxdorW dKGdBk05zeUChU9fSJv4dFvwAkZluYHHzKxBPj9Jr4q+mneWCc0VfE1cgHrj/zBL1EfSjZo2MFA Nu7rothPbjGpwvJdQeBUo/Uop/cmgnRDvVPbfl00Ssxq06u6/aTjBr8uKMhP88Qui2GfqWH+gt3 IpQtfRYoxkGSq+OS6TANodTTF4hQ0+Y/fXSdO4HzZHo4Y+ktkN5heuMpRPQXfoP9Px5/T6HZMKn sUPLqo7ffyNpikXJvf6NtzpCP6SbAeds68bnC7be/8eOPWJHwwSMzjYmdjhjSPgBpLxUOo40YNx +rFCtUkZvCkgNT1GDQpTVBKEeP68zf5a610YIw/4VYBLbnzUOpA5uK5Xmrs= X-Received: by 2002:a17:90b:4a49:b0:3ab:1e1c:837f with SMTP id 98e67ed59e1d1-3b5e06859eamr522596a91.47.1796352796967; Thu, 03 Dec 2026 18:53:16 -0800 (PST) Received: from localhost ([2a00:79e0:203d:7:baaf:2341:c22:c17a]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3b5c7d7a6b5sm6777669a91.14.2026.12.03.18.53.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 18:53:16 -0800 (PST) From: Chen-Yu Tsai To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Chen-Yu Tsai , Alan Stern , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, Matthias Kaehlcke , Stephen Boyd , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Johan Hovold , Mathias Nyman , Neil Armstrong , Bjorn Andersson , stable@vger.kernel.org Subject: [PATCH 1/4] usb: of: Ignore 0-based or unnumbered OF graphs in usb_of_get_connect_type() Date: Fri, 4 Dec 2026 10:52:39 +0800 Message-ID: <20261204025243.807657-2-wenst@chromium.org> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261204025243.807657-1-wenst@chromium.org> References: <20261204025243.807657-1-wenst@chromium.org> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit USB downstream port numbering in both the USB specifications and the USB device tree bindings (usb-device.yaml, usb-hub.yaml) starts at 1; valid USB port graphs never define port@0 or an unnumbered "port" node. usb-hcd.yaml will also gain a "ports" child node following this 1-based numbering for attaching USB connectors to downstream ports via OF graphs. However, existing dual-role USB controller bindings (as well as the legacy unnumbered "port" in mediatek,mtk-xhci.yaml) use OF graph connections that do not follow 1-based USB port numbering: - An unnumbered "port" child node for usb-role-switch (e.g. dwc2, chipidea, cdns3, and single-port snps,dwc3) or a Type-C SuperSpeed endpoint (mediatek,mtk-xhci). - 0-based port@0 (HS) and port@1 (SS) numbering (existing snps,dwc3 bindings). Currently usb_of_get_connect_type() checks of_graph_is_present() without verifying that the graph uses 1-based numbering. As a result: - Controllers with an unnumbered "port" node never match a 1-based port number and return USB_PORT_NOT_USED, causing external hot-plug devices to be marked DEVICE_FIXED. - Controllers with 0-based port@0/port@1 nodes match the wrong port on port 1, and once root-hub raw port lookup is used, SuperSpeed port 2 finds no port@2 and returns USB_PORT_NOT_USED (DEVICE_FIXED). Since port@0 indicates a 0-based scheme where port@1 is also shifted, ignore the entire OF graph whenever port 0 is present (via of_graph_get_port_by_id(np, 0), which treats a missing "reg" property on an unnumbered "port" node as 0 as well). Such controllers fall back to USB_PORT_CONNECT_TYPE_UNKNOWN unless hard-wired child USB device nodes (which already use 1-based port numbers, e.g. onboard hubs under snps,dwc3) are present. Note two behavioral details on existing 0-based snps,dwc3 device trees: - On controllers with port@0/port@1 nodes (around 174 in-tree nodes, such as Qualcomm sc8280xp and Apple t600x boards), the sysfs "removable" attribute changes from "removable" (previously matched by accident via 0-based port@1 on logical port 1) to "unknown". - A 0-based snps,dwc3 node defining only port@1 without port@0 (currently only rk3576-lckfb-tspi-3m.dts, which has hub@1 plus ports/port@1 for its SuperSpeed Type-A port) cannot be distinguished from a 1-based graph here; once raw-port graph lookup is used, its SuperSpeed port's connect_type changes from "hardwired" to "not used" (while "removable" remains "fixed"). 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. The port0 != NULL ignore path is compile-tested only (not exercised on MT8195 Cherry Dojo). Fixes: 82e82130a78b ("usb: core: Set connect_type of ports based on DT node") Cc: Signed-off-by: Chen-Yu Tsai --- drivers/usb/core/of.c | 49 ++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c index a6ee20d8774e..a040fae5710b 100644 --- a/drivers/usb/core/of.c +++ b/drivers/usb/core/of.c @@ -76,13 +76,8 @@ bool usb_of_has_combined_node(struct usb_device *udev) } EXPORT_SYMBOL_GPL(usb_of_has_combined_node); -static bool usb_of_has_devices_or_graph(const struct usb_device *hub) +static bool usb_of_has_devices(const struct device_node *np) { - const struct device_node *np = hub->dev.of_node; - - if (of_graph_is_present(np)) - return true; - for_each_child_of_node_scoped(np, child) if (of_property_present(child, "reg")) return true; @@ -90,38 +85,62 @@ static bool usb_of_has_devices_or_graph(const struct usb_device *hub) return false; } +/* + * USB downstream port numbering starts at 1. An OF graph containing port@0 + * or an unnumbered "port" node (such as legacy usb-role-switch or 0-based + * snps,dwc3 bindings) does not follow the USB port numbering scheme. + */ +static bool usb_of_has_graph(struct device_node *np) +{ + struct device_node *port0; + + if (!of_graph_is_present(np)) + return false; + + port0 = of_graph_get_port_by_id(np, 0); + if (port0) { + of_node_put(port0); + return false; + } + + return true; +} + /** * usb_of_get_connect_type() - get a USB hub's port connect_type * @hub: hub to which port is for @port1 * @port1: one-based index of port * * Get the connect_type of @port1 based on the device node for @hub. If the - * port is described in the OF graph, the connect_type is "hotplug". If the - * @hub has a child device has with a 'reg' property equal to @port1 the - * connect_type is "hard-wired". If there isn't an OF graph or child node at - * all then the connect_type is "unknown". Otherwise, the port is considered - * "unused" because it isn't described at all. + * port is described in a valid 1-based OF graph, the connect_type is + * "hotplug". OF graphs containing port@0 or an unnumbered "port" node are + * ignored. If the @hub has a child device with a 'reg' property equal to + * @port1 the connect_type is "hard-wired". If there isn't a valid 1-based OF + * graph or any child node with a 'reg' property then the connect_type is + * "unknown". Otherwise, the port is considered "unused" because it isn't + * described at all. * * Return: A connect_type for @port1 based on the device node for @hub. */ enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub, int port1) { - struct device_node *np, *child, *ep, *remote_np; + struct device_node *np = hub->dev.of_node; + struct device_node *child, *ep, *remote_np; enum usb_port_connect_type connect_type; + bool has_graph = usb_of_has_graph(np); /* Only set connect_type if binding has ports/hardwired devices. */ - if (!usb_of_has_devices_or_graph(hub)) + if (!has_graph && !usb_of_has_devices(np)) return USB_PORT_CONNECT_TYPE_UNKNOWN; /* Assume port is unused if there's a graph or a child node. */ connect_type = USB_PORT_NOT_USED; - np = hub->dev.of_node; /* * Hotplug ports are connected to an available remote node, e.g. * usb-a-connector compatible node, in the OF graph. */ - if (of_graph_is_present(np)) { + if (has_graph) { ep = of_graph_get_endpoint_by_regs(np, port1, -1); if (ep) { remote_np = of_graph_get_remote_port_parent(ep); -- 2.56.1.915.g69d5ec7298-goog