From patchwork Thu Oct 24 14:39:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13849323 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 00BAFCE8E80 for ; Thu, 24 Oct 2024 14:44:02 +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=JGUlhZ43PwNiZe+WoiqAZXBIK0Hu1ZZLJh8tggzP4eE=; b=kPAcL3nyDCi+k1 C8PNUaOrqATRxwrUR8TxaTxzJkj+z3rpQKp34bmvq1cQmdXt2Wc+LDzkPibonhRDvC5GZkRybHBNp tBqGwirbNwxcZ7H7JQ/+OFaVBJ1ALqpgL0fInga99p50n1HXEAvL6UVcypB9qS6tmi26uH6BAozWq pTPj7CPJdH29xic3sNEnGaap0LriG3YYPq/DT0EKRun7Kv7F5HQf1jlmE/0Z5EDVSP2RRpwQ5JeA0 kwc4vbB2I4frKGoQzoca5TQdftXNrK95PP9QjOf04prNJOraIsM8Xz9Mq98YsT8OQjVMFDuY3PKVb 3tlqHM6y5eu25KXSMNRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3z4E-00000000nKi-2iWY; Thu, 24 Oct 2024 14:44:02 +0000 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3z0l-00000000mAL-1nBf for linux-phy@lists.infradead.org; Thu, 24 Oct 2024 14:40:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1729780816; bh=c/rKY0ydmsqmsb5VAz6RQ0R/W37ECcNylk7mClGfPHo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=S6zLwyqNEXARkAjbxPabqt/8JQ3zIkpgVa1gi5G9klp3VM6jCfun9kI7lAlzAG+A2 xC3e1D+NUabIF9oDJfI66BXwrOhpBxObG2TbXQegVAzvKQzvyrzQsBy9lsbMMwOZAT ittY30p//Gdvj0YvTCGnT06rRDFfT57+AOju8l0Pg1XblBzYpLrCUcOoBH8NsTK6zD ldBAjb2bkcHTN02vSBv5wCpvkqcmSmekD5ZVsCgsa8kQte94nR716tRiWJQgKmUseH GV26r0lZABybU8cstzK0HHoAuXbYrStV1e9gb0gVcg0DcPVQCuNJpeLjVo+3MH8EbW XqfjACuAkAf+Q== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id 66947C801E0; Thu, 24 Oct 2024 14:40:07 +0000 (UTC) From: Zijun Hu Date: Thu, 24 Oct 2024 22:39:26 +0800 Subject: [PATCH v2 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy MIME-Version: 1.0 Message-Id: <20241024-phy_core_fix-v2-1-fc0c63dbfcf3@quicinc.com> References: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@quicinc.com> In-Reply-To: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@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 , 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: sLtY8xgbdBGSAXlWpDWcppV-kzHRsNm7 X-Proofpoint-GUID: sLtY8xgbdBGSAXlWpDWcppV-kzHRsNm7 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-24_15,2024-10-24_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1015 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410240120 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-20241024_074027_506251_D05BE03F X-CRM114-Status: GOOD ( 12.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 For devm_phy_put(), its comment says it needs to invoke phy_put() to release the phy, but it does not invoke the function actually since devres_destroy() will not call devm_phy_release() at all which will call the function, 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(); 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 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 Thu Oct 24 14:39: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: 13849324 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 4BE33CE8E84 for ; Thu, 24 Oct 2024 14:44:03 +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=tu3vYbUYX65icKdL4ea8jG+CuFvokagO6Ziqk/EiGAw=; b=3UxMtXsaRZgaPZ yiLzBjsNFdCmBYHQjQY9LoEJIg99FKDrlekqW0IzQWGBHtnqYWtYt8ewOHl/5+QHujrEOPn7gA+lf 7KWYD+9fnwtSGAxKbTV8jlJofI2Hq3cd/JnU1HQnIwb5R1oiw7BNdPg6G4hm8g+TAg1QMBZ5eDQHh UFvBXHmiMPTfvtqt9ZETFi0ROdRSXpnRJTb0njIsHf/3RQnL0mSt3KzTlI4jIfvzNWpRlqksGbpHM 6ZSYJZWKAvcoLj54QxI8h9iCyiLZYvZsiaLySWY3bhFfr5779dBFD2d3YvUxDWdolrYXNAgzynDQZ GPxNL8mAgxgQ1mSiIF9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3z4E-00000000nL0-4BVu; Thu, 24 Oct 2024 14:44:03 +0000 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3z0n-00000000mAn-09Sc for linux-phy@lists.infradead.org; Thu, 24 Oct 2024 14:40:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1729780823; bh=IY7OGHzpIoCsCwScK85J8CO2WsYIPvSqixH8c9pokf4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=k426lwDDQoSxAd4KQQjcHBMp1GyyzoV+SsgcdF4/QW/eHVgQokUXNSlX8r6twXqUV DXAJ/TfRp5ccEuPEc2xAKHsrgcfnG9sayIk1MS4im0Squ1WB8BPBDbVAf/8ZTSmc79 jwROAqpAyH5/bhLHZfJHzp1UJlg8DifF5dMsuIYZhOTgSSaGqwE9XDQGfeKHTKQUmi KtiHH6VFuVT77JbNk4Da76627pgJx1ZuYns40q7QCdjXuYQt4pSILR+1Y16pS/Raqh 06XqMOo6pnR1InXhmHEPUhPAgU3RIXU5lGVnzNhVDR/ioLPahNanLjI36piojW+N6T c+oKmnxJr/mJQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id 4F6E2C8010A; Thu, 24 Oct 2024 14:40:17 +0000 (UTC) From: Zijun Hu Date: Thu, 24 Oct 2024 22:39:27 +0800 Subject: [PATCH v2 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider MIME-Version: 1.0 Message-Id: <20241024-phy_core_fix-v2-2-fc0c63dbfcf3@quicinc.com> References: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@quicinc.com> In-Reply-To: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@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 , 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: SioPm7yDGhdwDsR-7_Tlo6gC-OHYN77Z X-Proofpoint-GUID: SioPm7yDGhdwDsR-7_Tlo6gC-OHYN77Z 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-24_15,2024-10-24_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1015 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410240120 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-20241024_074029_134825_452AD5C7 X-CRM114-Status: GOOD ( 10.42 ) 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 does not invoke the function actually since devres_destroy() will not call devm_phy_provider_release() at all which will call the function, 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. 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 --- 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 Thu Oct 24 14:39: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: 13849325 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 A16BACE8E84 for ; Thu, 24 Oct 2024 14:45:37 +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=ebKC7ftwcFMXQV6Fu+yz+G9CZTuFMlfbkEJgiWMZT5g=; b=uY6H+SfyXmsJzU JlehKfavyUxsTtzS1mW627uSyo85o/iiNb+GVeRovdqRvVG3cVLknjitnSPVFzvHHMJ5nEdHHjcfN pqfsRiElDkbl/h0shnYW3O+K+vhpi7cAyGiT9pN5Wq5NZJNOdlB1GvgqrcocTZTSQYYesyZc7j688 gxhb4iqEP6jiHxa9FwchaLkCq6vNw1X15XSQLAB3oIObQ8lVNg98kXgvaR5uRGu5FbDhue9v5+R+t vK5L/Q1I8zkR2LhZ0quCAYr4lGYK8InmWtm0VWdssG7BiJ+SctmwZzUDdk4X/G0Rspdol7cLwMguh mWRN+5ShWkXyp/KR6CRw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3z5l-00000000nYB-1NCi; Thu, 24 Oct 2024 14:45:37 +0000 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3z0r-00000000mDS-1cv3 for linux-phy@lists.infradead.org; Thu, 24 Oct 2024 14:40:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1729780831; bh=6mqxkWzrEpyKrm2lpF26RrivIenk/tZDn/SIHzzqvlg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=0cta08Hk5UECwqRpw5sluAfg5bJQ6gK0HPTl9zMqQxM/V7njFvXlIb+fxlfYW+n9g 8aHVK2PtPjAV9FtP2sfCaCVJdJ3YEu6yJWYV7sW/CC3f2WV4eckB2rcbB9lF2L0CZI 6ZBtYp90HX8ZSycHjgNbbuNaaeJwjFxzSEPa1GxQFOUBhCSfMhXt1umDrX9i0WJzAP B8VQybrGH6mrcbVlEwxFHSc9W4fcZmP0pWOStZ3UYQQed6WE0e/L+S8tyqOYO403UX uylJ+x54W+NaG7vVrdwai1nmzw4WLunIA0m6L/VF00cGW0i8PVahs30cmYAROR/Wnf 8BKxKf6KBwQug== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id 53724C8019D; Thu, 24 Oct 2024 14:40:24 +0000 (UTC) From: Zijun Hu Date: Thu, 24 Oct 2024 22:39:28 +0800 Subject: [PATCH v2 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy MIME-Version: 1.0 Message-Id: <20241024-phy_core_fix-v2-3-fc0c63dbfcf3@quicinc.com> References: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@quicinc.com> In-Reply-To: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@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 , 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: suBrFoxD-WoAD9TMyXHHqMf0w4lir4hd X-Proofpoint-GUID: suBrFoxD-WoAD9TMyXHHqMf0w4lir4hd 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-24_15,2024-10-24_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1015 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410240120 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-20241024_074033_508455_F59702DD X-CRM114-Status: GOOD ( 11.08 ) 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 does not invoke the function actually since devres_destroy() will not call devm_phy_consume() at all which will call the function, and the missing phy_destroy() call will case that the phy fails to be destroyed. 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 --- 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 Thu Oct 24 14:39: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: 13849326 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 029E1CE8E80 for ; Thu, 24 Oct 2024 14:45:37 +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=es/Gnqqbr494DKEOLI4Yjh7lkPqyqHkW+z5XhWYpXrE=; b=ltVP0zU0wofNjN WOCaR83xQJmbgdtgPgXrZOmFMnIzxXLfqsO6HvgncBG/SQOHX/mvyBIdKlyIUQJPirClxcHJ0U3+9 +U9u6NXCLb0DZhj/lL9ZLGsgm1QZx0X8FlUR6rynPsg9Zd/rr5edefWXZ0gC2sTecJ8+lS9yfAi9g RGtUZ7Ua1OH0JR9BCDZ9mfIzxxd2MZ4+NVoqHBnrOsW45c5J/0rrvMPG3hVSfJN8YR6ICYXvu6apL sEqDLR9bzhY5Ge7xW9pmwtGAV6lbfcS1d1zUdG3H4Oqc1dprEZr/gDTSACtEGWHeqgHjUOwozCa2j 6652ntrCkNrfva/H445A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3z5l-00000000nYN-2bAs; Thu, 24 Oct 2024 14:45:37 +0000 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3z12-00000000mG6-1e4M for linux-phy@lists.infradead.org; Thu, 24 Oct 2024 14:40:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1729780838; bh=7SUVDbgSA2VfVZU2rqgQuLCciZm9GwyAD6JqO4qnFgM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=0+NSNjFn68dgCW5i+v659pv1usu51fd/8QHQfjydDrEI8ejVud+tearBU0ObxZTVf JpNieaL0NLuqvGSOw/15WMy26cetH4U/OujVejp+bEe1+iSRkZxTvLJnX1jeIGCFF4 ZglqrvNS9Lagq+8K5LqGe+yTTdI9gEg4iCExgDAuNA3FVxh/7aCxzquFFfDtS0wwMG 28XxVJR6ciRKinzYnBgNYhOMR4sOTQFGPd0oLj5snh6yP2LMvWF1Ik5zLaa5+NhwBp khLKBDAESVRkVZO6OPu5NHVlqiDQb+uomDxmo39lD0beHHGS4/C9XJmP56DWWuysEN LexEakwQIrZUA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id A1A1FC80102; Thu, 24 Oct 2024 14:40:31 +0000 (UTC) From: Zijun Hu Date: Thu, 24 Oct 2024 22:39:29 +0800 Subject: [PATCH v2 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() MIME-Version: 1.0 Message-Id: <20241024-phy_core_fix-v2-4-fc0c63dbfcf3@quicinc.com> References: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@quicinc.com> In-Reply-To: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@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 , 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: A5fzWN84D0-VXZjY7cEVmNuokoA0ioi1 X-Proofpoint-GUID: A5fzWN84D0-VXZjY7cEVmNuokoA0ioi1 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-24_15,2024-10-24_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1015 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410240120 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-20241024_074044_612270_F51FFB08 X-CRM114-Status: GOOD ( 10.96 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu It will leak refcount of OF node @args.np for _of_phy_get() not to decrease refcount increased by previous of_parse_phandle_with_args() when returns due to of_device_is_compatible() error. Fix by adding 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 52ca590a58b9..967878b78797 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -629,8 +629,11 @@ 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")) + if (of_device_is_compatible(args.np, "usb-nop-xceiv")) { + /* Put refcount above of_parse_phandle_with_args() got */ + of_node_put(args.np); return ERR_PTR(-ENODEV); + } mutex_lock(&phy_provider_mutex); phy_provider = of_phy_provider_lookup(args.np); From patchwork Thu Oct 24 14:39:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13849327 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 3F45CCE8E85 for ; Thu, 24 Oct 2024 14:45: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=vxt8G44i+91TRaWv2ce+hU6+P8QKAVNl9vQvG/6Vpw8=; b=cdQdPNz0DwwG45 96pExOQR7KiiCjX8XQcOH5AtKpMEMyqhOwLY+pvSCtYob1o6k1FupsS99TJIIGX+/QMQyG+DfGBGU JTKrmKDVZVDDnWOj6/avlwMMddQ0PSuU6evBPcl4tqdtM7f7PjQEsLhln2ZN+YT6XDMyTV7UcaT4R jNnleTaiMeKTqFRpZLxMQSLe4/82DcoJFD+xdNEotObX9L+t19kijEk9KPWLlShSMBRjZSb0qAQDF 6kcyANg/wuwqOZ6chXchNsRUWEoee6TEMLNjTMZvUlacLR5tl/dO7nFOkTUVBNSM4H+LInsqL++Ot BBVmaNr6IUAjMKtjGQlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3z5l-00000000nYk-40Li; Thu, 24 Oct 2024 14:45:37 +0000 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3z14-00000000mH4-16oR for linux-phy@lists.infradead.org; Thu, 24 Oct 2024 14:40:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1729780845; bh=Ao26SUIb49PEusAusFKVqbKwYbs2RGsKMlMvZlYTPaY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=puj7eOkviFui+XPsW59+5X+gEPwLIDDj0ip2kCBMb9ckgcCVO9y5WMle8LC90hCgo TVnZsLZyu+M8qJMqsedVLqBZIsZI7w+GcPbPl9B8vijaUh8TQq6f7bZKcc1wEMHy4G BaVir5Mv6CGeSFFjByPwTi7MM8ollBCiM/IjgLK09hanfsj9Ra0iP7aUlsoQbDvdnP DYoB8GcELq6Iyu+G6mnSZetOJpfw6oZ198ec1wI+4YRE/f+LI4Rcm2qow2hTurNpe8 aDairxQYm+uLUxJitzL2TqyOfd0VGNNs/7wH/EJJvN9sFT1LSsHCzyPamlyF0Fmn7E syLDcInm2fFqQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id F3D3EC801D5; Thu, 24 Oct 2024 14:40:38 +0000 (UTC) From: Zijun Hu Date: Thu, 24 Oct 2024 22:39:30 +0800 Subject: [PATCH v2 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() MIME-Version: 1.0 Message-Id: <20241024-phy_core_fix-v2-5-fc0c63dbfcf3@quicinc.com> References: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@quicinc.com> In-Reply-To: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@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 , 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: ljF3k-k6RczWgU4HR65qjNpZTcRZvZNQ X-Proofpoint-GUID: ljF3k-k6RczWgU4HR65qjNpZTcRZvZNQ 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-24_15,2024-10-24_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1015 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410240120 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-20241024_074046_357513_B8284D61 X-CRM114-Status: GOOD ( 10.26 ) X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org From: Zijun Hu For 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 Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- 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 967878b78797..de0264dfc387 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 Thu Oct 24 14:39:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijun Hu X-Patchwork-Id: 13849328 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 DC687CE8E83 for ; Thu, 24 Oct 2024 14:45: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=zXdT/55UnkZYXz9dPooiKxYccymK9UBXgcej0uqHgDg=; b=287zhhgMxQF+V9 srdeqVU/a42t22AC+QswzthZNrWOgxTib2uw1xNW22ESiEbeRDB8KqFi20UVDTsF/fE5W/2Hzo4vR J9Jtbidq69aYNKvCdKTSsolVwlmBlVclnd5YbeMQ8R0vNoWx+Cbos2F9KEABXLgmgrhXCKfK/SMYr BoV4/4WFvP/LdVtZfjmjRnvnnDItsJY797OOH8EszM5lJgk9sIzziV0OIKapVERGmhxMo1kE1g7yS U3gnJfzTA1YqFijgAcvWVm41cP59CNRYDDWPBLf9LdVHVnAR4vV5Gm5Nw5IxMEZTU5WmxflP6m/aK 42oX8wVYfs20eKhjtPCw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t3z5m-00000000nZ1-1CYC; Thu, 24 Oct 2024 14:45:38 +0000 Received: from pv50p00im-hyfv10011601.me.com ([17.58.6.43]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t3z1C-00000000mLi-1Btv for linux-phy@lists.infradead.org; Thu, 24 Oct 2024 14:40:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1729780854; bh=WmCswZRvkq5WGhabYEyPR/NmcnJ9vmObxp5kPrfpCBY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; b=hYcgBkly1dOfQwz/FwLHxlli7FRnHINaxmitJN2ytTrAZ2i9555OuGsPe4Ncwd6Fn VnkaxwSrnzBu1FVjNp6cQ8KyRIRI1zgj4wvf6wxpl4P1vVkt1VvEZZwzz1pP5i7tYb 4vRN1/0dUg7i+QOicQKLdnsNBv+X6miGqmH9Ke8XfnHK2guU8A+AWsWxSm8XefV1TH fdJaxQhta5amcUls0goL57b4ZLJBK5wee9/e+CYViqg5u9wuaEwGDzzIScp3sQIsCk 79a1ZksS3iRgmWYGM6xoQkuwXfCIxDl3xbGf4ea3C3BqT3qwNO2E1/iua/lbMG8ibC N+sMxp6fMJiUA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-hyfv10011601.me.com (Postfix) with ESMTPSA id 636BAC80102; Thu, 24 Oct 2024 14:40:46 +0000 (UTC) From: Zijun Hu Date: Thu, 24 Oct 2024 22:39:31 +0800 Subject: [PATCH v2 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation MIME-Version: 1.0 Message-Id: <20241024-phy_core_fix-v2-6-fc0c63dbfcf3@quicinc.com> References: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@quicinc.com> In-Reply-To: <20241024-phy_core_fix-v2-0-fc0c63dbfcf3@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 , 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: bMZgaXaVPFhitUgiIfVpQoWbRlqMPNO3 X-Proofpoint-GUID: bMZgaXaVPFhitUgiIfVpQoWbRlqMPNO3 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-24_15,2024-10-24_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 clxscore=1015 mlxscore=0 spamscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2410240120 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-20241024_074054_423214_E6878607 X-CRM114-Status: GOOD ( 10.83 ) 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 de0264dfc387..b83c6aa0287d 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);