From patchwork Wed Oct 30 14:18:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13856592 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 C43C7D5CCB2 for ; Wed, 30 Oct 2024 14:19:05 +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=KouRKuhnyOuT7Y oR9V/46B61ZDRvuzlYKyu0FZhPRmjOnHRLFVf6dsBfIS/9EPpyn+a7EeSbx9FeNv7/H7U6NVck6Vp s0iCMVuRjGRqGVGTRRn4wns70zYWx5JDcf0v9VL16/FPbS4BcF+HEjYmr60iRrwXtxZAD9Q9gAJHy 3YqOz8E3zVg4I1BSADyhfDt63QlMM1yJN1uQSzmE8fhforHTlefPGh6TIU4Jd5C0yf6Ayk9HILSPj 11QCE0IXkxx1m8jXps8LAgjBAnKzOUYc75bQjoa+mnokmqKTIDsS1Q4pkzODOH5HzZFiFJU7/2lDM S0uDfHpkcTu4d7Ef2B8g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t69XN-00000000d3K-24uK; Wed, 30 Oct 2024 14:19:05 +0000 Received: from ms11p00im-qufo17291901.me.com ([17.58.38.48]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t69XK-00000000d1w-2pYK for linux-phy@lists.infradead.org; Wed, 30 Oct 2024 14:19:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730297941; bh=vWvPGu251oYkL+PTVEWgGIZl7f0hmGMZGCDwAIm43uc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=tXyTUqNb9GzwXBeGIjBFuP3FgoddBjM3dEHOyk5xWqJELN0ofD0Uc4/uB5m5MRZV2 qi+S+UX3DqUYD4NlEf5lXp6ocQ1qX3k0GqA+6+8bS61n/jr15FHcl3L6MoE0Vsoadl 2pKbhKV+f4c3xnx1pFsdPjH5H8Agt72PX8yRP3rWLWSXFFcmPeWqEDARYaf8HTJBe/ iEGeEanlazDM8YOaB1wzFNrjwP85Jiw8gpLmH3us8DF3PknJ4OocMLWHeOT15MdmwL z3m9Gyu2AZ0tnWUODSJ/7x6pWQc9CIdiSu5EEtzpgoaxAeR9ZQHyH2i4gZblItnUL/ yB32jqw1HJ+zQ== Received: from [192.168.1.26] (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17291901.me.com (Postfix) with ESMTPSA id 107AABC02AC; Wed, 30 Oct 2024 14:18:51 +0000 (UTC) From: Zijun Hu Date: Wed, 30 Oct 2024 22:18:24 +0800 Subject: [PATCH v3 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy MIME-Version: 1.0 Message-Id: <20241030-phy_core_fix-v3-1-19b97c3ec917@quicinc.com> References: <20241030-phy_core_fix-v3-0-19b97c3ec917@quicinc.com> In-Reply-To: <20241030-phy_core_fix-v3-0-19b97c3ec917@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: KRcO9NduntJ9G_8WHU6EzaOnEuZhFdSC X-Proofpoint-ORIG-GUID: KRcO9NduntJ9G_8WHU6EzaOnEuZhFdSC 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-10-30_12,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410300113 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-20241030_071902_759277_2B5CDE30 X-CRM114-Status: GOOD ( 12.93 ) 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 --- 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 Oct 30 14:18:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13856593 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 98044D5CCAF for ; Wed, 30 Oct 2024 14:19:18 +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=x4adGlnJWXj30w jegYcBpO4MrpabCp1geoTuAxfOnllZ16IzC8lgIpRNd8HrNJNDYubcjez1F9S5Zzwed2lBg+3XoJA 9mY+wJMYGZSkLBuYQAJVykS3i6OOmw3uhFFgPLIMspi3UUUB6sv97weu5U47TSQsFbCD3lkD5KSuX tbr8RkrQmgYk66ze2wSo9svQ0RrbQ0JYxnCXGtA+6o42zEDa9kYZPMDGL6FGxCF0QcuYZxf+XSGg8 jEvqmkmGhNhX0gH908mvUH1JqHqwU2P+eZI7tHHHy1LAissToeH0z1HaQyEYrTBjZQcxXdEIenuQi 0PbnqZ9G+hQAy0LWncIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xa-00000000d86-0kJI; Wed, 30 Oct 2024 14:19:18 +0000 Received: from ms11p00im-qufo17291901.me.com ([17.58.38.48]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t69XX-00000000d6z-3ghq for linux-phy@lists.infradead.org; Wed, 30 Oct 2024 14:19:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730297950; bh=4SuEXx9ddfkxQj1AQp57UC2HOKADg1X3Q4LCag85EnU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=JPzuB8RR8ju6RXo4slRR6W1puQ5GkMLV2K7ukB8u/M+LA2ugS1vNPS/or5pzy5IQH 7JazL2KGyeL2eNeHAaYsmAU44qelXY4PEYtbrFCe32ksTQgB68J9guhmnyDtyWnQ5e Qp52rMERG7Eebxi3WBubJrueORfCRwnKmP9G7kNpWmmG4SBDcZrCMvP3+QKocuP3JB 0khd4r0YizjlSby/F+vJc2//kCIGW8lub72qhwgr7mFVFSiVOgZoZHRZxIE5a6I9XO grbwhy+GueSjznm75/UIETpCxsvx4YQ4in0iipu5aZzTDYiO3X82eHY9JZAz/xOr61 dMlDCpEz2J21g== Received: from [192.168.1.26] (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17291901.me.com (Postfix) with ESMTPSA id AB880BC01F4; Wed, 30 Oct 2024 14:19:01 +0000 (UTC) From: Zijun Hu Date: Wed, 30 Oct 2024 22:18:25 +0800 Subject: [PATCH v3 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider MIME-Version: 1.0 Message-Id: <20241030-phy_core_fix-v3-2-19b97c3ec917@quicinc.com> References: <20241030-phy_core_fix-v3-0-19b97c3ec917@quicinc.com> In-Reply-To: <20241030-phy_core_fix-v3-0-19b97c3ec917@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: a0_zSuWftRCGpbUEWyLL5C6M9dq2C0ZJ X-Proofpoint-ORIG-GUID: a0_zSuWftRCGpbUEWyLL5C6M9dq2C0ZJ 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-10-30_12,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410300113 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-20241030_071915_985943_03699563 X-CRM114-Status: GOOD ( 13.15 ) 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 --- 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 Oct 30 14:18:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13856594 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 8A014D5CCB1 for ; Wed, 30 Oct 2024 14:19:22 +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=CI97sL0pXFE33g x/QoBgpP+U5aeLssTxT+kO3jkJXOGBG0wu7Ro8DAJW57BzsWAjSIS+73ETdmnfUYbvP/KHXw7nHwv PnzwUwCwEnvBI/VilSAkz+ythT+GNDSwqh/T5YB8RBjxB32WaAfpW6rFRiafY7G+eqih8RFDV7mTv Wp2+FV53EkjXWPqpfApaqs5eL3P/kTSgxJhQLw1yqmKbgMDhrY88VX7QKBGxxRFCFCxt89IBG7AFc qTtaFT0dznpyaB31fnSiFLwv5PKQ0taZVQ91jzEXP1iPJvGAwH/nQ2e1PqBy4czhXit2pHhFgn2IV GrsNlKt2HdzwDfU7g+YQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xe-00000000d9a-0wLS; Wed, 30 Oct 2024 14:19:22 +0000 Received: from ms11p00im-qufo17291901.me.com ([17.58.38.48]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xc-00000000d8c-1AkX for linux-phy@lists.infradead.org; Wed, 30 Oct 2024 14:19:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730297959; bh=JH4PLE2Ueuk57jBTrJMy1byNBdSHe/p/HgNBwh/Fobs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=w/MkvKd++gMbvMJ5HDABsoY27t2wunTOtksLTGmI86sGe6tK1WEKNlPqhlmij+eaV lJvKPzoYCm/3Co2yWFUXoWMhaXKHoK2jYUNnCU7Ek97GJ5X++a2mGufxvlvR806m1M TQaFtOQUY6c7K+MtTqJR+5LHizXLihmxiFPvAx22fXr8FD7yFiTZw7qUYEUGw3WKZw WOjolM5a5rHL8K62xOhj5ZSqlfLn/ltWGz7wekg2XhZBLfH5hJDkprEA+sw+yPuusI WqBDKP17vRAVd6BqUYvW/tE7+7JramKkVPTvLp3G6agbwXFazrC3F7raANqN9CL5tT SJR0dkT4qPfeQ== Received: from [192.168.1.26] (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17291901.me.com (Postfix) with ESMTPSA id DA7ACBC001F; Wed, 30 Oct 2024 14:19:10 +0000 (UTC) From: Zijun Hu Date: Wed, 30 Oct 2024 22:18:26 +0800 Subject: [PATCH v3 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy MIME-Version: 1.0 Message-Id: <20241030-phy_core_fix-v3-3-19b97c3ec917@quicinc.com> References: <20241030-phy_core_fix-v3-0-19b97c3ec917@quicinc.com> In-Reply-To: <20241030-phy_core_fix-v3-0-19b97c3ec917@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: 3vi5sPVEyGfQOu8B4zInxOY8iBdXU74h X-Proofpoint-ORIG-GUID: 3vi5sPVEyGfQOu8B4zInxOY8iBdXU74h 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-10-30_12,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410300113 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-20241030_071920_379624_07843A79 X-CRM114-Status: GOOD ( 13.78 ) 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 --- 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 Oct 30 14:18:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13856595 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 7AFCFD5CCB1 for ; Wed, 30 Oct 2024 14:19: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=eoxo67qT5GC4UOGsjIm/u9dH7lYW6dCVw4g8VSe9DOA=; b=H8pqllOXKweJ4W ksN2QsokBKQ1COTQ4IxXj+e4+uTVBZ7ldmjSk8frmrx3xgdljUGDk9sfdMzerdzX4qReiefWMNELO GtwGE4+dw8EUOXtipIHyt2MTFv0NSsxKiAbDgE6ZOx4QjBAW/4Ge/e5xi+88iFuR5/c/RgZBAKC+/ o3L10P4i6soCljjoqxukDQ3SYySQ+ixZwUkm0v5vJF7kXwR1hd9czHl6YTF44igxEWXxaYw/yiKgK mJXX3VECkXjH4bypc/qUwFfOOPzYOeAfzjiGLEtpCwiVYvlHoGSHJYA+MOZQRuPsCxzi+c38CuuS+ SItsJDEwtBBONztgNxjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xp-00000000dDq-0Tc2; Wed, 30 Oct 2024 14:19:33 +0000 Received: from ms11p00im-qufo17291901.me.com ([17.58.38.48]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xm-00000000dCW-0nZP for linux-phy@lists.infradead.org; Wed, 30 Oct 2024 14:19:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730297969; bh=toeSTG1G9vSODnOMlPD25srU4vchWguh6NSK6vYSJnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=xBNqE/mRnPYdBHUItd2jTeo8Awi0MjU6q3H0rJPUixN+iRw5DSI0IXTARu0kHab0a LPtRoimDpEuVtuFP/P6rf/LtCWcvPYSp2hUo/aIlgPR1Z0SBpvvx2dX89WtGsIQ4KG M7ok35/gvIpXEEgY9qczKPt5leUa7DtmzpEBWYcoBNuPuI6Q+5HJ5W8KpWPVaob3EW K4AYdo5VUfR1WXU/uCceH7vfzZs0Hia/3jEXGSIg5JBbswfwn6AUupWdWBHI5YwBuj VekYuxyVPN/A5a1styNQF01BNs7Jf5P+Zpbjyi6Mjs3bqeiWOG3mFtJEO1orGqM4ac GfaklE++PdzVA== Received: from [192.168.1.26] (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17291901.me.com (Postfix) with ESMTPSA id 686A2BC026F; Wed, 30 Oct 2024 14:19:20 +0000 (UTC) From: Zijun Hu Date: Wed, 30 Oct 2024 22:18:27 +0800 Subject: [PATCH v3 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() MIME-Version: 1.0 Message-Id: <20241030-phy_core_fix-v3-4-19b97c3ec917@quicinc.com> References: <20241030-phy_core_fix-v3-0-19b97c3ec917@quicinc.com> In-Reply-To: <20241030-phy_core_fix-v3-0-19b97c3ec917@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: UGZtLvO1V-e2-nDBJPqX6d3Ah1CxpuBj X-Proofpoint-ORIG-GUID: UGZtLvO1V-e2-nDBJPqX6d3Ah1CxpuBj 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-10-30_12,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410300113 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-20241030_071930_302177_B13CA666 X-CRM114-Status: GOOD ( 11.47 ) 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 --- 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 Wed Oct 30 14:18:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13856596 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 0885AD5CCAF for ; Wed, 30 Oct 2024 14:19: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=dn4JgJiCufJvGFDJaEIGBZ58NecVtpxDHtZQguNWSAA=; b=ZEi6LhZbUgnpcW rk856SxfCluLZwWT2b2Sb1szx62PedhzBtz4TXtnGmyW29OkLBH3cPvVDtfKUOa/qsFaRb2mzlmYW pHQIo+l3pOOXl/pEPG6KBTsG9fkLsq29H8EKjYXKMak/XX3O940LmPdEs092cJSrqFlW6ayQcOG3D O63SiamTChXiTd6kvma8qIiJ3Vx0G5i54icoRMfuHkPLeqzQvHpn8xg7xb3ccV3y6biQMLmvJ/iNx Bpl8+sbNsl9QJryLuWIVISNOpJRPGSan77S8pOcr5x0MaWU7niLDXM2mcukRpNXfQ0xyVUB+4B/5c HKZQw2RcLu4nun9Y/eEQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xy-00000000dHl-2wqe; Wed, 30 Oct 2024 14:19:42 +0000 Received: from ms11p00im-qufo17291901.me.com ([17.58.38.48]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t69Xw-00000000dFl-0Z9y for linux-phy@lists.infradead.org; Wed, 30 Oct 2024 14:19:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730297979; bh=/xDAp1FMKoohjXNf6SYzu0enHw6XyaRJMqxsvwCqpAY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=Metiyj5IKVLX/zrRoiXllbJJ4DhNnCW8yfTOLr646yz0UZAxaOvwoTEaOQ7wqpkjw 3wn+SKMKV6Qx5iEAUdfULzdsprdx8xXtPOGQynlzn/ymO6gFoO5pyeWP8XVNRbC+kq NFeib8/8TBwEA4G//DNQgYZWA5aaUiFQ8LQNNmZiYOqMVw/VwnoqnQTYWo/IQXMYVC SM2hgheyo7xA4aBGDfrOlopQu+aIsvb38r3PZ5WQYbCARQx1Hhgzio7dAATW1l95aG ee/XngyU90hWspxg+VdwD86XneM497wyw5SUUjUbaqjgDVNRHaQci+9H2r9zVhZdUf Ke+FrWb74f08A== Received: from [192.168.1.26] (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17291901.me.com (Postfix) with ESMTPSA id 5AA1EBC02C7; Wed, 30 Oct 2024 14:19:29 +0000 (UTC) From: Zijun Hu Date: Wed, 30 Oct 2024 22:18:28 +0800 Subject: [PATCH v3 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() MIME-Version: 1.0 Message-Id: <20241030-phy_core_fix-v3-5-19b97c3ec917@quicinc.com> References: <20241030-phy_core_fix-v3-0-19b97c3ec917@quicinc.com> In-Reply-To: <20241030-phy_core_fix-v3-0-19b97c3ec917@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: tSsirJfjP54u_Uwxo2IEOrLjozEYSnVS X-Proofpoint-ORIG-GUID: tSsirJfjP54u_Uwxo2IEOrLjozEYSnVS 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-10-30_12,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410300113 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-20241030_071940_239387_450437F2 X-CRM114-Status: GOOD ( 10.75 ) 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 Wed Oct 30 14:18:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13856597 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 B4D18D5CCB1 for ; Wed, 30 Oct 2024 14:19:52 +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=prKregmXkKhUHcwV+n0NpMb0WAqMhvKPjZkVKJuy6uA=; b=n7CKXhbaW6f4qY ord2nl3R94ue/lCqXMr9KqYopeGiy59VtmyFY1vbw0TLRkIIahHDWJsSI/UOGg5/c9QCnQf6+dKdQ 1HmrUU6D3IzsIZ/e5yQllIe4Q0DawLOvmhcDUySQiADl+j/lNf9wET7/2QL6H2Jqaxw+bylquoGIc yIEITUrhrMy/wV1I6FLrI46w+i2VBZsfSBCxt0OyY0DSwk4hInZskc7BpeYjCvLZsiF2S6lKzVVaE pRzhN4ogKdRzMI+7NbBbdKBn/4KzzM1fRjHW+HyZsVzTsELohKgoP2UNYeG2/HyWDV+n9ZyVOJpVy +hUHeJnd1P7DDbPxrnLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t69Y8-00000000dL1-10Yr; Wed, 30 Oct 2024 14:19:52 +0000 Received: from ms11p00im-qufo17291901.me.com ([17.58.38.48]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t69Y5-00000000dJv-1XcI for linux-phy@lists.infradead.org; Wed, 30 Oct 2024 14:19:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730297988; bh=ZakhXA4iXn4pYZPN9VM+ilE3613V44qufhhl/xE3Xmg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=MDpo1gs5EursbtzVB2Ul5rNLfRcrXFu6htUBlqhBLtBqoPsficoEIupEstzdNegC+ y8NgbFSxEOaVcv5bdIowwN80wvA3GOO4hxWT5E63gofXiM+sbFnkuI33jUDZ/l6sW6 9rWUU752iwi0X60KQAZahIaL0+d5QR5ZZwD7JPoN+BHoM+dffc8y4SR8dlTq35RZbf pfcGOtx83+SUPkaep5UZGsuwN3ZBRgsOFlVaU/tPCB/aM9gQk6EcM3F6hBmEcNlFjJ 2/ImsFGh9FJNEjDiafRtx+K6dKxM9bkh/tRWqsfqEkFqcb/EYnwmCt+UJbDaH0CWZl 8sXXLzSfaRfhQ== Received: from [192.168.1.26] (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17291901.me.com (Postfix) with ESMTPSA id 38EFABC02CC; Wed, 30 Oct 2024 14:19:39 +0000 (UTC) From: Zijun Hu Date: Wed, 30 Oct 2024 22:18:29 +0800 Subject: [PATCH v3 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation MIME-Version: 1.0 Message-Id: <20241030-phy_core_fix-v3-6-19b97c3ec917@quicinc.com> References: <20241030-phy_core_fix-v3-0-19b97c3ec917@quicinc.com> In-Reply-To: <20241030-phy_core_fix-v3-0-19b97c3ec917@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: QTpvfTAyCY4I5nIWcjoiRNx73xgwaJFj X-Proofpoint-ORIG-GUID: QTpvfTAyCY4I5nIWcjoiRNx73xgwaJFj 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-10-30_12,2024-10-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 clxscore=1015 adultscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410300113 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-20241030_071949_470553_4CE8C109 X-CRM114-Status: GOOD ( 11.21 ) 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() which is also safer since it subsys_get() the class's subsystem in advance of iterating over the class's devices. 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);