From nobody Mon Nov 25 02:46:42 2024 Received: from ms11p00im-qufo17291901.me.com (ms11p00im-qufo17291901.me.com [17.58.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7858B1EABC2 for ; Wed, 30 Oct 2024 14:19:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297943; cv=none; b=oswUSY8L9zpSw+fRpDOJ240f5RcTUoSzMRlLvxKVfnSs1z1qXBQf3iWZqujCiHBP3cA9Sh4r04TAi9RhrTb+Qu/B6IHpBoiEacLYgigsuDSwuuHgiqfGiAI6b7Jxe0iwxCwKWDPPCgTjeMwc3ALoG5uvHfik64vFUWWiL2aweXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297943; c=relaxed/simple; bh=sdBwJWQ6ygdWuveJ5bfLElwUqgfCsYWhRjFOQhi7j/k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RzlP92YylT+ewvYc0mTXyt8hEhTduVS/4cVDGSZ73ifIP5LAl9A+ExemLF3nSJvZT3n6qI6idEk01P72D6lbK6E3eaCDE1w5J2htucfR+DEJ/cFcdPArlgDUiqN1e7VKRXfQGDfK3nt4C3RFoiqm4LRUSTx7x6/HosBtNlaXE+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=tXyTUqNb; arc=none smtp.client-ip=17.58.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="tXyTUqNb" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=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 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 =3D 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=C5=84ski" 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; =20 - r =3D devres_destroy(dev, devm_phy_release, devm_phy_match, phy); + r =3D 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); --=20 2.34.1 From nobody Mon Nov 25 02:46:42 2024 Received: from ms11p00im-qufo17291901.me.com (ms11p00im-qufo17291901.me.com [17.58.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A31BC1EC018 for ; Wed, 30 Oct 2024 14:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297952; cv=none; b=s5LHC8iARkxIh6Eq0yaV8QhKPA4qDlchAfYTUEFUDhAI1vNOgHFF6gAcPVMY93UobemgXiORy37ibG8gZ0syKxfeqc63wKVrNf5EcN9llVkuFqipX5ycFI9SQS8aKZDclJmm1f3o2eSVQPg/DpDUwze9SWZ8F2EfFYa3Y+7YqVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297952; c=relaxed/simple; bh=nGsaVSj3Or+PJCrL5rwS3AkSAQW59whRTC5OEgG+xXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UsVLhzQx0p3x9ZIbuP/Vi2ZUY+EFxQlYxqjkHoZLfMEeH4uwqd/mD2v+mLajOhH/yBMKmkPBDuVeylaiTkc9/qShsiw+812TR4e5SZ40D/C7Oclq+oji9WaaFPxjj/OIcvBA0aS+ZxyWx2Ys6vGj4J/Br8i6sKGYqe9Fmshs50Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=JPzuB8RR; arc=none smtp.client-ip=17.58.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="JPzuB8RR" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=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 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; =20 - r =3D devres_destroy(dev, devm_phy_provider_release, devm_phy_match, - phy_provider); + r =3D 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); --=20 2.34.1 From nobody Mon Nov 25 02:46:42 2024 Received: from ms11p00im-qufo17291901.me.com (ms11p00im-qufo17291901.me.com [17.58.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62AF51EF94E for ; Wed, 30 Oct 2024 14:19:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297963; cv=none; b=mikcBrUlhM3X5lO/46tinDhRVoQ0yeuCEcec9fw/At+ezDtESgPY2gqfsJO1WstuRZ934nnm/+1zn9opK3wSwMud9eBt50oivEw3al7qvq6RtHu257O0Tlecl8uadQ3aKYDk427WdEBbHVaCXJ1xZsPHFQ8jfcMeozGoMVeSg1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297963; c=relaxed/simple; bh=92EGOINSOaGj1I0u/RpgR5u33MAN5rnUxszAui8+GlE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GZBBM0oiG0oQcjA/K5tO+HU4v2t5EcITZBi6CeW7mjNEw5D+XC0f0Ya6/hegVptel/WaWRMdvKioxKvWYt7qxGmy23R33FfIz97wTG2YMyvPRSglxGo5ip1U2U3Hbk58QBivdUCBgNUtQaoobx3S+dh194NHI4bsLkcvlt115pw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=w/MkvKd+; arc=none smtp.client-ip=17.58.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="w/MkvKd+" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=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 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; =20 - r =3D devres_destroy(dev, devm_phy_consume, devm_phy_match, phy); + r =3D 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); --=20 2.34.1 From nobody Mon Nov 25 02:46:42 2024 Received: from ms11p00im-qufo17291901.me.com (ms11p00im-qufo17291901.me.com [17.58.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 571C21EF953 for ; Wed, 30 Oct 2024 14:19:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297972; cv=none; b=NLsdgCiqo6LjQbrARnc3QJPk6eq6OPPS6YmI+CVTKLjzQl9eZCUY2eavdKx9laGg6nJoNJ5LC5cPGVtJzPYYXsGlW4Ceap8qKSjfBXGUQbKS2OAoUefctNbSCpHM1SAbD+7Nn2nZpJXG+vyPvE9/U6aGd2WQhKUqfSmvRKOyW1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297972; c=relaxed/simple; bh=BxGlcQezFWQl4tzqPkJ+P+ewrSmqTZbTtmnndcK5vz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nWJlkvzXew+d9Tk7Cy/kPhl6N38i5sDQDtZCKxUkopc3nLpfUtcgxXJPkk6ZiaxMiW/LWHlyu8RFZNs/vivIBjIpJLyP8WvbIIZ+d6CYmtSumjLbg3dH8cWca2KOZ7BUEK6/K+2ph+tG+N6IpRiPfygog3Zhffo6JNXvA82+JH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=xBNqE/mR; arc=none smtp.client-ip=17.58.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="xBNqE/mR" 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() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=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 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 d= evices") 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; =20 ret =3D of_parse_phandle_with_args(np, "phys", "#phy-cells", - index, &args); + index, &args); if (ret) return ERR_PTR(-ENODEV); =20 /* 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 =3D ERR_PTR(-ENODEV); + goto out_put_node; + } =20 mutex_lock(&phy_provider_mutex); phy_provider =3D of_phy_provider_lookup(args.np); @@ -652,6 +654,7 @@ static struct phy *_of_phy_get(struct device_node *np, = int index) =20 out_unlock: mutex_unlock(&phy_provider_mutex); +out_put_node: of_node_put(args.np); =20 return phy; --=20 2.34.1 From nobody Mon Nov 25 02:46:42 2024 Received: from ms11p00im-qufo17291901.me.com (ms11p00im-qufo17291901.me.com [17.58.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8A9F1EF95E for ; Wed, 30 Oct 2024 14:19:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297981; cv=none; b=dDoIgqZplujJa3fqERlEhKTgs8PVZpGCaOyfz/Lu75aObQCjFAV4Zw3iv/ZS1BbooiZ5KGvARMYFcoS+9IJo150re9PPuKDyR+VBqreTu2iomgrEgoyoqm8rIiwBwwYGlglBOO58ZM19YC18wMf4c4+kMqcMt/v04q6pK7D1obA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297981; c=relaxed/simple; bh=GtU76M6i2RKZjVJicBblCUDWJFIYTPUiNzBHNlGbmqM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eztYXfSz7UyjUppB54gAEIoUAIcE/YHekcSZ0yaAMh3mLeJCK+yhJ9/R9LRYP/71j3tw0tvuywF04WcMw3ajtAPEXZMIHprIATjcRF9yZB/qAbX4QY0ilH5PvisXuU2kIqVZa5fjvwBMfKXfHPfYQBZFXIuvgRaxsq6kFFzUnbs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=Metiyj5I; arc=none smtp.client-ip=17.58.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="Metiyj5I" 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() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=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 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 p= rovider 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(str= uct device_node *node) return phy_provider; =20 for_each_child_of_node(phy_provider->children, child) - if (child =3D=3D node) + if (child =3D=3D node) { + of_node_put(child); return phy_provider; + } } =20 return ERR_PTR(-EPROBE_DEFER); --=20 2.34.1 From nobody Mon Nov 25 02:46:42 2024 Received: from ms11p00im-qufo17291901.me.com (ms11p00im-qufo17291901.me.com [17.58.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EC651F4713 for ; Wed, 30 Oct 2024 14:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297990; cv=none; b=hzwL7xNt4JRSiCGCrTSF7wWFbkcfz2qx6JfiZSlJep2USo/QecA8BqQGj58MFnkUNO3f4o1hVEoGd2HTvGLMB/AcQ/kwOP/hGfaaiGWpRr7tvs9BjPdGsSHFW3t/vZw6793lF42YGBI75LMO2pvpwenyC50YaS0EBQF9WUc9GGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730297990; c=relaxed/simple; bh=SK34U5RHBmAsPixFJhqplzyxy0jl6yeoCiNhMra99nM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kELuyHyT3DhZjxlXZeNLbHEOUa7RLPz/SJk/wK9VYeSt5FD3Ge5gFu3XBGa4mHYWlCm8f4Km+GFXs0zcb8do1jThV3i0LO4Eqvy2Y272lh+V47Qe43j36BHmgRE1ik5yuJU6pXP6/w8ttu2JACTwMWrO5ggdP3dn6cNb4hfpSBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=MDpo1gs5; arc=none smtp.client-ip=17.58.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="MDpo1gs5" 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=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 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); =20 /** * 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-cell= s is * 0. For other cases where #phy-cells is greater than '0', the phy provid= er @@ -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 =3D class_dev_iter_next(&iter))) { - phy =3D to_phy(dev); - if (args->np !=3D phy->dev.of_node) - continue; + struct device *target_dev; =20 - class_dev_iter_exit(&iter); - return phy; + target_dev =3D class_find_device_by_of_node(&phy_class, args->np); + if (target_dev) { + put_device(target_dev); + return to_phy(target_dev); } =20 - class_dev_iter_exit(&iter); return ERR_PTR(-ENODEV); } EXPORT_SYMBOL_GPL(of_phy_simple_xlate); --=20 2.34.1