From patchwork Fri Dec 13 12:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13906966 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 3D0F9E7717F for ; Fri, 13 Dec 2024 12:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Zhy/YAxcPfKmf2wdsGIr7ScK53FdxfPePDSpAndG8JY=; b=Uw1bRDWfRPJek9 dwZ1I9V9ipMDRgQgtqkXO3alKNBz420+cueIUL8oqeQudCiGauSAyx+IJxVIwfzxZ6ga/C7VCNIFg KRfCjX6qHaS31bwGcHgsc3jhZprS4af+rcRT9PP8/sm0XxgKCln1B7NbUIhctWT4j3muKzfMqBiU2 PbiRG7JGLhkJQeDwlQqpTlHG6lqseYKzwIHS5jrRptko1gF8Hl9g0StAdbJIKxyrPEmr5MbgVVWA8 E95/GpAk/OCqqlueM7Pq88RQmggExswpZtKlzs0RLxGFVjE1OrpvUtWHE5sy0W5HAxKv82wgWq2Du jpSfEI1YaaILWXVPPv7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vG-00000003jeY-02dJ; Fri, 13 Dec 2024 12:37:34 +0000 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vD-00000003jcq-2JC0 for linux-phy@lists.infradead.org; Fri, 13 Dec 2024 12:37:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734093441; bh=eoBflErfJ5YHnH9CNE+FKU4F+Kpr2DDHXom6su6dnH0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=fCcdkbyJSEtCGwzS72wGRUBVZHDv9Og+2KBDCZ1BIh40i5JINYTGuRivbJ06ZGhzm ZN4S5QkfGcca85vpkr5ix6SMgEFfCZbgqC+RE1V/HRR566EdbHYNZL8W7TdtfYR+Mg Xq6vfkQkUBWwZN8xSdKIZ0LdZvbfm8jL76LCC2K2nBnbjHao6M22l94ozhvL1kcTML T56jv3JV9iFl1jvpi+mI7gHB8huwZXa9FNHiDeaQ8CXyfqruRvdzwRolgXNrqyoYEb xPIKsThxn0SzZM4097WG6Ss+dXtpJ+m11Un/babxcE61QFrlOkkBTnA9kDFCh/FJnl B3TW3XjY6Eszw== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 523552793D57; Fri, 13 Dec 2024 12:37:11 +0000 (UTC) From: Zijun Hu Date: Fri, 13 Dec 2024 20:36:41 +0800 Subject: [PATCH v6 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy MIME-Version: 1.0 Message-Id: <20241213-phy_core_fix-v6-1-40ae28f5015a@quicinc.com> References: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> In-Reply-To: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Johan Hovold X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: zx_KhUXQuellMpf8dLz_2dTS_YfoqjQg X-Proofpoint-GUID: zx_KhUXQuellMpf8dLz_2dTS_YfoqjQg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-13_05,2024-12-12_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412130089 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241213_043731_615109_59F297B0 X-CRM114-Status: GOOD ( 13.26 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu For devm_phy_put(), its comment says it needs to invoke phy_put() to release the phy, but it will not actually invoke the function since devres_destroy() does not call devm_phy_release(), and the missing phy_put() call will cause: - The phy fails to be released. - devm_phy_put() can not fully undo what API devm_phy_get() does. - Leak refcount of both the module and device for below typical usage: devm_phy_get(); // or its variant ... err = do_something(); if (err) goto err_out; ... err_out: devm_phy_put(); // leak refcount here The file(s) affected by this issue are shown below since they have such typical usage. drivers/pci/controller/cadence/pcie-cadence.c drivers/net/ethernet/ti/am65-cpsw-nuss.c Fix by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Cc: Lorenzo Pieralisi Cc: Krzysztof WilczyƄski Cc: Bjorn Helgaas Cc: David S. Miller Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu --- drivers/phy/phy-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index f053b525ccffab1629f5e09581a6ebcc35e47f79..f190d7126613ad253b4820b9e4167dda8623439d 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -737,7 +737,7 @@ void devm_phy_put(struct device *dev, struct phy *phy) if (!phy) return; - r = devres_destroy(dev, devm_phy_release, devm_phy_match, phy); + r = devres_release(dev, devm_phy_release, devm_phy_match, phy); dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); } EXPORT_SYMBOL_GPL(devm_phy_put); From patchwork Fri Dec 13 12:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13906965 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 F2F72E77180 for ; Fri, 13 Dec 2024 12:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xa/cBryAx4y4Kb7kD102cm4OtD1+8MtviuQH24JU39M=; b=vjpDiguO4nqK1y MD4yecYDUDoMLfvwkasfoCw+TGYBUQfdD7XFAGrQ9nLdy44iq3zk3+F/KLG9WHr3S2WmUeOw9InZ0 wkT/2E3/cvbVhlpKuL4726H5Bz+L5uO6Zi0r8ilV9zkjJoHiucot2rmzMa2Dfwd9pXlgHo2XnK/52 0cilhDLUYjjORl/S70+h40omoWY6S4vl6xe3rx1ycmVu3Mc57xq1mhmgat+Qk2KKdDHsMGcfXk2F9 MTdgEnQWdhQjutGZcbtYqcmWFW/2maoD0hrZy5JMuifXRMmvhs6LOV2Q0Us6D56SGyJGWQiAEEOql Rz9Fl8G0Wwaknhbvu4xA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vF-00000003jeF-39Mr; Fri, 13 Dec 2024 12:37:33 +0000 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vD-00000003jcO-1Hnn for linux-phy@lists.infradead.org; Fri, 13 Dec 2024 12:37:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734093450; bh=KAEa84k4ae1AAp04syMst+ARnTqenvGiw7Oz9H59tBM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=mNEvKuCb1lQjOrLHo4R10tK+X/Bvk8loRodTLH4mazxIenpdxQi04qSd8hkUJLEVa 5KBBTZjpEPdk6xaUKC1uUx9eqyhrVgHeMAuTy23XI8scdRObpivBgxkVWGPuCvkF2L qR4PKSf7MTeXCtqXRJB23RHCR5iVESNfNTac56tJidYAo9gbgA7JWClrpMSaJUoeag RZ5BDCmYFz0S0bkvNOa66wj3Sb/P0qJcO3A7AmAinU9SIIqpBkMI5YGLzw8/RNnX1e +njW2ftb0EkdNDfAZL7TPBsxI8Zmcb3ooFqgJdTurrMBzKxpbajZgZmuqx3Fqq/pMw 6r2O3B0xiZxgQ== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id DB3FF2793FB6; Fri, 13 Dec 2024 12:37:21 +0000 (UTC) From: Zijun Hu Date: Fri, 13 Dec 2024 20:36:42 +0800 Subject: [PATCH v6 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider MIME-Version: 1.0 Message-Id: <20241213-phy_core_fix-v6-2-40ae28f5015a@quicinc.com> References: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> In-Reply-To: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Johan Hovold X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: v_a_AiZBMIwjWVGHSWCDMAyn0MPuwZIh X-Proofpoint-GUID: v_a_AiZBMIwjWVGHSWCDMAyn0MPuwZIh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-13_05,2024-12-12_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412130089 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241213_043731_367261_AE4F09CD X-CRM114-Status: GOOD ( 13.17 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu For devm_of_phy_provider_unregister(), its comment says it needs to invoke of_phy_provider_unregister() to unregister the phy provider, but it will not actually invoke the function since devres_destroy() does not call devm_phy_provider_release(), and the missing of_phy_provider_unregister() call will cause: - The phy provider fails to be unregistered. - Leak both memory and the OF node refcount. Fortunately, the faulty API has not been used by current kernel tree. Fix by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu --- Why to fix the API here instead of directly deleting it? 1) it is simpler, just one line change. 2) it may be used in future. 3) ensure this restored API right if need to restore it in future after deleting. Anyone may remove such APIs separately later if he/she cares. --- drivers/phy/phy-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index f190d7126613ad253b4820b9e4167dda8623439d..de07e1616b34d12056024558124f3ea2469c0323 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1259,12 +1259,12 @@ EXPORT_SYMBOL_GPL(of_phy_provider_unregister); * of_phy_provider_unregister to unregister the phy provider. */ void devm_of_phy_provider_unregister(struct device *dev, - struct phy_provider *phy_provider) + struct phy_provider *phy_provider) { int r; - r = devres_destroy(dev, devm_phy_provider_release, devm_phy_match, - phy_provider); + r = devres_release(dev, devm_phy_provider_release, devm_phy_match, + phy_provider); dev_WARN_ONCE(dev, r, "couldn't find PHY provider device resource\n"); } EXPORT_SYMBOL_GPL(devm_of_phy_provider_unregister); From patchwork Fri Dec 13 12:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13906967 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 7EA25E7717D for ; Fri, 13 Dec 2024 12:37:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uukcSZGmOH4gz99LsBkg/fTGRK/9F1HqWvkTVKl8xsQ=; b=jszlOtzjwjVmZh v/6fVV4uCRe4nD3CThN3aBFi0PV9aL6G5YlyClSWYvGmugGJ+6Y7GBLKkVKJMFlvwii113dDao6Vz uwFmWL3eis+ItN/UuH/T/jHs7s+uWcITGIPfg0dzAfaZ1YLSPaZ3nX08gs2qJn9oxyo2Lfe661BXM SrLU4CRuzsG1K3qjnBhSESjnO6VRivysUqkaF2HPImcpBoGjesT/iGCrD6bAuitqxO7fRRZhYv4Ip tjINOn1uaPpZNXK43z0nhKCkwqwlJcse6IE9jTr7WtOXM8JTkXzSQ5syAFaNJ8yaU0ie1gCKd1D/D gfeWI9Ofj1LR/V4lHMSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vP-00000003jhG-1A7x; Fri, 13 Dec 2024 12:37:43 +0000 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vN-00000003jgY-0XGQ for linux-phy@lists.infradead.org; Fri, 13 Dec 2024 12:37:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734093459; bh=FvdkTxRCCic+u0D/ycct2THNC9tLn/b6kR+RvY6/y70=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=Kguba0Y1C6F46s7WdKWywICv38W8N8PtDGmQtRxPtc5+qWaQjRC2O0rtt1WO3dG79 C1K2p5t/MGXU7iDvNY2iNyZ6opvZ6M3+zKusBnKk9rS0dTyf4CpaBsdh2Te+om+rIB KqNrY2o3/zpgfCY+oyiczelwN65iNXhKcqzgTcNepmBnItWMK4oSeo7PZcFI5fKQv6 f0il8yCzLZZYEF1w9XepuZi+KgOgXFMc7vOcXoKla6pBK8SWJeISSvFQcgtD8prX72 Ibacxu5uJxshzMK/lcLALsPw/jN2jyfejSFlikCiElATaRzuAbB5ClCsjZjw8Uri/M igqXxMR3fttww== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 3E0392793CF8; Fri, 13 Dec 2024 12:37:30 +0000 (UTC) From: Zijun Hu Date: Fri, 13 Dec 2024 20:36:43 +0800 Subject: [PATCH v6 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy MIME-Version: 1.0 Message-Id: <20241213-phy_core_fix-v6-3-40ae28f5015a@quicinc.com> References: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> In-Reply-To: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Johan Hovold X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: 3rcy8yTyNCAggnrEPM8caX2FB31AkD2D X-Proofpoint-GUID: 3rcy8yTyNCAggnrEPM8caX2FB31AkD2D X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-13_05,2024-12-12_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412130089 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241213_043741_179834_0785051C X-CRM114-Status: GOOD ( 14.02 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu For devm_phy_destroy(), its comment says it needs to invoke phy_destroy() to destroy the phy, but it will not actually invoke the function since devres_destroy() does not call devm_phy_consume(), and the missing phy_destroy() call will cause that the phy fails to be destroyed. Fortunately, the faulty API has not been used by current kernel tree. Fix by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu --- Why to fix the API here instead of directly deleting it? 1) it is simpler, just one line change. 2) it may be used in future. 3) ensure this restored API right if need to restore it in future after deleting. Anyone may remove such APIs separately later if he/she cares. --- drivers/phy/phy-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index de07e1616b34d12056024558124f3ea2469c0323..52ca590a58b9c303b21bf892565612a7ab92c095 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1121,7 +1121,7 @@ void devm_phy_destroy(struct device *dev, struct phy *phy) { int r; - r = devres_destroy(dev, devm_phy_consume, devm_phy_match, phy); + r = devres_release(dev, devm_phy_consume, devm_phy_match, phy); dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); } EXPORT_SYMBOL_GPL(devm_phy_destroy); From patchwork Fri Dec 13 12:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13906968 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 C2666E7717F for ; Fri, 13 Dec 2024 12:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aNcitrMV0cSQVJnE0EhQGeea3nliuKxO5hS47p6CB14=; b=Jzc+nllV7IpARL daophm+iyRA/u4QGRr0lZS1jtl/v0D8c8kUaaqcqFhiZAmLK4b+y1a3uS8qfa4eeJ+ddJOA6AEDZF GaPXQpitQ5Ym6l+PTuSoZYtObjwVJdx4NJDCglWvSuZ0wWSf7kI//6HGTXmsu/U2tEq6aBIt2JZKW /y2bEq/4p2A6JC8vcvqqZzr88dOqrupxtAL0dBnecPM1/cnnuXS4ewGSEuhF7GNCA5GIxEXOoEy6z +fVEAOpwEULKUJVJ5W7zIOGgUBCzOGrXimAjUW543zGdtjPpIaEJrwN5WBRMSoa/UDeIyEgUsnK3C u9BpAsEF2Sb0OwKpc2Xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vX-00000003jj0-2JZd; Fri, 13 Dec 2024 12:37:51 +0000 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vU-00000003ji0-2g6o for linux-phy@lists.infradead.org; Fri, 13 Dec 2024 12:37:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734093468; bh=wyxreJ8ZOeQ11pLqAphuyUs2BXs2kHLB0q1+hs7nobY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=JdwMQie476kqVi74Ijs0Ss090VYMx6tic88LobqilcAt3RITK8waA2pkp5mEP5S3A YFtfXESe51cCYKEoM2YBQZHlq62VKEAaIQt8a56F5cISDJ4+AhH4x0Qlm1PILREY3w 6/nrS3GD7btp/WZhkuPTfUOl6gPyfuSmDgcZyKalGk2GvvwvZOseDHAiNkAZmdEUWo paJjCHcyGZix9I6MmoQgLd+xP3OWcA3HS+adQq3BMBwkCYg6DftlebYynQfn/7pV1w sVKV9q8WF9LdY4e2++BDeR3uJofpG5KU/1JlKCzSaIMVh6o0xnaHHkbmWd6JO+3G2B cONLFD2EqodtA== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 2C22A2793DC6; Fri, 13 Dec 2024 12:37:39 +0000 (UTC) From: Zijun Hu Date: Fri, 13 Dec 2024 20:36:44 +0800 Subject: [PATCH v6 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() MIME-Version: 1.0 Message-Id: <20241213-phy_core_fix-v6-4-40ae28f5015a@quicinc.com> References: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> In-Reply-To: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Johan Hovold X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: JD-pS1O41hgJIkTIlLV-MtOWkkjA_jIb X-Proofpoint-GUID: JD-pS1O41hgJIkTIlLV-MtOWkkjA_jIb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-13_05,2024-12-12_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412130089 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241213_043748_689197_89697245 X-CRM114-Status: GOOD ( 11.09 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu _of_phy_get() will directly return when suffers of_device_is_compatible() error, but it forgets to decrease refcount of OF node @args.np before error return, the refcount was increased by previous of_parse_phandle_with_args() so causes the OF node's refcount leakage. Fix by decreasing the refcount via of_node_put() before the error return. Fixes: b7563e2796f8 ("phy: work around 'phys' references to usb-nop-xceiv devices") Cc: stable@vger.kernel.org Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu --- drivers/phy/phy-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 52ca590a58b9c303b21bf892565612a7ab92c095..b88fbda6c046174b7abd0a0435ec54763e9f42bc 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -629,8 +629,10 @@ static struct phy *_of_phy_get(struct device_node *np, int index) return ERR_PTR(-ENODEV); /* This phy type handled by the usb-phy subsystem for now */ - if (of_device_is_compatible(args.np, "usb-nop-xceiv")) - return ERR_PTR(-ENODEV); + if (of_device_is_compatible(args.np, "usb-nop-xceiv")) { + phy = ERR_PTR(-ENODEV); + goto out_put_node; + } mutex_lock(&phy_provider_mutex); phy_provider = of_phy_provider_lookup(args.np); @@ -652,6 +654,7 @@ static struct phy *_of_phy_get(struct device_node *np, int index) out_unlock: mutex_unlock(&phy_provider_mutex); +out_put_node: of_node_put(args.np); return phy; From patchwork Fri Dec 13 12:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13906969 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 547BCE7717F for ; Fri, 13 Dec 2024 12:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=clPNK0e3dKFU25t2jqzgjOK6pLlDU7EHvcwTK9zV0WM=; b=T/E99mUBXDfsDF Ua3xR628l8OlQY5rUifGRvUWQeDqBQ/rvn1/ou0SPbAEUuftHHWxfKlwChiIIkX1ucxDl/pbNgvaf XGJQA3zN8f1wgdKnZV4cx6jHwMpoVwM4Vem9IvA4lsBehsDxHqRG4KY5LFcP5ut5hBjz1tUN5HGx8 93yX575XzUIRKafLUWNyE9zro3F+RKrbnkEaN5LQXnJFIsjwQBQ5crBvtMysDnng+ZVu6KCA44AYG D3p1lmYksx8jAv06940gYn9KqTlBtmSpf2GVCjr7mldJzLdmEPiSiBbvjpEKceknJYlY7M4+0NWam 6D8bNTIa0zZ8chKLS4bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vh-00000003jm2-0FlO; Fri, 13 Dec 2024 12:38:01 +0000 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tM4ve-00000003jl9-3j6b for linux-phy@lists.infradead.org; Fri, 13 Dec 2024 12:38:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734093477; bh=vHF8DCKQH6/n7GK9DPqqodw58R039f9qaEE0YJ47Wlw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=xx+S+tjJSX/ndp7wqRkmyXmIOfMsUFc6Fnl2LDiY59ajeP8ZyW27AgSD9yvTfWSyy MldnwU25gn/W1ldQHdPsRDjV2fmqHQqKEfRkmgWcrJ48gFz8yqOZVNYG2WPCSIoyC7 igZMOWUQJ6slaTvSbGN7zTeHTSbv7Oe7nVL6pJpcKqpXT7U1mPAfzMGuzda9oE3pza +yp9t4EtLPIvgUDOeTnwYzPkyX01r8okP/t1Iz61Oj5u/FxU74uyAR/quesUSIiFrs 6dP6jz/Jd2V3pnOiBFkI9FG1ZW1CkZsIIkZCIBTGAlKCqcmE01TftTxxF+KMgX5/e6 TUbBV2DTbtR7w== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id 10F2A2793FE0; Fri, 13 Dec 2024 12:37:48 +0000 (UTC) From: Zijun Hu Date: Fri, 13 Dec 2024 20:36:45 +0800 Subject: [PATCH v6 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() MIME-Version: 1.0 Message-Id: <20241213-phy_core_fix-v6-5-40ae28f5015a@quicinc.com> References: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> In-Reply-To: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Johan Hovold X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: kkC14_aTfSvXZL-K-AObGaPtXdPiUX68 X-Proofpoint-GUID: kkC14_aTfSvXZL-K-AObGaPtXdPiUX68 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-13_05,2024-12-12_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412130089 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241213_043758_949700_1B946699 X-CRM114-Status: GOOD ( 10.88 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu For macro for_each_child_of_node(parent, child), refcount of @child has been increased before entering its loop body, so normally needs to call of_node_put(@child) before returning from the loop body to avoid refcount leakage. of_phy_provider_lookup() has such usage but does not call of_node_put() before returning, so cause leakage of the OF node refcount. Fix by simply calling of_node_put() before returning from the loop body. The APIs affected by this issue are shown below since they indirectly invoke problematic of_phy_provider_lookup(). phy_get() of_phy_get() devm_phy_get() devm_of_phy_get() devm_of_phy_get_by_index() Fixes: 2a4c37016ca9 ("phy: core: Fix of_phy_provider_lookup to return PHY provider for sub node") Cc: stable@vger.kernel.org Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu --- The following kernel mainline commit fixes a similar issue: Commit: b337cc3ce475 ("backlight: lm3509_bl: Fix early returns in for_each_child_of_node()") --- drivers/phy/phy-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index b88fbda6c046174b7abd0a0435ec54763e9f42bc..413f76e2d1744dd8ffb63a6c3a093f5c6cbead7b 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -145,8 +145,10 @@ static struct phy_provider *of_phy_provider_lookup(struct device_node *node) return phy_provider; for_each_child_of_node(phy_provider->children, child) - if (child == node) + if (child == node) { + of_node_put(child); return phy_provider; + } } return ERR_PTR(-EPROBE_DEFER); From patchwork Fri Dec 13 12:36:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13906970 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 9141DE7717D for ; Fri, 13 Dec 2024 12:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lRjDO96iq/sXSdB9fbX7SbWNarBaR1BMXggkzqgtsGE=; b=lATDxWcROuy+oa Bs/Sy7d3yE7AT20v2Z2pm4lkxH5IXVIYSd1/Wn5RtUkWa99pf0lJab12lyUrZHPZTWjG8xQcDERM0 7C+6s/xOUO6j+OenzoLuJo2fJ8zzNhGd5vVLfUiQ9hzrAMqUbvlqWnvt3o7lL73G4/LTkGNcWPTh+ 1D6KgWE5gDhZ54dHA2auBk7YCfTADLqv9m3XtOteyAHr8Ly42u3/6bEZ+dh+aLPLhk2cmwFGQMZ8H QuzMDWZgF1B+SRT3zob5agTDTUn8+BUWfYHB1l4AjEX8Tpjr7PHI6STZdFC3qG3r6GX8Tg8r8D9i4 Bj0QkOZvGXSfCSbnpZFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vq-00000003joW-1OS4; Fri, 13 Dec 2024 12:38:10 +0000 Received: from mr85p00im-zteg06021501.me.com ([17.58.23.183]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tM4vo-00000003jnq-0jrF for linux-phy@lists.infradead.org; Fri, 13 Dec 2024 12:38:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1734093486; bh=gAZiIBAW97iSqVxa0yzt2S2NKUuhI3+PKJU5sy0ohIM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=GTPLGRqI7p1Ug1WY1aEwDN1yujO59xixCqprE1ZG56aOCN7U68v4cuc4Ch2zXZAkN sg1zCwuNzK0bo1+vCD/XBDB6DBmyNkcby5lP8BWIwd2ZuWDSJBdh9T/nBh151AQw61 G9ec6MNgTav9ZpzCC7yhOC273s6iEocbnvYEF8ADLbNEjKSK5Cia+9h8C4KbH5NPfY Jom59IwQG3XT7TUQXZahOaiP8XfmBWbPu89fq3gdCD9zGi3fbbneUL0JQyME7gV9Fv 97nNftPHguBSu6PI6oCin36dAV7X1olD48w8k3waOe8DiFLAL1u47yZlmc4wb9x1Wa g4/RmMai0Lwwg== Received: from [192.168.1.26] (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-zteg06021501.me.com (Postfix) with ESMTPSA id E31592793D1D; Fri, 13 Dec 2024 12:37:57 +0000 (UTC) From: Zijun Hu Date: Fri, 13 Dec 2024 20:36:46 +0800 Subject: [PATCH v6 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation MIME-Version: 1.0 Message-Id: <20241213-phy_core_fix-v6-6-40ae28f5015a@quicinc.com> References: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> In-Reply-To: <20241213-phy_core_fix-v6-0-40ae28f5015a@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Greg Kroah-Hartman , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Simon Horman X-Mailer: b4 0.14.2 X-Proofpoint-ORIG-GUID: 2JINNleipOqtTWVGoJDHTzZH0QuUezzf X-Proofpoint-GUID: 2JINNleipOqtTWVGoJDHTzZH0QuUezzf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-13_05,2024-12-12_03,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2412130089 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241213_043808_227965_84A4088F X-CRM114-Status: GOOD ( 10.96 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu Simplify of_phy_simple_xlate() implementation by API class_find_device_by_of_node(). Also correct comments to mark its parameter @dev as unused instead of @args in passing. Signed-off-by: Zijun Hu Cc: Simon Horman --- drivers/phy/phy-core.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 413f76e2d1744dd8ffb63a6c3a093f5c6cbead7b..8dfdce605a905d7f38205727151258af41f807a9 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -749,8 +749,8 @@ EXPORT_SYMBOL_GPL(devm_phy_put); /** * of_phy_simple_xlate() - returns the phy instance from phy provider - * @dev: the PHY provider device - * @args: of_phandle_args (not used here) + * @dev: the PHY provider device (not used here) + * @args: of_phandle_args * * Intended to be used by phy provider for the common case where #phy-cells is * 0. For other cases where #phy-cells is greater than '0', the phy provider @@ -760,21 +760,14 @@ EXPORT_SYMBOL_GPL(devm_phy_put); struct phy *of_phy_simple_xlate(struct device *dev, const struct of_phandle_args *args) { - struct phy *phy; - struct class_dev_iter iter; - - class_dev_iter_init(&iter, &phy_class, NULL, NULL); - while ((dev = class_dev_iter_next(&iter))) { - phy = to_phy(dev); - if (args->np != phy->dev.of_node) - continue; + struct device *target_dev; - class_dev_iter_exit(&iter); - return phy; - } + target_dev = class_find_device_by_of_node(&phy_class, args->np); + if (!target_dev) + return ERR_PTR(-ENODEV); - class_dev_iter_exit(&iter); - return ERR_PTR(-ENODEV); + put_device(target_dev); + return to_phy(target_dev); } EXPORT_SYMBOL_GPL(of_phy_simple_xlate);