From patchwork Sat Nov 2 03:53:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13859911 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 29B42E67497 for ; Sat, 2 Nov 2024 03:54:35 +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=bTwkqZdffmygGCA+3zFGQxxACuI9R9aMfrSV/W/6+ic=; b=qFBJCHA7bgIlBO c5ChUAliTUfAgxrhlKyLKqNXrqEKAFoRCEjJ6oeLieBW35MXlMaMp0KwHDInAxz0Il1mmNggWq0r8 P6JqZ1jkqwMtBHVcAukaBPQChR58c/HxLeUik/KPaZkPkgnOo7DhGP6EJe5skGAGOyXxDH4dcXuMg sT+bEGZEQJ/JwIMvVxkpchKKBkbdV34U+UAfchfam6F9UtAsv+IasWuSXR3L7ya8KJNJOE0npe7W3 zoZCeTRGWfkCVAzEDPuZZ2vyh6r99oQ42LektEBmduQKcc/Fnb6k9l6oFGfoBAe8DKXTXz4WILhRZ jRi6rODdMaWBO97p95vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t75De-00000008yiQ-3eFG; Sat, 02 Nov 2024 03:54:34 +0000 Received: from pv50p00im-zteg10021401.me.com ([17.58.6.47]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t75Db-00000008yhp-2dz0 for linux-phy@lists.infradead.org; Sat, 02 Nov 2024 03:54:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519664; bh=vWvPGu251oYkL+PTVEWgGIZl7f0hmGMZGCDwAIm43uc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=WAs1oex0c+Y78h6SmNmO5co6vwP+jQkLG+ugKTnU/0AYwjHcJfYrvoUcq2U/6xbHO x1JUdPWeTYsiqlf1PK6843DP09jSgl4ViTWB7UkgWQC6QD4xVJ1DluZxQCr7wk1nX2 noDRKempXMpKHrHErWExO/78F+C+1b1rCN/92FLE0+Pvgp0qdYkujPp7Ls61ufKtVq WieY8/XiVJa4kAzNGEfD1Gss8pIUjyY+jCcw69B3oP160143IgVSE9tzKSckEzL3RX eVZQSmAsBRixa6wnFT8GVCPIzD/phS9bMeSQMr6QJR2EJB6osfEpeZYEnqf+0Qb8cK Tt1CwHuDB/mRw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 07AFC8E00B3; Sat, 2 Nov 2024 03:54:13 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:43 +0800 Subject: [PATCH v4 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy MIME-Version: 1.0 Message-Id: <20241102-phy_core_fix-v4-1-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: 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 X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: VBFZYkbd-yy1qVXFeyW1gt5AEzHJi56C X-Proofpoint-GUID: VBFZYkbd-yy1qVXFeyW1gt5AEzHJi56C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 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-20241101_205431_708972_8B70B0CA X-CRM114-Status: GOOD ( 12.68 ) 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 Fixed 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 Cc: Johan Hovold Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- 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 f053b525ccff..f190d7126613 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 Sat Nov 2 03:53: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: 13859912 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 91C17E6894B for ; Sat, 2 Nov 2024 03:54:38 +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=/C7DP6E3J2BCiYTICdEvKvn00XmpNgVbGoBT1N34eWM=; b=puuNvKXjwf8ohc a7cKSVWUwPKM6J+WLa42EECk0LAwBr5gdhah4By920CZb4uIsUq9/fVzSk9ULV/Epl4rP+2sL2N62 0SSDAaJkVjG5Nje5WihSXpNgsdOD6EKNuoTz47i8ZqCG7VDmbQ9Mn5CJmDnkQmizakGYP0zvU96nu ysI2K4ShIxVyOVHTDPMBLo5SA5u/ogHV19DWFhQd7flKtCBYTgJWSJAzGsVg6obfW4z+07xeOVGT0 mxEPlSSmPlpoTeyStxH9j8XTPXe0E/8A5yVRZ6c4NlBM2a9uhZk1JhMXIcDwkFGHouqfnPsgU28id Ybv9lLXOLGHDX9ZFaWgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t75Di-00000008yjz-13Ma; Sat, 02 Nov 2024 03:54:38 +0000 Received: from pv50p00im-zteg10021401.me.com ([17.58.6.47]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t75Df-00000008yil-3Xx9 for linux-phy@lists.infradead.org; Sat, 02 Nov 2024 03:54:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519675; bh=4SuEXx9ddfkxQj1AQp57UC2HOKADg1X3Q4LCag85EnU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=DocaVHfO48ZC2WeKzMcfBg2iCGiSqgW0XDpiX9LMRvlQb4DCtfJ8Y3b8wgA6KiKln oF20A+VL8HenjW5fMmIvWmhzjN0+NNX25tlpZTFxtRsxucsli+zSY490xvaKhlkR72 Oa+7+cudXbSAuFNAPQbXDFxWePKsF+t1TzJ52rclDHBDX+10QogNuHgxuWIa6wZle6 xS+i25hgkNzasqzvNTCfuhlMT/W1PrXNWm6Oc5r3A/jY8Qq1XU8owwgj40TrOrQhFZ h8U0j778gE9Zg+uv7s2RH1/AvKLakhzAamFiQTTG2s9U1tlf4ls1lj3t4+9tpq1uIU 0Nv22i6ZnG+Lw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id F08C38E001D; Sat, 2 Nov 2024 03:54:24 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:44 +0800 Subject: [PATCH v4 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider MIME-Version: 1.0 Message-Id: <20241102-phy_core_fix-v4-2-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: 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 X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: sZ1d0MhMlAkKd3WtDVYi4Z85pp9PjKSO X-Proofpoint-GUID: sZ1d0MhMlAkKd3WtDVYi4Z85pp9PjKSO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 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-20241101_205435_919361_2B97749B X-CRM114-Status: GOOD ( 12.90 ) 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 case: - 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. Fixed by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- 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 f190d7126613..de07e1616b34 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 Sat Nov 2 03:53: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: 13859913 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 B4755E6894B for ; Sat, 2 Nov 2024 03:54:53 +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=VwILqIFJdh8UVt4EH6cno49y8IFOGyszhKYqWm62yA0=; b=kP+MvZYCsu02lA bgHCud9P9T95x+kahCpNdphhy8QrLpnFyVjEQ5n8sRZjckB4WEpNMetp6DKaiLXJNsbK4WgzB00ih 9KFt6t4MtsHxiPKfLbrPz+53NdGg8abkzE0PBWqSJjBSOB+qCuxzqkx5HUJrbSW4QVLlNw0kvZ85h 8pQ6QliaRoSb82rWWwYgznNYKFOlyJRTpcLlKsxEz5kf6ZPo6Wlivi9tLcZmv/8Jrqyg6jlI+6Jna 7HfaLxdsq/fMVJj++6SXKKuSk+E+VJl8ZhtEwugmHFaHmoHeQnmmcQKjS+5pNXf/shAW+QzaRYuuP mWURPv16vduKgn8aHAcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t75Dx-00000008ypI-0hXV; Sat, 02 Nov 2024 03:54:53 +0000 Received: from pv50p00im-zteg10021401.me.com ([17.58.6.47]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t75Dv-00000008yoP-2ALV for linux-phy@lists.infradead.org; Sat, 02 Nov 2024 03:54:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519686; bh=JH4PLE2Ueuk57jBTrJMy1byNBdSHe/p/HgNBwh/Fobs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=Pkkz/TijAgnlXHMysDyZoxIen2kUVvBkL67RqJFoSWxpHDWjuy6M+68/l30P0B0yd jNgzlGAuPB3glYvS/UkIbpyBm0n6VtzUskfICRzL476UH5DvPDnyNnu0qFch+CWbCJ XksM+UkxhxRZQeY30rIS+t4H55V1TCmtrc0cDaqBZyFvMdnemJZ9BhGnuoCAKmz21f /s25IXVV+I+QZ3J3MVuTQemcH0xbhVMn5qu4o5qW/R1Aex5yRCz4e1l54K3j8V6X1v IozOhGxENeMWWKRi13SAjpAL6yX7yLCIdwq2NqjDmaxiTWUGJd3t8SRaR/RxTz2jgI NoUH9l4CJKhtA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id E00238E01D3; Sat, 2 Nov 2024 03:54:35 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:45 +0800 Subject: [PATCH v4 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy MIME-Version: 1.0 Message-Id: <20241102-phy_core_fix-v4-3-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: 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 X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: GhmL4pJC9aQs-aNsLgPM7SwBPrZlx_Gt X-Proofpoint-GUID: GhmL4pJC9aQs-aNsLgPM7SwBPrZlx_Gt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 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-20241101_205451_590272_3F72AAD3 X-CRM114-Status: GOOD ( 13.53 ) 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 case that the phy fails to be destroyed. Fortunately, the faulty API has not been used by current kernel tree. Fixed by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- 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 de07e1616b34..52ca590a58b9 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 Sat Nov 2 03:53: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: 13859914 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 4E9E5E6894B for ; Sat, 2 Nov 2024 03:55:06 +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=eoxo67qT5GC4UOGsjIm/u9dH7lYW6dCVw4g8VSe9DOA=; b=EeyC9/mdMIQC25 tSltnd/6+bF4UhHku5yJdFAa8Ryws2LsInlQK4Dw7LUmIe+KFKfwCvTlucF7S+h0P8Z4YVB766f4y HSfQoOk0RKy3puu/21q1GQE5VlGMK3fi6uRXgFbc9SHLx+KxGknKyZJSkc5jeLO7QoQvZpzaPLThM MsZ7/iVB6T+xACwFRufap6g14KtLW7BIo8AbXTQUJ41xWVuJ+A3PySf3KMAiuyQxdmafbjNgte6DB Xzf/TBIdKy6+PuP9V1p6frGv6jskUj/8KRDsS/1tkUYC+ZEGSlo02JWg6BixxSNkdbWemAnICMd3R F5U+g2KBm8JZMecQ5bIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t75EA-00000008ytt-04T7; Sat, 02 Nov 2024 03:55:06 +0000 Received: from pv50p00im-zteg10021401.me.com ([17.58.6.47]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t75E6-00000008ysn-2yaN for linux-phy@lists.infradead.org; Sat, 02 Nov 2024 03:55:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519697; bh=toeSTG1G9vSODnOMlPD25srU4vchWguh6NSK6vYSJnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=gEE+Q0BHmF3IKQcGGBCumeTFjOc551M5gvwK+Yu/S2alOeDlJzqN/ouaLOCHHcKcD xUHHi6z5C9muTKRuMsFZ63ox+2Wj7Y4T/cQRSrnXdRBAKRDtOniWl/KaUngHl+vdKx jLTSSqoMCmdodw09InlTw6CU+XIOJ4nwP89xns7p//ok48BEYlMWAyNDwXShcYMJ7R fFLg16kifKSkLFODpL69BFCm1+rw5V9Mr13icAcxDS1ExhDsqzmObWGHU1EMwB+3JU wN/2AfQUMUZ65tF7zBeOhSo1Cma3XXpAueQLsoGgdmgPOe42LyQ07Ng2YaVlxC0n/L M0pG/rkR5bokw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id E7A938E0088; Sat, 2 Nov 2024 03:54:46 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:46 +0800 Subject: [PATCH v4 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() MIME-Version: 1.0 Message-Id: <20241102-phy_core_fix-v4-4-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: 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 X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: kcVLdLswlu9IQ1-VEEHCLvzb46GQ7BY0 X-Proofpoint-GUID: kcVLdLswlu9IQ1-VEEHCLvzb46GQ7BY0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 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-20241101_205502_969167_98BF77A2 X-CRM114-Status: GOOD ( 11.12 ) 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 Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- drivers/phy/phy-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 52ca590a58b9..3127c5d9c637 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -624,13 +624,15 @@ static struct phy *_of_phy_get(struct device_node *np, int index) struct of_phandle_args args; ret = of_parse_phandle_with_args(np, "phys", "#phy-cells", - index, &args); + index, &args); if (ret) 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 Sat Nov 2 03:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13859915 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 3743BE67497 for ; Sat, 2 Nov 2024 03:55:30 +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=dn4JgJiCufJvGFDJaEIGBZ58NecVtpxDHtZQguNWSAA=; b=PWCHiGwohaZ4Or 6dnZY04XXg3tq5OyV1ADNAhQQtkzeMcJfBeD5StB7hiYMy2FNCtVi2oPwwIxFWxQmr1foiOvlKyZa f0HGoEKNL3zjABRG+PtEj9Uix5qmJT223Ckz7y77MiTZgVU4zD3ZMUyOyoXmLJEBhEdcNzn5imVYz XRt3TwGzP0foyeqNgN4CfhuXEt9LFpFjruGuc+2Yi2W9IGZuEC2HD6c/lbK4clroaGeYaACHnm9pm WuFneZ4Y7XkoozlhjK25IAn6YkFSjS4S1+FNMrwfqs45AY0IlxWYe/XzuNUq2iPgUiuAsun1LPrj+ iFwvpLN9B7VSERm4vB1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t75EX-00000008yyW-3gVH; Sat, 02 Nov 2024 03:55:29 +0000 Received: from pv50p00im-zteg10021401.me.com ([17.58.6.47]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t75EV-00000008yy7-0foE for linux-phy@lists.infradead.org; Sat, 02 Nov 2024 03:55:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519726; bh=/xDAp1FMKoohjXNf6SYzu0enHw6XyaRJMqxsvwCqpAY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=XLqkagHWDgslVODtuCdwUwXOZWM1RDuXiT81J+teNOc+FfQsnozA7SY1wod56mHCS EaaCsjCwvdTTQi7Fk1GJioLzrkQpfuJtdJ5vNTMkxk3vWg26D3P7/CAww0LzGKAjBt 63mKjAJRrK8SRQmOY0taxJa6HP+tsZ2lpm1XoMrMhKBpFgx1fzYXHskvs5Bedum1q9 2zi+wy4AtHNWg1owsfp5/xd3sNPgPuB/e/uhW9Tb8Gm2SuvABMKZis6lqS4WY03yu7 jc4lFUiz/t2QAIIOztMHFzQJuZ25M1122f8I7SH+r0l+wKt9481JjVGtTZhEaKP4pb FAWC+kZ11xsjQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 167B88E025C; Sat, 2 Nov 2024 03:54:57 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:47 +0800 Subject: [PATCH v4 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() MIME-Version: 1.0 Message-Id: <20241102-phy_core_fix-v4-5-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: 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.1 X-Proofpoint-ORIG-GUID: DYGZfXmOFcG85eyxohgP_TfPVQasc3AF X-Proofpoint-GUID: DYGZfXmOFcG85eyxohgP_TfPVQasc3AF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020032 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-20241101_205527_252160_768AB17B X-CRM114-Status: GOOD ( 10.40 ) 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. Fixed 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 3127c5d9c637..9d4cc64a0865 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 Sat Nov 2 03:53:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13859916 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 13CB4E6894B for ; Sat, 2 Nov 2024 03:55:47 +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=Bvc5FiASusxG1OEaBp/rqbFUHIBVbPEsLAqTA5WUKdE=; b=r1tTAcUZRe7OJs 7cQgFoC15gBoHGhI2EYRwNPfSoH01m04n926zwVFVJ1/Zl4KnDuyevEy/AI6QiqWzIAF7RCkMFnWA OaSJifHd25v7gwaLyD7mTqN7iOlB1fB+f9uWGkQJWM/InXkgEbV/Cl0NwqyEnmr1v8XlF7ASvhVrn w8xfJT8tkJTILy117g6xzY2VqKKMVauaxjy5amZ85qZz9rSonduRUtltKWoYH+doc23//ptWRt2ik JjT96bUxRnnanoQ+nZ896JjcaQ5T1LVj8AEWfwqi/ykVpf2rxKcsS4C4Qlx8HiTFsFmzyUGRbRiH+ txfmkbtgMiZp076BlUDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t75Eo-00000008z29-2hyp; Sat, 02 Nov 2024 03:55:46 +0000 Received: from pv50p00im-zteg10021401.me.com ([17.58.6.47]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t75El-00000008z1A-47aj for linux-phy@lists.infradead.org; Sat, 02 Nov 2024 03:55:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519738; bh=06XEXE3RdGyDqIVZgj7Hd7CzsKtHn4L7U6k0cu73Blg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=COvujrbRwoQZyFJcH82UdPbs47EQ+luVL7mkAfhryXRBczX/QWQRmgDECixzcxqRo 1SlWhQeNOrCeNJ3hHTep0rEWseWyK79yQpNXSn0jj//D6IpsS8rFdg0WnNNRFWl/Ti Wct4fUKlINGdKRZzpsT1i6P7ztYIEEw7LyfCqy934fKFffDVEWZlrJ4ivYDWwJ/AN4 LOfTS9tpSD0THAr0q87ppBFNJF19WkiugENQPD1MSAeYZSB/XnTR60T1Ap00I6G/G9 HKgPOB5d3maht5SBOo82ePwGiz/lIPG8I+pqrdwrn6MMPvM6R0WbmqVe1WClcm6kqG hbQLd5tYdvv5g== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id A67858E01B7; Sat, 2 Nov 2024 03:55:27 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:48 +0800 Subject: [PATCH v4 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation MIME-Version: 1.0 Message-Id: <20241102-phy_core_fix-v4-6-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: 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 X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: QuSC-0nx-vVo5COz6hbbnQz0mp8EobP4 X-Proofpoint-GUID: QuSC-0nx-vVo5COz6hbbnQz0mp8EobP4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020032 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-20241101_205544_073821_648420F3 X-CRM114-Status: GOOD ( 10.72 ) 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 --- drivers/phy/phy-core.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 9d4cc64a0865..39476ca9e51c 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,20 +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) { + put_device(target_dev); + return to_phy(target_dev); } - class_dev_iter_exit(&iter); return ERR_PTR(-ENODEV); } EXPORT_SYMBOL_GPL(of_phy_simple_xlate);