From nobody Mon Nov 25 19:24:19 2024 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) (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 2B52F1D5ACC for ; Thu, 24 Oct 2024 14:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780818; cv=none; b=DcNPwmIYe0TA+il//0eKxB4zeCxSJVgDzIyUvPzcIx3l3I7CVSdru/Rr9QedY7fBOD3NnYrd+i3fzuvmeRsRRzs1Kkj6ehyIreqFOofpNcAPIXDhvBi4kiJLZ/Mailcdzjk0j2AZbRabnTw6yunhsCi6sbhH4SLRo3+CJ73rHfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780818; c=relaxed/simple; bh=WpXDbUcLp8BNJZMyUqge5I4iIRsA5NefSWyZ0hHkrS8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XKy61/Hq30TkaZiNsFO5dtlW6YI5KCnqgWGJC0dMYZ5p+F6P75qfqGVVOGHN5KQde4yp3qWXRofYMtVxSVRUFydOtQnBLYXsMSJlhS9mTfvb4dbp5h+tVgxZqjObXkFhP4Tj3u+fAFgWlhr4Sbjw8LvfMjmgkWZVOA+tyxqv/kQ= 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=S6zLwyqN; arc=none smtp.client-ip=17.58.6.43 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="S6zLwyqN" 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 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: <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=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 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 =3D 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=C5=84ski" 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; =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 19:24:19 2024 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) (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 1DBAE1E3DE6 for ; Thu, 24 Oct 2024 14:40:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780825; cv=none; b=Lsn9Y+p1NaphFP5y4bxtxd59F+n70dtqoAUrHncJhC0kK7yTCXMgET7nLMFeeW+mLidkem5Q0idhq/ovEd2F0sa1SYkAPa/0AA9s9xFc6AnZwK9xDwQErMTcNhcjqQsRpxti6zcAyXo5aEBBqhVuAu3piSDekIoQAo3ByyUoiNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780825; c=relaxed/simple; bh=SH2TfzmkIKDBwZDqoeZ5RlnHmwfu/b81MmWMuPbS9K0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PkEyAv8D48j4lcYVKKt8AWkQc8yfW9m3e55LNBp/PZEDlpJqA9WsiA14072izKbaWFW4Ni+bF63eqIkcN08OBkFt2ARu1iYORAmwXzOT1gR3Oil8nNcVbOlmbJpn9Iaj6aUu8UTuy0HBxrHejIGjSTQs28A4C8UXoqhSpyf0JQw= 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=k426lwDD; arc=none smtp.client-ip=17.58.6.43 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="k426lwDD" 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 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: <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=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 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; =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 19:24:19 2024 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) (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 6BEBC1E32C4 for ; Thu, 24 Oct 2024 14:40:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780833; cv=none; b=SiPwk4r13OEs8Z7VyCV4820mb26gODTcCtH5UdtiOJXC6J8aL+FoJ1ZVUZRPm3kDIygCzG3qmsQzbi0h813+0+UzxWtP7uV2hcSJUSU8Xi6zzHFTRbZrO+MDKRazg0zYUTznGGS4RuWK4cQt5ARNLe4nyV9naL4UAXwCLO45iTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780833; c=relaxed/simple; bh=KuC8QJgWMDP0M0UYhUaMvuor1BX/HMv6T/muqE5kB7A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FU1FhqYj9KCMTu9ihIr69TPf4oY9S+SMyCir+7kP8CB5d8QHO+NBRfUICspiiMjNDoNKqVvymC8LcrJXAImCVOzL9Z78xc71vspWPNMmUwNI9yfKO5ewsIb+0j+5vmjRXxBzuksLKcEMRuFXq2bIVxMbTFkN2SJuzIFqyIpYpl0= 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=0cta08Hk; arc=none smtp.client-ip=17.58.6.43 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="0cta08Hk" 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 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: <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=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 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; =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 19:24:19 2024 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) (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 CFD2B1E570C for ; Thu, 24 Oct 2024 14:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780840; cv=none; b=nsYrI0BfNlnNJL2s2S5Ecawz3x0mY0B+0pdz2bTX6KZ0vdBkmnjH/JUz5EuldkwKhDTpGLLpImeErzfR0/Kh3B4J+SivRzumwmHCv80h8ctNJkIimnsnVgkWSQ35UaRQ9UYgZkSJVrPORyjglescx6fQJAh8Zr+wsjjbEuPeBtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780840; c=relaxed/simple; bh=Z6xTQmbM5bDzK6tXlwcDv8PR4b6kBhxB2kA1wRjXxiY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nUL8ASPApHe4gOuFYV1eVMa3Im+RK3HB6LUfj2EBhn/mXNkkNAqO04blssieKWKea6km82Xkuj76Z2vh2QGiVi14MCtLzKvG8vFfWFHqtXQQcOjlmwuWXj3LJohi7NX1f+BwOV15v2JHPncD6omjS0wFwE9wvFPjjT2+f4DRez0= 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=0+NSNjFn; arc=none smtp.client-ip=17.58.6.43 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="0+NSNjFn" 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() 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: <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=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 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 d= evices") 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); =20 /* 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); + } =20 mutex_lock(&phy_provider_mutex); phy_provider =3D of_phy_provider_lookup(args.np); --=20 2.34.1 From nobody Mon Nov 25 19:24:19 2024 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) (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 3B4591EC013 for ; Thu, 24 Oct 2024 14:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780849; cv=none; b=RGuAhOXLMW2Kv+lSGgvc1At1/iX1E5d6Pqu+HHwb6Z8cBm8xlVgPko7PVTvO57TGF9joFJF0d6Q2czDFxf7OkPhw9oICZtp2kRb7ikFp4M0SQmvYqNBX2koLsxbUUFiAXigqAZyKY2Tx04KbKPeZslS/95JmK+ntckAXWYryI24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780849; c=relaxed/simple; bh=iZKDw8ZYl2r+PnmmzzqcjTPuBPeYAfMiAPoDOy7IBj0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lGsWwDTBjFQSajUXZMW1AOF2WrtAaObwrPk8XTI+GDI7iFpw33khbuxsBBfUzTNotICllkekSeQpXaPnrhJssGJCUpfVi4mqVTVAeYuZ5a3TGFeO/AStM6a9cEvlv2ZXmam7/0qmvRpTVSL5k/5RNig6PHP4gzro4oURkRcnLPY= 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=puj7eOkv; arc=none smtp.client-ip=17.58.6.43 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="puj7eOkv" 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() 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: <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=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 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 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(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 19:24:19 2024 Received: from pv50p00im-hyfv10011601.me.com (pv50p00im-hyfv10011601.me.com [17.58.6.43]) (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 50BDD1E7664 for ; Thu, 24 Oct 2024 14:40:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780856; cv=none; b=tri85WnKQD9C/okaNvDD/Hca6OFDNEQ/TZ1HwWOGv9Vl+5MpcRVh7exu5t4cwqeebmVguzlmtUruKc+RgpUlP8gayFflYoqQx0gagBJl73s3IVq8qnXxLGNUrT5EU2YNV1V1BfmncWIr5hdlGniM7e79icsY6fIa3FSUrnvzytM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729780856; c=relaxed/simple; bh=MJbrB7W8kX/cyQEalTTmjsZNEab1KL1hzlNY1ejl9U8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l08MkbZWBlO5/WRsRqHfsB7ntjXpWB1J23EJMJ2TsaL8iPyMikcej7scc8iQwcHD5WVTQkaldmzniOW7PlCHUi+HPgZcIoH5gRJcH7tHm9lQF/JiaSoLrvP8eIjwLotZRCcJqnW0pb/UTR4NvlgJhWP67klZ+ygqCQAzDElGy6Q= 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=hYcgBkly; arc=none smtp.client-ip=17.58.6.43 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="hYcgBkly" 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 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: <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=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 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); =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