From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88E70CD3436 for ; Tue, 5 May 2026 10:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NDybnB3UNtSjaXyKFcIZ/N44VcjPS1MoxizI85eNGkQ=; b=sW7RGtZi6nB4dELCVeP8XycznD hRmBaaffoxkvMNCjkY58R+g4LorwnFBeNhR3a+Jsn+hlAJ2YHlv8leyeJg/BjHLqTiUeNdGJcqVPW NcqHxfzwbgJn3XFzw+ZXy/0m+zj0D4WR9XZfSsHR47rO0PC1Ie6/9vGvTR8NtJE8zwUBmjJvGzW2T sK3vwos89vTLoBdUjUtFhJ7Sg2gK0yWw5pXuwFG7c+oTkm40ilaBzoY+2wG9mvs7GcwDCZjk7NVfC K6Xl4EJWf+Rz0shpDTt1EmisP1BNCJQxlckoYQQIo8xtBix8RQljIbJziIGwLDSlwYIbG1t1iE54V sBbVNHdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKCgk-0000000FnCv-0uwx; Tue, 05 May 2026 10:07:38 +0000 Received: from mail-swedencentralazlp170130007.outbound.protection.outlook.com ([2a01:111:f403:c202::7] helo=GVXPR05CU001.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wKCfd-0000000Fkdf-3lBO; Tue, 05 May 2026 10:06:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=f5d9SVnTONC0Qk5yDsJZbiXHf2d7mXGDQz2B7iaq5gIN7dUKicPNUuZMfaftrg4tFpDR6fKNnt36HdkyT+ZZhRQgYy/nralJ/k3gEhPR/HsfHrXfeF6RGYvyHzidCcc+bFqu91QMpXIjzaSh17l1j4W5wA8zXfdKoQwdlfj96FCKQXQVs+OeAAkok7P9whFnrcUBRtmgrnBdkGzuSsVQdHPuY60SAyxLd1x2cDNkwFW7cpJXWm5cUN0CHdTA0ktnZvinOQNw/Wyt7KamzaHPVI5sGs9ojykiDCjqRneHP/0ZalVi0t8kdhgF6H7aCGl6UJ9IDiyRlDAqofzmK8P7ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NDybnB3UNtSjaXyKFcIZ/N44VcjPS1MoxizI85eNGkQ=; b=jU69uJWSEuQVt5lqHVb90Wc0GID/41HsAr7JB3IfNV4Sto5cK/xe16SzSGcidm81vHi17+KS32P4lV+r6HHQuAJgR89OpFObjn15JwUoftXAB2HUjLdy6UX1X83xkpdvLmyCLBxkx0Xx1S5txiYvMuSBN53GnaGvVdiVfiHTmQQcCFjRx0nACIraoKgLh+fYZNWYmsgaH+n2zhHRm+kvnpavnsOcP/2tt+KL43v2HfiKw4vYCd+fTTHIU9lO+USQ9KwdhmDtPC4pu/kfN5NyWAC89BUj/4g4UY3qD6vhIV3fVxvZJHiYBEV8ZM9ae0wPaYwKDE4+DhvHlkqyiwUIBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NDybnB3UNtSjaXyKFcIZ/N44VcjPS1MoxizI85eNGkQ=; b=UcyW/2TH7SIJ3eYeGCxzkkM0I7k6lK38WS9M1C40A7v2vigaEoHT+p/iBJ/NgQwnwS218ulwaNlWss11yGcyeEfHEmpKMJWS1OogT6eukS0P/J8Tj3AKjg5WGm7ODMW0sNbOc+szpn1j0RNdAPHwoC2uE1jiyDPHMx3Btitoh+lg7tqDlA+uqAbv0Ljlj30xZ2zcU2PQAPL53sJ9MJzXVtJ7jji4GJEcLUbYuT6hSByXuxBf9azJOo41dl0+uwug9HjCzl7+W7qlOQ2NC3F1oI4Wrx2DtjhiHKIR74lnwTQu4IKr5jzCv2meIqiJLVUaiBgTBa4qvLD2y2Hz/U5lRQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) by DB9PR04MB8363.eurprd04.prod.outlook.com (2603:10a6:10:24b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9846.26; Tue, 5 May 2026 10:06:13 +0000 Received: from AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4]) by AM9PR04MB8585.eurprd04.prod.outlook.com ([fe80::f010:fca8:7ef:62f4%4]) with mapi id 15.20.9870.023; Tue, 5 May 2026 10:06:13 +0000 From: Vladimir Oltean To: linux-phy@lists.infradead.org Cc: Vinod Koul , Neil Armstrong , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-can@vger.kernel.org, linux-gpio@vger.kernel.org, linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-scsi@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org, spacemit@lists.linux.dev, UNGLinuxDriver@microchip.com, Greg Kroah-Hartman , JC Kuo , Johan Hovold , Jonathan Hunter , Mathias Nyman , Thierry Reding Subject: [PATCH v8 phy-next 17/31] usb: gadget: tegra-xudc: avoid direct dereference of phy->dev.of_node Date: Tue, 5 May 2026 13:05:09 +0300 Message-Id: <20260505100523.1922388-18-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260505100523.1922388-1-vladimir.oltean@nxp.com> References: <20260505100523.1922388-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: FR4P281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c9::10) To AM9PR04MB8585.eurprd04.prod.outlook.com (2603:10a6:20b:438::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8585:EE_|DB9PR04MB8363:EE_ X-MS-Office365-Filtering-Correlation-Id: 5e8003b9-860f-4f21-8db8-08deaa8df066 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|19092799006|7416014|366016|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: +43zuyaWtPW7n9G02XNQ8SeWPaM6OkchNGuE3B4VBZ1FxHr/n1wvNmr5aIkd9J5R8gnayR+ZHlk0+DymxVjQ+vKOn3CcgUaWocRq0A/iqqeQ93A3QE7IHTbiYsTwF+gyVrpt/jNH1YvQ9wqsivPXvHr1B0veWT48nuozIEE4CN79iL1n3uvyOWyPn1CYhDXH1UCX0kaI8rneg2WpYQs0HFTTSsQGTex5hQ+6axU8rMSexdw8AkGoSRRn5p23jFjTxQObqoRPnnSYEUXNdm0ugpOgW1Jfm3sQxSOBncHAfjE0qJDAX53S7TmyAKF7ZG028z1MAoAL+5CUNu2C/+H9EaSLfmyQa9CEcv+XrXBblYNbzMcsPC58vav4beXOQhkXqHjbDmzlNft9hjx7QIzXgAuM05X/YXxUuIILaYkEBnkIvSxZWLeQ+MpF2F7SclfSII3s3vFBMCh08BmssicsrTv8Z4+eEvypgvknCMkVrZAmehEtZ9iC7buzuW4vVcaPqPiV3oYmN1/SX7Y0KeEJ5rju0xUgVyTuhLxtGWhI7CDJ6D1/D0VUS2atYCa0MeeoTslhEugNwO+VEaXrxbu+1Xy/yX9DJiL9efnkHilhqMqNTuhbJ6icgpx9WHLyNB4ULxqIypLG0aDOoxc/xCwoGx29HQiy8d5HDeLLj4SjXrTBtmkZKajJ0xnyULo9MyFU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM9PR04MB8585.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(19092799006)(7416014)(366016)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?jVz6d8aTwnL3r+AoxBV3pYRGlJMFQE7CnvIjbAYmO4LHOadyk62C6fCFfcr/?= =?us-ascii?Q?k2V7CAg4Zmr/S1StEUoHf/MAWhj3JQo9OS49s/ovFxnfK+Cu//UAAMYdI3xw?= =?us-ascii?Q?xLRA+GWKoCpyNU+j5SO9KSzS1ee5Txr08gwlTcGmspz/BgFkfIExxsRBujnj?= =?us-ascii?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Jw0Mg3Ysm?= =?us-ascii?Q?BknvRAVxFQ2HVCgBItAIFLdRaavZ3eoSs67CNqKELv388P4B1GN+geHdT187?= =?us-ascii?Q?JQNkAkxGGVTiGexCGOgXDMuqAMFFTh+aX0fGrJYBZMpKgyzcFi65bUOBNut9?= =?us-ascii?Q?6PVOo/4pkeGaXBWi/dz6cY3zaHDphlb3suKo2wxO9jX5K0hahvPudPaulk1g?= =?us-ascii?Q?VtXahv6fWsUz4f3e5f1P6qBmAdEo6R+7KF9OaP2/10iwQcH2UY4RPGcLT3bo?= =?us-ascii?Q?PLIIfYF8zUT27kMOpDQBKeSuWZYoI6+Gt8SDm8XmtcvQ8+yMg5Bvzsw5FQpO?= =?us-ascii?Q?89HtYb6G4jhjR8qFQ1jx+c5WK4dg0eXNPCMeF2HoYpJLXpIoAfVMTd1GzJpP?= =?us-ascii?Q?Jo8Tx3Gb+FHV/ldlv+KNcxIk6bmc3GG4aLaKLXYdiyceA37wbk6rSeYxfhQ8?= =?us-ascii?Q?++8dBX2+EZ8A3m5Pfh1yGRIvlVsOmGfDMnziNB4G4dyLRpRZTzQKQdZwMf78?= =?us-ascii?Q?UeZDyJ9ZO/I3M/ON5lw6XujVoBbbbX+3EjEfvg9F8jpUWs5H8koZ/zE+Om9M?= =?us-ascii?Q?DvKzIRMBwfJ/L+uFWPO2eHL1t/xQpWPCBEW+Yni2ZmQzR6qGFbMWfU6WZAIq?= =?us-ascii?Q?It/Own4EvJm4hx2Mo6bX2SdpxJKcFSlNnM3gLfsMCQGc5qlZAhxHvsByun8r?= =?us-ascii?Q?MyzG+zCgLg=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e8003b9-860f-4f21-8db8-08deaa8df066 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8585.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2026 10:06:13.5888 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Q08+RyOZNT3PkBbB/ySI9fKoKcPt+mIkDhUJ8xAoCnJbmDIw8r7uAZgmXbpkb28giwoK4CB0CrQt+jK/bc2YxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8363 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260505_030629_987342_00956C30 X-CRM114-Status: GOOD ( 20.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In a somewhat similar situation as the Tegra USB host controller driver, the Tegra XUDC driver for USB gadget mode needs to get to a struct usb_phy that sits behind the same OF node as the Generic PHY. It does that directly, which will no longer be possible. The PHY provider is also the xusb padctl driver. The rework here is also to implement a parallel OF node lookup path based on the "phys" phandle and the #phy-cells of the padctl provider. Some further notes: - create a local "usbphy" variable to hold the devm_usb_get_phy_by_node() output. This makes the error checks more obvious (avoids keeping an error-encoded pointer in xudc->usbphy[i] even temporarily). - the "if (IS_ERR(utmi_phy)) .. else if (utmi_phy) .. else if (!utmi_phy)" pattern can be simplified, considering that neither the IS_ERR() nor the NULL case continue execution in the current block. Therefore, we can move the case where the "utmi_phy" is a valid pointer outside the "if" checks, and this reduces the code indentation level. Signed-off-by: Vladimir Oltean --- Cc: Greg Kroah-Hartman Cc: JC Kuo Cc: Johan Hovold Cc: Jonathan Hunter Cc: Mathias Nyman Cc: Thierry Reding v7->v8: - remove duplicated variable "err" which shadows existing one - stop execution on of_property_match_string() and of_parse_phandle_with_args() errors, instead of silently continuing v5->v7: none v4->v5: patch is new --- drivers/usb/gadget/udc/tegra-xudc.c | 43 +++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index e9d33be02866..f93e0a5651ab 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -3494,6 +3494,7 @@ static void tegra_xudc_device_params_init(struct tegra_xudc *xudc) static int tegra_xudc_phy_get(struct tegra_xudc *xudc) { + struct device_node *np = dev_of_node(xudc->dev); int err = 0, usb3_companion_port; unsigned int i, j; @@ -3515,7 +3516,10 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) xudc->vbus_nb.notifier_call = tegra_xudc_vbus_notify; for (i = 0; i < xudc->soc->num_phys; i++) { + struct of_phandle_args args; char phy_name[] = "usb.-."; + struct usb_phy *usbphy; + int index; /* Get USB2 phy */ snprintf(phy_name, sizeof(phy_name), "usb2-%d", i); @@ -3525,22 +3529,39 @@ static int tegra_xudc_phy_get(struct tegra_xudc *xudc) dev_err_probe(xudc->dev, err, "failed to get PHY for phy-name usb2-%d\n", i); goto clean_up; - } else if (xudc->utmi_phy[i]) { - /* Get usb-phy, if utmi phy is available */ - xudc->usbphy[i] = devm_usb_get_phy_by_node(xudc->dev, - xudc->utmi_phy[i]->dev.of_node, - NULL); - if (IS_ERR(xudc->usbphy[i])) { - err = PTR_ERR(xudc->usbphy[i]); - dev_err_probe(xudc->dev, err, - "failed to get usbphy-%d\n", i); - goto clean_up; - } } else if (!xudc->utmi_phy[i]) { /* if utmi phy is not available, ignore USB3 phy get */ continue; } + index = of_property_match_string(np, "phy-names", phy_name); + if (index < 0) { + dev_err(xudc->dev, + "no \"phy-names\" entry for \"%s\": %pe\n", + phy_name, ERR_PTR(index)); + goto clean_up; + } + + err = of_parse_phandle_with_args(np, "phys", "#phy-cells", + index, &args); + if (err) { + dev_err(xudc->dev, + "failed to follow \"%s\" reference\n: %pe\n", + phy_name, ERR_PTR(err)); + goto clean_up; + } + + /* Get usb-phy, if utmi phy is available */ + usbphy = devm_usb_get_phy_by_node(xudc->dev, args.np, NULL); + of_node_put(args.np); + if (IS_ERR(usbphy)) { + err = PTR_ERR(usbphy); + dev_err_probe(xudc->dev, err, + "failed to get usbphy-%d\n", i); + goto clean_up; + } + xudc->usbphy[i] = usbphy; + /* Get USB3 phy */ usb3_companion_port = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); if (usb3_companion_port < 0) -- 2.34.1