From nobody Sun Nov 24 19:42:27 2024 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 ACE2B184F for ; Sat, 2 Nov 2024 03:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519666; cv=none; b=oDTdWf4PbfLIm9mTteYbqqRpTMmLqpvfKhgflXlnA9avdejmEpyCEbPEqo49ExJTovpoiZF17bJwdowR9Jc1utGwkUi6s4jnoxzKP1OVsECwvlhLHI3B+TmO3O3ycH2KWqk5WQVC2v0KU4nt48njqOzPfWHTcXf9qH1dNeUudh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519666; c=relaxed/simple; bh=sdBwJWQ6ygdWuveJ5bfLElwUqgfCsYWhRjFOQhi7j/k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bwf/eDRobGQ5vJ7a/5DJxwZPt3ixsuTtakhlFYVOENj8x5Ik9F2NA8qlRy9zzi5jvkF4hPjSb04N7GxLWNDCNwdIdUTOMsFhaXkm7o7Z5JIA8NJbqPpan/05SCr92x8TD6UAiMpyQc1eb+JbReh2q4lISF2LBn05166VU+HdLmg= 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=WAs1oex0; arc=none smtp.client-ip=17.58.6.47 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="WAs1oex0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519664; bh=vWvPGu251oYkL+PTVEWgGIZl7f0hmGMZGCDwAIm43uc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=WAs1oex0c+Y78h6SmNmO5co6vwP+jQkLG+ugKTnU/0AYwjHcJfYrvoUcq2U/6xbHO x1JUdPWeTYsiqlf1PK6843DP09jSgl4ViTWB7UkgWQC6QD4xVJ1DluZxQCr7wk1nX2 noDRKempXMpKHrHErWExO/78F+C+1b1rCN/92FLE0+Pvgp0qdYkujPp7Ls61ufKtVq WieY8/XiVJa4kAzNGEfD1Gss8pIUjyY+jCcw69B3oP160143IgVSE9tzKSckEzL3RX eVZQSmAsBRixa6wnFT8GVCPIzD/phS9bMeSQMr6QJR2EJB6osfEpeZYEnqf+0Qb8cK Tt1CwHuDB/mRw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 07AFC8E00B3; Sat, 2 Nov 2024 03:54:13 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:43 +0800 Subject: [PATCH v4 1/6] phy: core: Fix that API devm_phy_put() fails to release the phy 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: <20241102-phy_core_fix-v4-1-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: VBFZYkbd-yy1qVXFeyW1gt5AEzHJi56C X-Proofpoint-GUID: VBFZYkbd-yy1qVXFeyW1gt5AEzHJi56C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 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 Reviewed-by: Johan Hovold --- drivers/phy/phy-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index f053b525ccff..f190d7126613 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -737,7 +737,7 @@ void devm_phy_put(struct device *dev, struct phy *phy) if (!phy) return; =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 Sun Nov 24 19:42:27 2024 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 7D1AD184F for ; Sat, 2 Nov 2024 03:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519676; cv=none; b=Pf8luORsPmW3g1qCza3TmkdwwEjNXjRSwm6g2yyH/odcXRZclYSZ1d43Va9LbJqMyXCmrzRuEWHHDs1ut+/rMezhkSNH/3+TzWYkiDt8A8/nlRD/4szZIrgz/yqOsG4KG9FbZXSNXo0Yli/jDQSrq6VemzpAJ1qdhgeGh5LGPGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519676; c=relaxed/simple; bh=nGsaVSj3Or+PJCrL5rwS3AkSAQW59whRTC5OEgG+xXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tABtTr495KF280d2eTQYJ4RqMiXMYMs8KaVZGJS0NxMdEH9TyQhgDDv2G3ElDgzeVeJW7e2isX98mgU6gx6jh4h+SViA4czEXht5f60XEh+ZHeUFJWGvcOkUAidj/cmMSV+JO0V9TSVdbUAonZS+4zZG0GtVU2diZTlqTHXR3NM= 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=DocaVHfO; arc=none smtp.client-ip=17.58.6.47 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="DocaVHfO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519675; bh=4SuEXx9ddfkxQj1AQp57UC2HOKADg1X3Q4LCag85EnU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=DocaVHfO48ZC2WeKzMcfBg2iCGiSqgW0XDpiX9LMRvlQb4DCtfJ8Y3b8wgA6KiKln oF20A+VL8HenjW5fMmIvWmhzjN0+NNX25tlpZTFxtRsxucsli+zSY490xvaKhlkR72 Oa+7+cudXbSAuFNAPQbXDFxWePKsF+t1TzJ52rclDHBDX+10QogNuHgxuWIa6wZle6 xS+i25hgkNzasqzvNTCfuhlMT/W1PrXNWm6Oc5r3A/jY8Qq1XU8owwgj40TrOrQhFZ h8U0j778gE9Zg+uv7s2RH1/AvKLakhzAamFiQTTG2s9U1tlf4ls1lj3t4+9tpq1uIU 0Nv22i6ZnG+Lw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id F08C38E001D; Sat, 2 Nov 2024 03:54:24 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:44 +0800 Subject: [PATCH v4 2/6] phy: core: Fix that API devm_of_phy_provider_unregister() fails to unregister the phy provider 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: <20241102-phy_core_fix-v4-2-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: sZ1d0MhMlAkKd3WtDVYi4Z85pp9PjKSO X-Proofpoint-GUID: sZ1d0MhMlAkKd3WtDVYi4Z85pp9PjKSO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For devm_of_phy_provider_unregister(), its comment says it needs to invoke of_phy_provider_unregister() to unregister the phy provider, but it will not actually invoke the function since devres_destroy() does not call devm_phy_provider_release(), and the missing of_phy_provider_unregister() call will case: - The phy provider fails to be unregistered. - Leak both memory and the OF node refcount. Fortunately, the faulty API has not been used by current kernel tree. Fixed by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- Why to fix the API here instead of directly deleting it? 1) it is simpler, just one line change. 2) it may be used in future. 3) ensure this restored API right if need to restore it in future after deleting. Anyone may remove such APIs separately later if he/she cares. --- drivers/phy/phy-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index f190d7126613..de07e1616b34 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1259,12 +1259,12 @@ EXPORT_SYMBOL_GPL(of_phy_provider_unregister); * of_phy_provider_unregister to unregister the phy provider. */ void devm_of_phy_provider_unregister(struct device *dev, - struct phy_provider *phy_provider) + struct phy_provider *phy_provider) { int r; =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 Sun Nov 24 19:42:27 2024 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 80CAE149C42 for ; Sat, 2 Nov 2024 03:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519687; cv=none; b=BoIb7rg7G68wjE2Pkk53GUWgH2w8AkvOhMrC1yUm/THp0DglbXx+k03xk2/sn9Vy/8E6jy7QOkjh4/gAeVwd5OkNHufY7fg/q+mS5joMS33tjgK6Wn/lTSLls08Wuf42jXuSGPJgNy8OzDcXwFPLMxxROXQHijomzRhIwhvCre4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519687; c=relaxed/simple; bh=92EGOINSOaGj1I0u/RpgR5u33MAN5rnUxszAui8+GlE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=M9lCKOuLMY+cuLTnTapGob0KnU0WyBoo9MS4ddHu29SXx5gDaWjtwWESgaa5E8IUt6cRYJ3q3Hhhl2u1PufBmRgX28SLTI7hcXmfzMcChc4WB42vANuVQHGpMa9A+RR2/g1LtPXOMfifw6hx3yU9aulYJ9FTSWCPpzQ8RbZvxok= 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=Pkkz/Tij; arc=none smtp.client-ip=17.58.6.47 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="Pkkz/Tij" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519686; bh=JH4PLE2Ueuk57jBTrJMy1byNBdSHe/p/HgNBwh/Fobs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=Pkkz/TijAgnlXHMysDyZoxIen2kUVvBkL67RqJFoSWxpHDWjuy6M+68/l30P0B0yd jNgzlGAuPB3glYvS/UkIbpyBm0n6VtzUskfICRzL476UH5DvPDnyNnu0qFch+CWbCJ XksM+UkxhxRZQeY30rIS+t4H55V1TCmtrc0cDaqBZyFvMdnemJZ9BhGnuoCAKmz21f /s25IXVV+I+QZ3J3MVuTQemcH0xbhVMn5qu4o5qW/R1Aex5yRCz4e1l54K3j8V6X1v IozOhGxENeMWWKRi13SAjpAL6yX7yLCIdwq2NqjDmaxiTWUGJd3t8SRaR/RxTz2jgI NoUH9l4CJKhtA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id E00238E01D3; Sat, 2 Nov 2024 03:54:35 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:45 +0800 Subject: [PATCH v4 3/6] phy: core: Fix that API devm_phy_destroy() fails to destroy the phy 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: <20241102-phy_core_fix-v4-3-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: GhmL4pJC9aQs-aNsLgPM7SwBPrZlx_Gt X-Proofpoint-GUID: GhmL4pJC9aQs-aNsLgPM7SwBPrZlx_Gt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu For devm_phy_destroy(), its comment says it needs to invoke phy_destroy() to destroy the phy, but it will not actually invoke the function since devres_destroy() does not call devm_phy_consume(), and the missing phy_destroy() call will case that the phy fails to be destroyed. Fortunately, the faulty API has not been used by current kernel tree. Fixed by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Signed-off-by: Zijun Hu Reviewed-by: Johan Hovold --- Why to fix the API here instead of directly deleting it? 1) it is simpler, just one line change. 2) it may be used in future. 3) ensure this restored API right if need to restore it in future after deleting. Anyone may remove such APIs separately later if he/she cares. --- drivers/phy/phy-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index de07e1616b34..52ca590a58b9 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -1121,7 +1121,7 @@ void devm_phy_destroy(struct device *dev, struct phy = *phy) { int r; =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 Sun Nov 24 19:42:27 2024 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 927CC140E34 for ; Sat, 2 Nov 2024 03:54:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519698; cv=none; b=OF254oQtVgSca8IDkWXadnCm6YxsTSJ5teoL670mXiiK6RdVH/FqrqD1tiuOBejwO9bYOcuLjQNkXPWK1y/bZG46aOLqxwmrHd1oLhBKYHHsXS2QJuBqdgIr3iRXqxQQernW4lZ6Xs3tT126kNCBYlWX2/koB4hnWFnva8XiLCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519698; c=relaxed/simple; bh=BxGlcQezFWQl4tzqPkJ+P+ewrSmqTZbTtmnndcK5vz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FeNOltuPcrHT92Lx+mf9ZRodcXwTGCLobYytsOGLVc7A2MwJV/1oF/5FGyzKIOfEvSokE5ZSmupcx3Ce/vQ8zgCmMu383DffndXVf4LHPUsoSItQLigjoM0DEgpC2KPQYskALmGVcxN/bodSFcl4q9sAWe9cIyeF1vs+Hry69ns= 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=gEE+Q0BH; arc=none smtp.client-ip=17.58.6.47 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="gEE+Q0BH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519697; bh=toeSTG1G9vSODnOMlPD25srU4vchWguh6NSK6vYSJnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=gEE+Q0BHmF3IKQcGGBCumeTFjOc551M5gvwK+Yu/S2alOeDlJzqN/ouaLOCHHcKcD xUHHi6z5C9muTKRuMsFZ63ox+2Wj7Y4T/cQRSrnXdRBAKRDtOniWl/KaUngHl+vdKx jLTSSqoMCmdodw09InlTw6CU+XIOJ4nwP89xns7p//ok48BEYlMWAyNDwXShcYMJ7R fFLg16kifKSkLFODpL69BFCm1+rw5V9Mr13icAcxDS1ExhDsqzmObWGHU1EMwB+3JU wN/2AfQUMUZ65tF7zBeOhSo1Cma3XXpAueQLsoGgdmgPOe42LyQ07Ng2YaVlxC0n/L M0pG/rkR5bokw== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id E7A938E0088; Sat, 2 Nov 2024 03:54:46 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:46 +0800 Subject: [PATCH v4 4/6] phy: core: Fix an OF node refcount leakage in _of_phy_get() 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: <20241102-phy_core_fix-v4-4-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: kcVLdLswlu9IQ1-VEEHCLvzb46GQ7BY0 X-Proofpoint-GUID: kcVLdLswlu9IQ1-VEEHCLvzb46GQ7BY0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020031 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 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 Reviewed-by: Johan Hovold --- drivers/phy/phy-core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 52ca590a58b9..3127c5d9c637 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -624,13 +624,15 @@ static struct phy *_of_phy_get(struct device_node *np= , int index) struct of_phandle_args args; =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 Sun Nov 24 19:42:27 2024 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 5959D184F for ; Sat, 2 Nov 2024 03:55:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519728; cv=none; b=ADcaJmhBVYfkTA1g+Vz4NiEoebtTTHquWbm7UsWSMwDJYV3u1nttbqtgAqWVCDBadE6Bv1KWJXpbvXiR7EuA4Gm/za40s5I08gfQ3uePjAQBxzY8Qps6AYpx6G/Cq5FwnUu1dXi1POUTw57CnvObrnHQgEIvT2bZiSJfJDo2tYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519728; c=relaxed/simple; bh=GtU76M6i2RKZjVJicBblCUDWJFIYTPUiNzBHNlGbmqM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EEAE78cPfBXtT5SnHdOZqfdvytlf/UJOcYc67WmB1fFLBEC9myRVqapgRV2J7wGSSzDy2NQIdk5n583FsQd4gAe4Jyl5ll7yB9xiIgGSqt6f0gtFsbLiV3XV0ToegudC6xGbwzhuRixLnL0n7rKwkVp/53En7m+63eX+hic8rjw= 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=XLqkagHW; arc=none smtp.client-ip=17.58.6.47 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="XLqkagHW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519726; bh=/xDAp1FMKoohjXNf6SYzu0enHw6XyaRJMqxsvwCqpAY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=XLqkagHWDgslVODtuCdwUwXOZWM1RDuXiT81J+teNOc+FfQsnozA7SY1wod56mHCS EaaCsjCwvdTTQi7Fk1GJioLzrkQpfuJtdJ5vNTMkxk3vWg26D3P7/CAww0LzGKAjBt 63mKjAJRrK8SRQmOY0taxJa6HP+tsZ2lpm1XoMrMhKBpFgx1fzYXHskvs5Bedum1q9 2zi+wy4AtHNWg1owsfp5/xd3sNPgPuB/e/uhW9Tb8Gm2SuvABMKZis6lqS4WY03yu7 jc4lFUiz/t2QAIIOztMHFzQJuZ25M1122f8I7SH+r0l+wKt9481JjVGtTZhEaKP4pb FAWC+kZ11xsjQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id 167B88E025C; Sat, 2 Nov 2024 03:54:57 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:47 +0800 Subject: [PATCH v4 5/6] phy: core: Fix an OF node refcount leakage in of_phy_provider_lookup() 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: <20241102-phy_core_fix-v4-5-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu , Johan Hovold X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: DYGZfXmOFcG85eyxohgP_TfPVQasc3AF X-Proofpoint-GUID: DYGZfXmOFcG85eyxohgP_TfPVQasc3AF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020032 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 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 Sun Nov 24 19:42:27 2024 Received: from pv50p00im-zteg10021401.me.com (pv50p00im-zteg10021401.me.com [17.58.6.47]) (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 D0ED1184F for ; Sat, 2 Nov 2024 03:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519740; cv=none; b=oc4rYWwVOOULH3YuQgMxTgBwBiW+P3usFTqGTP1Jt0YB0Cmifio5x81FJu2XI/lQYYEGwzXbgs3jsFtLqlQ/kx3YPQMo9WyDTzZSJNZ91Fo23mYWiLU7MP2hATWNDro//nxAtxDdmDFdTNBDiMhTkmiFxad955ZCvy78Wmt9ztM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730519740; c=relaxed/simple; bh=zi+AC3aNmGewTjTQMimffXRimaWmbxs2lSQyYUeplow=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MxD3BPBsao6orjyQnppmrG+6BVrsSF1M6wS/05puX/n5Eif1GyisYTa21aA0Nvz62//aGXM5ZdlA7EpgF1+tgoXAZpprs0pRZScm4RofHDXs7/F1iNjGnGOGXtCDUurQbAW4GLgokm+jYzX2oEtmYF+eg+7JQG1x8rg3osdKSwU= 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=COvujrbR; arc=none smtp.client-ip=17.58.6.47 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="COvujrbR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730519738; bh=06XEXE3RdGyDqIVZgj7Hd7CzsKtHn4L7U6k0cu73Blg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=COvujrbRwoQZyFJcH82UdPbs47EQ+luVL7mkAfhryXRBczX/QWQRmgDECixzcxqRo 1SlWhQeNOrCeNJ3hHTep0rEWseWyK79yQpNXSn0jj//D6IpsS8rFdg0WnNNRFWl/Ti Wct4fUKlINGdKRZzpsT1i6P7ztYIEEw7LyfCqy934fKFffDVEWZlrJ4ivYDWwJ/AN4 LOfTS9tpSD0THAr0q87ppBFNJF19WkiugENQPD1MSAeYZSB/XnTR60T1Ap00I6G/G9 HKgPOB5d3maht5SBOo82ePwGiz/lIPG8I+pqrdwrn6MMPvM6R0WbmqVe1WClcm6kqG hbQLd5tYdvv5g== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-zteg10021401.me.com (Postfix) with ESMTPSA id A67858E01B7; Sat, 2 Nov 2024 03:55:27 +0000 (UTC) From: Zijun Hu Date: Sat, 02 Nov 2024 11:53:48 +0800 Subject: [PATCH v4 6/6] phy: core: Simplify API of_phy_simple_xlate() implementation 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: <20241102-phy_core_fix-v4-6-4f06439f61b1@quicinc.com> References: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> In-Reply-To: <20241102-phy_core_fix-v4-0-4f06439f61b1@quicinc.com> To: Vinod Koul , Kishon Vijay Abraham I , Felipe Balbi , Greg Kroah-Hartman , Rob Herring , Arnd Bergmann , Lee Jones Cc: Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christophe JAILLET , Johan Hovold , Zijun Hu , stable@vger.kernel.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, Zijun Hu X-Mailer: b4 0.14.1 X-Proofpoint-ORIG-GUID: QuSC-0nx-vVo5COz6hbbnQz0mp8EobP4 X-Proofpoint-GUID: QuSC-0nx-vVo5COz6hbbnQz0mp8EobP4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-02_02,2024-11-01_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411020032 X-Apple-Remote-Links: v=1;h=KCk=;charset=UTF-8 From: Zijun Hu Simplify of_phy_simple_xlate() implementation by API class_find_device_by_of_node(). Also correct comments to mark its parameter @dev as unused instead of @args in passing. Signed-off-by: Zijun Hu --- drivers/phy/phy-core.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 9d4cc64a0865..39476ca9e51c 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -749,8 +749,8 @@ EXPORT_SYMBOL_GPL(devm_phy_put); =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