From patchwork Wed Nov 6 15:29:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13865082 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 C05DAD44D78 for ; Wed, 6 Nov 2024 15:34:24 +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=82Hr/EmhsIRqn5zKCDwZaHoIPl1XTy4OrQlbEr+dRw4=; b=2xDPdbj5Z2XwIk bY6+l1MT8KeymdWOeGET7IvhD1ElGmkcSj1CQb19iXxhc7NbXt24XG2JJmguuF/jNF3xMfBDL1Puc iO5BEJ/FDTNBEFguDcOoRGCkM04RMsE4qUn3pALx9WlbdIz1qK6VqpeeJWT1dR5c5G+/PzZeJMgHq lkSlGQpponS1mrC+g2WD5OXnM/eP011bjGJrUqY7ORaA7ALpssCPNdiZQYwijo9qsoa7peItP2cvd tAfiIeNVT8t+FR40487zUUfcubR4UxY+R8PHOsUsMJnBYawleuUut0KYB525ZKt6N2aUFne3velbE VWpaksHhlQmd8OQzyrgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8i36-00000003pxL-1g0a; Wed, 06 Nov 2024 15:34:24 +0000 Received: from pv50p00im-tydg10021701.me.com ([17.58.6.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8hzL-00000003owX-3IL6 for linux-phy@lists.infradead.org; Wed, 06 Nov 2024 15:30:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907030; bh=kDM9n2NzpCZMaLluXurrrPauvVeEV4qNGscAtK/f3Ro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=WgqbqTBVkqLitSjHYLzgA2GLsBcXYfyyxfc2JrCtbMkzxq/3gUhZPT+1IQqxcy0ok 591DgJEO6PQftAlCSzJXT+LsbgarJq/9xwEW2YhPhano9Y5ZxEGyE1NUO3ovfKg2+C AWNI6BhBfB4BfMZJcOOawPyXOIIanZHfZu8eRsESvTMydxiiY4S67/QYwXunvfmmfP oGPYpQOfruNZnF0fE0aqH5kSwWRlsUDcH2BzY/Ie6vbvroYmhgsyPwlfi6mY1GvlnS 57t1stMQvmEt4D/PvTPdaURtGRZZzmcwOuIWw3rSDop/nkYU4v7DmS121ER01pFePO 1i8+sjENfGw+w== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 2EEDA3A0A01; Wed, 6 Nov 2024 15:30:17 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:17 +0800 Subject: [PATCH v5 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy MIME-Version: 1.0 Message-Id: <20241106-phy_core_fix-v5-1-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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-GUID: 396FS2ilzy-__07h64kBH5Fxkcc1YkYA X-Proofpoint-ORIG-GUID: 396FS2ilzy-__07h64kBH5Fxkcc1YkYA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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-20241106_073031_862760_CB8A4EBD X-CRM114-Status: GOOD ( 13.20 ) 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 Cc: Johan Hovold 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 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 Wed Nov 6 15:29:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13865086 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 25166D29FBD for ; Wed, 6 Nov 2024 15:34:25 +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=iPorTeSKbYXQwt/InUCI3Aq7GKgEPgsy0pxn1TvcOz4=; b=lSge2f7h5j0Khc Uxq0N2XsFgC1cGRKj0Rv8rnljXkv28CMnAHt0umDbZbuGkZP84pW/Qh+CcPhaqPF1hgRoDeoCXK3e EKA/6f8EUzFZudfrBArR5K27g2BrWg5l9xPq6LCox/DfEjBhmFKvEhiwnsSKJuK3PwwFy0Orsirkk BkmMih418Zfh2nJ93L9ADElkmmVZjWdSK6bOYOFTNHCapMBIFnKahDu1LtYhIQuKvldltwVZBdkyV SCidEXgmgTwCwDolBWugF6RmJK+pFEX1MbOPlHdNv9w67maAPX3KJXLAi64+evr/Nn+7mh8yh3UVT F/V182JUq/SY/kqWi7UA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8i36-00000003pxo-3EF1; Wed, 06 Nov 2024 15:34:24 +0000 Received: from pv50p00im-tydg10021701.me.com ([17.58.6.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8hzf-00000003p2e-3lHz for linux-phy@lists.infradead.org; Wed, 06 Nov 2024 15:30:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907043; bh=gXDaTlvtbcQ4620sn7VJl7LM/l6KBZAqPN7GJEoSAS8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=OQdkFHavbijUZ6V8LHAtiMh29xd7nim3WmVzvCjFV/Wrlrfmgo65eNWhaRrAVaisK 1D7Gh2OqyJUcUOXl24buofAk+jjlhA/AQBCO05V/R4Z4ZF7t/4VUhOXpw5au6i4+JK MTQoi57NQJEr+c02xQ9A5bwO6SsFHAcJsnNwF76bC9ibJLjdgdt/LG232TddxHtmhH t/lEBFpMq4NnW/BKTm3LKUHwZKAUOrEoquvyaajqsJ0Yprgu2bFQjcBv4Q7RiRz1ys Yq+uN3CgDo+A2apU9LiUin3G5TGAQ0237IB3AA9l+2YSqnrooKcBt2/kEGWZvfwP/q aHksR9Yx9y2sQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 3EE9F3A10F1; Wed, 6 Nov 2024 15:30:30 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:18 +0800 Subject: [PATCH v5 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider MIME-Version: 1.0 Message-Id: <20241106-phy_core_fix-v5-2-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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-GUID: NkVSiluEF-TtD-WFLQjJ3KQtdcwT94VZ X-Proofpoint-ORIG-GUID: NkVSiluEF-TtD-WFLQjJ3KQtdcwT94VZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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-20241106_073051_991471_232FC815 X-CRM114-Status: GOOD ( 13.22 ) 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") Cc: stable@vger.kernel.org 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 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 Wed Nov 6 15:29:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13865083 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 7B033D3E789 for ; Wed, 6 Nov 2024 15:34:25 +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=/ajWpT70XVe7kC8zzkHUW9N8+tCycnYbDqrQ5jSQvZE=; b=DtWGWKLhESweWq EkUJzLVjNAJQW6Hc2fkyyb7Z+jfBR+IYYkLpTU+M0deJPmKqwjkLP9uXvmc0WgmkGRqPE9JyPIOEP KS+lFGYxD+H0c474gbKG/lX5UaMy/FdBvOB8jtZ4bIBeScGiUpEe7Jqv3uG+ZEQiiUfyhtaH5VCCP 44e/KjsSjE33F+cDThRVcey/ha0xrED232TaJ08vdE0dsmhjgPNZPgCeTAO8kC+NAZSw6tPM5oiXG FG7JuCCU+8X8FRIjlwTkm3M11jNbtcEPO+dD6yIIkEjrXmtyRWvpbkSaDn49T/7Q3eQfYzQt3Ogxz Fk0U6O55+5TnYp8S4MPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8i37-00000003py5-0J2J; Wed, 06 Nov 2024 15:34:25 +0000 Received: from pv50p00im-tydg10021701.me.com ([17.58.6.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8hzn-00000003p55-08Ar for linux-phy@lists.infradead.org; Wed, 06 Nov 2024 15:31:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907058; bh=D4p/ONPwsChgPFkyQAZ67fVmHAM1m6iVzlq7cFn+C6Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=fr3HZQ017dFCBGKqttkIsUH2i3owsFsG+7gLZMNXsBYZ6xXhGy1yl47UdUlea9o+i SS97zM/WqTgmQyJdYA4IcPffxaBC4vYN+GBtVGU3Jg9XE0zQvBN/vCenJA+Vko+3NL nAhSmKNpW7tRrvaj56rNGr/Y0EOILd6vBAs9D+vq6DohmC+aCalDqYasiRYoKlxuM+ oXQ7mBd/49q5AoyJP342heXsninLXoChVvECmbwtfEU+uH1LmtkjqxFILH2LOPK4He OAzdE5i63FqwQIoXdL8v8V/WLDXVefW2vQBikf6ZrQ2oG6Im/XZvIwTiJPd0Bk3gv6 LvNNbV7npFOEQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id A9D853A1115; Wed, 6 Nov 2024 15:30:46 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:19 +0800 Subject: [PATCH v5 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy MIME-Version: 1.0 Message-Id: <20241106-phy_core_fix-v5-3-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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-GUID: IspyCmIlreuz43qiXRwdWu5eepWx8eoK X-Proofpoint-ORIG-GUID: IspyCmIlreuz43qiXRwdWu5eepWx8eoK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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-20241106_073059_123449_1CDDB0DE X-CRM114-Status: GOOD ( 13.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 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") Cc: stable@vger.kernel.org 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 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 Wed Nov 6 15:29:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13865085 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 CE968D3E799 for ; Wed, 6 Nov 2024 15:34:25 +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=7e7Ad0QjRVdcz7day4F3zU7bswAMv24XAmAGwSaSDqk=; b=lexhQr+6M9wj3i 1Zi53Qpt9vmwQ0jACpT6NWpHHVxVrP2pkNdvmGpO8AOnI34y5nFqYUb7aDLP3srpmKQ2ZD3b2GPNT gq7ZBL5PlgnWd3bV60+xw9Nk/s8OSg5b2unFyQlFxAkubFPw7nx8EIBL+p1O2WsID2wki39VOhX6l gENCQguRsAbCxokpK9YGyg+bp+raSxQo3UTmXkRM8xlfiq52yosw3DBmJXRZRQDnVGdvMeQAR9erW TJPJ+Bk8Z4nwXrEdd9OmhaN65Jw+2F7qmPNHylezjmO96LIiwGI5lnd0DKSY5UZJx1mJXJBVrU/pf hvRvyBBYql9rP7/yoYrA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8i37-00000003pyQ-1kA4; Wed, 06 Nov 2024 15:34:25 +0000 Received: from pv50p00im-tydg10021701.me.com ([17.58.6.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8i01-00000003p9l-0mv5 for linux-phy@lists.infradead.org; Wed, 06 Nov 2024 15:31:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907071; bh=jRJAq6X1q0kmcyUpWLUZ36Ko6dovwQNaa0R6U7y4YOE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=W6/p8tBjL9AUAg9Podk7POQ5vLnNEo8ef1bFmoIF4j/vVQSo+5kv7MbvN1ePRcSEO sS5DYAU24u6IHuprUqLj+ZI8tCcRHDbkwdFlyuQgBnowvYcncNrroBPrVm2FFmbdhp +5cpCuEE15Q1h81E8oUZGdTZr/0CjDSl5O/d9jxOi8bymvPuuYhjddbBz71lYHNbmy HFsFINDT5t04LvUtkSHEe0tj0UK7J6VK5vmQu6z0+liT9S6SgiSycocnTPmZSDIhGE LeFTe3cyw9z85whLCp5wNbhaV2CDSDQZlVn2zr1iww2D+5jopHeK89hII95xfvEIvi HGQzJ9NZV+tdA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 9C3063A10BF; Wed, 6 Nov 2024 15:30:59 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:20 +0800 Subject: [PATCH v5 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() MIME-Version: 1.0 Message-Id: <20241106-phy_core_fix-v5-4-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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-GUID: XhTcyP6hSKb-9YGDWtkqgALci_WdNh6U X-Proofpoint-ORIG-GUID: XhTcyP6hSKb-9YGDWtkqgALci_WdNh6U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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-20241106_073113_281369_9613908C X-CRM114-Status: GOOD ( 11.03 ) 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 52ca590a58b9..b88fbda6c046 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 Wed Nov 6 15:29:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13865087 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 139EED3E79A for ; Wed, 6 Nov 2024 15:34:26 +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=Zf0AwCX0l1YZBxlmyfUPxdyGYh3lLi/oSYba/LCj0Fg=; b=SMtN6tM4mg1Ff1 1f42FH7RD7OhqG1YFNDTCFqgaMQ5NcsaH5SB3J5KC3+hMBDCBM3eohPom2JWD+iPxeF/BeynAWhab KuAuc+nEwIGKJPZR3t7GKtjFyMuQ1TbKv2f45eignZMfgIGD6PcrJINI40CnRxG5pgjwR8ZT4yDsG 67uofpec1CP8nUlXjzJQIHkoTk9ZH2uzqt7eFO8tM3nvNrC+gEFs7WbiqkjhW347PL6oRb7cpIU2M T+oUYYTpZ+XeBvge1OrXJRN49Xcq6usLOOn5LzD4aKQHjJb847v7FUPCDb9RF8f5ZPj0qSFb3HPMU C6pYWlxAqUVZYTBRSquA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8i37-00000003pyq-3D09; Wed, 06 Nov 2024 15:34:25 +0000 Received: from pv50p00im-tydg10021701.me.com ([17.58.6.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8i0D-00000003pCW-1Gxt for linux-phy@lists.infradead.org; Wed, 06 Nov 2024 15:31:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907084; bh=vn7YLlTMs35v/+bzgOIOZMQXRYeYPFiSPDi8rm2sJcM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=E+MspX7WdtzMGksSBtYzuCb3l2CAHvMSFZM2LLyF+T3joqiOZ/rDl5PlWfxbRUHvS oP5y/QQjPOVahyAoGRYDaALJoRVazqjCd+A5jcOmlL7eybgY20DgPeN0WeYqMvXdn/ eYasYgV5yfNSbMUVUOqRPdyGDDPqexbJRUYI5X7zyYm1tcttn23HUU+FgeCta6GFOd JA1reKNHhUiveMC6c5AK+nIhRs41A9M8PysGcgRuCSqIyQSRtLAP9h7OPIG5UVU7tf D3xE01op17lutnlWIg0mn+LNRhqzdCCKGK8OXhi2+pVHrTNFH5SO5UbMg0cmVxdszF ZWunrT5nuMGNg== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 932873A0A06; Wed, 6 Nov 2024 15:31:12 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:21 +0800 Subject: [PATCH v5 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() MIME-Version: 1.0 Message-Id: <20241106-phy_core_fix-v5-5-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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-GUID: sPXWQqURoU3m9fe4K3pZkqREUZjSNIng X-Proofpoint-ORIG-GUID: sPXWQqURoU3m9fe4K3pZkqREUZjSNIng X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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-20241106_073125_401760_58EF6BDD X-CRM114-Status: GOOD ( 10.82 ) 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 b88fbda6c046..413f76e2d174 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 Wed Nov 6 15:29:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13865084 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 6A4B2D59F41 for ; Wed, 6 Nov 2024 15:34:26 +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=JtOIfUH0puXHttsS+0DshZfWPYPYKydR7VYPWl31au0=; b=o6AzRCJoRGNup6 /Ry4tHCM/l3usaT2Wr4X6qSZh31pFZ6KkYPNxJl50ixz2TRGxFdrQ/192pjSZJzEkfOzNtahVUYXN +ojyc3iuz+XhgIKUvOztgtesHa1lrzaLa5mgLydqr+WJWCn4gdOPjG9JUbttzmchN+9CBs7bnOqMI C/LBMq8fksOvYaoIqKAEdMiuycoQzJWjDKVf6+tZQAaQ96vbX/kF67o6O6F5pLvGU3J9C+Y99jZkp VglRgi1ny30sZf2QSteaG18V3YW7CtfHD+M9zQFQJTawse+j4MPu9gsXlPUyCU3jPzMG/thZpl7ii HuxqcGXd0hohLoN8geiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8i38-00000003pzE-0Swj; Wed, 06 Nov 2024 15:34:26 +0000 Received: from pv50p00im-tydg10021701.me.com ([17.58.6.54]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8i0P-00000003pGn-3R3I for linux-phy@lists.infradead.org; Wed, 06 Nov 2024 15:31:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907097; bh=SyatfIV8TYuY4KBrfs0SWiSBpZQ2QH8QB6djYTU8Jpc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=PPNC1YMJJZheWJEXr7hFXaJvYx12jTX11+AiqxIoWfpiyRDWf8b6Zn8qhDYt4W8bJ XMRxsmPdWip/GMN8wiREpHiurL8lF+Uplbd+yuEqxRqTcsMaotIb984+Oa/JNqZUF5 TD+r6kQ0fpIydMPPbAsG9kimntUytQ8vFYeGC6WgjxORjEeEFF+NqR+xhwFwmrV7RC VQ9WLC1nbi+xRwChBF4EGxbnckMqL2DgOKPdSzBgFmuI7gYDbnzfswd6o0pY97nziE WxI3LC4VDTkuYpXf1l/E156ZkweAL0gU1GYGQgSwQH6gWVWi/i3yfqGJQ2d4gr5hXk rRWJjXdOcts9A== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 77F483A10B8; Wed, 6 Nov 2024 15:31:24 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:22 +0800 Subject: [PATCH v5 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation MIME-Version: 1.0 Message-Id: <20241106-phy_core_fix-v5-6-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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-GUID: zwvertWuy8IcK0I14C7v_mzF4MXFQOMu X-Proofpoint-ORIG-GUID: zwvertWuy8IcK0I14C7v_mzF4MXFQOMu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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-20241106_073137_993677_DD483D3D X-CRM114-Status: GOOD ( 11.05 ) 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 413f76e2d174..1dbb854672d3 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);