From nobody Sun Nov 24 07:57:07 2024 Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (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 CD9C42040BC for ; Wed, 6 Nov 2024 15:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907033; cv=none; b=rCTuQ96KodQOTXFXynRALEVFxMKmcGkKV+68kSfjNpXDKLWAaqyRz2++5wAjcuSJHVwjnRkHrV4M/RSIPVFeQh24um/f5CV8Q5/tJJnGawuL1bUI+aZI+Ja7bdYgI9ejp8Y9bk4skg8hWIG1REMHV/Ui2IcBDMXHpr/McvRI24M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907033; c=relaxed/simple; bh=wwDfRWsTVlrhRLH69VGr+sb/QwDgl0FjovU747cZaeI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AI5i1iYWRBfX5RkERPG1PFLgIKhma0nreA1flImHTNrtnlh6r1IjbSe66wiPS4oaMMCTYJggGU8kiy2+Va/sDsGXkchNArBfHGiOJE8KeNR8PSdvFQCXAW7wF8XyjnO+fBzS9Yv6kTNrxdZpyUcYmJsbSroRq0AP6aNqXZnkYwA= 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=WgqbqTBV; arc=none smtp.client-ip=17.58.6.54 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="WgqbqTBV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907030; bh=kDM9n2NzpCZMaLluXurrrPauvVeEV4qNGscAtK/f3Ro=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=WgqbqTBVkqLitSjHYLzgA2GLsBcXYfyyxfc2JrCtbMkzxq/3gUhZPT+1IQqxcy0ok 591DgJEO6PQftAlCSzJXT+LsbgarJq/9xwEW2YhPhano9Y5ZxEGyE1NUO3ovfKg2+C AWNI6BhBfB4BfMZJcOOawPyXOIIanZHfZu8eRsESvTMydxiiY4S67/QYwXunvfmmfP oGPYpQOfruNZnF0fE0aqH5kSwWRlsUDcH2BzY/Ie6vbvroYmhgsyPwlfi6mY1GvlnS 57t1stMQvmEt4D/PvTPdaURtGRZZzmcwOuIWw3rSDop/nkYU4v7DmS121ER01pFePO 1i8+sjENfGw+w== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 2EEDA3A0A01; Wed, 6 Nov 2024 15:30:17 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:17 +0800 Subject: [PATCH v5 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: <20241106-phy_core_fix-v5-1-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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: 396FS2ilzy-__07h64kBH5Fxkcc1YkYA X-Proofpoint-ORIG-GUID: 396FS2ilzy-__07h64kBH5Fxkcc1YkYA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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 Fix 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 Reviewed-by: 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 Sun Nov 24 07:57:07 2024 Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (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 71F05205E3C for ; Wed, 6 Nov 2024 15:30:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907047; cv=none; b=WKKm5mQOaQ0YANAGIn+7RfNo32wEm00OlFMA8Wis+EyTXcIi6BWbtpQjjUNPL7L7Vxj9LRUnJTd+eDn408ePOmV2Dd3e8sfP7mH4kD3J0EyrFyMx2FHPc8QlKcq0yZlCganrUWUyowxPpLU/U/2ElU9aA4XvJayxrF3Z3Oclj6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907047; c=relaxed/simple; bh=e+5tyiIv6i+hgfNoVziztpZSHlPmcFBE3iRiUB8RuCM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d/nBPT4rPIg2LzyQzfDN/B+7E34DEPUqnBiBkVc8vTcbc6/aeX9pOtbrcAJAVd3PdFasAq7J2etxRn9wnsAetM38uFHbN8WG2Cg+ncBq4cmVNfPCScFYX1r2tA3eq4OqqDGAvr6072tI7BrV6pVJrXKuBIPXr6DgNjCQmYjJniw= 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=OQdkFHav; arc=none smtp.client-ip=17.58.6.54 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="OQdkFHav" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907043; bh=gXDaTlvtbcQ4620sn7VJl7LM/l6KBZAqPN7GJEoSAS8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=OQdkFHavbijUZ6V8LHAtiMh29xd7nim3WmVzvCjFV/Wrlrfmgo65eNWhaRrAVaisK 1D7Gh2OqyJUcUOXl24buofAk+jjlhA/AQBCO05V/R4Z4ZF7t/4VUhOXpw5au6i4+JK MTQoi57NQJEr+c02xQ9A5bwO6SsFHAcJsnNwF76bC9ibJLjdgdt/LG232TddxHtmhH t/lEBFpMq4NnW/BKTm3LKUHwZKAUOrEoquvyaajqsJ0Yprgu2bFQjcBv4Q7RiRz1ys Yq+uN3CgDo+A2apU9LiUin3G5TGAQ0237IB3AA9l+2YSqnrooKcBt2/kEGWZvfwP/q aHksR9Yx9y2sQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 3EE9F3A10F1; Wed, 6 Nov 2024 15:30:30 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:18 +0800 Subject: [PATCH v5 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: <20241106-phy_core_fix-v5-2-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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: NkVSiluEF-TtD-WFLQjJ3KQtdcwT94VZ X-Proofpoint-ORIG-GUID: NkVSiluEF-TtD-WFLQjJ3KQtdcwT94VZ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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 cause: - 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. Fix by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Reviewed-by: Johan Hovold 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 Sun Nov 24 07:57:07 2024 Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (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 1C45A202628 for ; Wed, 6 Nov 2024 15:30:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907060; cv=none; b=rJc7+90/Y7ErK0b5CfOr2xW+CRT2y3Q0tK96zH4bOokq0zdFyD//d/+VVQniO7Y/FpRVKSPJqzWhTxXqZA04HuY+YuaA71dapZQOXoLSF+IQLjIih1KQWVhLWP4JPBGMVfA+IyB/8Vq6krHk2K7X4fONnJyievVzTMFOs92PMbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907060; c=relaxed/simple; bh=1KhAN6Up8LvxWkGYnnnz9w9v3VZ1k1LEOJafT0KomhU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uw50iq2lt2bsk/7pUPynXXESWm+fY6dgcyPm2NWOIIlJZhaN7hEfeEQPuATCMlwDNRZe8vDlwG6j/AGE26B3N/Owt2Jb4XAE0DJAQIC8e1ZA9WYb47rPNyDLuP0FTwkLPn7UuJiVKx5iWU8cYyXmSAyDT1HpX+Tb1XvT2ffVp0Y= 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=fr3HZQ01; arc=none smtp.client-ip=17.58.6.54 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="fr3HZQ01" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907058; bh=D4p/ONPwsChgPFkyQAZ67fVmHAM1m6iVzlq7cFn+C6Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=fr3HZQ017dFCBGKqttkIsUH2i3owsFsG+7gLZMNXsBYZ6xXhGy1yl47UdUlea9o+i SS97zM/WqTgmQyJdYA4IcPffxaBC4vYN+GBtVGU3Jg9XE0zQvBN/vCenJA+Vko+3NL nAhSmKNpW7tRrvaj56rNGr/Y0EOILd6vBAs9D+vq6DohmC+aCalDqYasiRYoKlxuM+ oXQ7mBd/49q5AoyJP342heXsninLXoChVvECmbwtfEU+uH1LmtkjqxFILH2LOPK4He OAzdE5i63FqwQIoXdL8v8V/WLDXVefW2vQBikf6ZrQ2oG6Im/XZvIwTiJPd0Bk3gv6 LvNNbV7npFOEQ== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id A9D853A1115; Wed, 6 Nov 2024 15:30:46 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:19 +0800 Subject: [PATCH v5 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: <20241106-phy_core_fix-v5-3-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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: IspyCmIlreuz43qiXRwdWu5eepWx8eoK X-Proofpoint-ORIG-GUID: IspyCmIlreuz43qiXRwdWu5eepWx8eoK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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 cause that the phy fails to be destroyed. Fortunately, the faulty API has not been used by current kernel tree. Fix by using devres_release() instead of devres_destroy() within the API. Fixes: ff764963479a ("drivers: phy: add generic PHY framework") Cc: stable@vger.kernel.org Reviewed-by: Johan Hovold 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 Sun Nov 24 07:57:07 2024 Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (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 EF8E320408D for ; Wed, 6 Nov 2024 15:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907073; cv=none; b=NcfrX2sychLas1+L6ux7Al1RPozsCWksEld9UprUezA/ze8iBjae1eLsmfFOP69AFIIk1esJ2ljXJOaaauezRan+t8aigZa/OPZtwnu0vEYRqX7aRbA4Kn5KG3eJKqpn9CcdNQY0752dUDlhOn9UKrMVFHOPHageV34pY1dwBLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907073; c=relaxed/simple; bh=1FZpCdVnTqeQowpVcN/DVZ5XI+WsghCG8934Yyo6w0s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lQbZcAM/4UKrfIfxDjutd8qtxQ3tSmKNZn3J8IIwGanWKzq/cXcI5TpAGmfhQQuLmCdERbaTF91dYs/2A5rony+MWBTFeY3Cbo/Sg5DsYUGIsR+UUSCcY6ZYVQDWuWthW3XcEyxH8lGMNx5li1MV0nEKzah7Al0ZrE3YQoXCHHg= 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=W6/p8tBj; arc=none smtp.client-ip=17.58.6.54 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="W6/p8tBj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907071; bh=jRJAq6X1q0kmcyUpWLUZ36Ko6dovwQNaa0R6U7y4YOE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=W6/p8tBjL9AUAg9Podk7POQ5vLnNEo8ef1bFmoIF4j/vVQSo+5kv7MbvN1ePRcSEO sS5DYAU24u6IHuprUqLj+ZI8tCcRHDbkwdFlyuQgBnowvYcncNrroBPrVm2FFmbdhp +5cpCuEE15Q1h81E8oUZGdTZr/0CjDSl5O/d9jxOi8bymvPuuYhjddbBz71lYHNbmy HFsFINDT5t04LvUtkSHEe0tj0UK7J6VK5vmQu6z0+liT9S6SgiSycocnTPmZSDIhGE LeFTe3cyw9z85whLCp5wNbhaV2CDSDQZlVn2zr1iww2D+5jopHeK89hII95xfvEIvi HGQzJ9NZV+tdA== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 9C3063A10BF; Wed, 6 Nov 2024 15:30:59 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:20 +0800 Subject: [PATCH v5 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: <20241106-phy_core_fix-v5-4-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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: XhTcyP6hSKb-9YGDWtkqgALci_WdNh6U X-Proofpoint-ORIG-GUID: XhTcyP6hSKb-9YGDWtkqgALci_WdNh6U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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 Reviewed-by: Johan Hovold Signed-off-by: Zijun Hu --- drivers/phy/phy-core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 52ca590a58b9..b88fbda6c046 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -629,8 +629,10 @@ 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")) - 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 07:57:07 2024 Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (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 CF4D62038DF for ; Wed, 6 Nov 2024 15:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907086; cv=none; b=rdEaceb2MjG4dPk4X+aB2o5gy1bA9dd+3+bqVvq+uYKZHf97yfDuBHhR0KlH2UWmpTKWXWz+g9dGH3VKKWIP3OaNbExigHPBgdlhrhj6vJr8IOfcqPczvfmjCLXOeb/Wy4Eno62bnsq2nqUh3+2XyHGr55cYxQ+LIdMFMrc5P8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907086; c=relaxed/simple; bh=n1clbFDxKveXazVTIlX8rYcw1NpLYuAEBm5zoMt1+oU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rL6f1K7VaxUXow29JckgdryXqkxaTXuy1Ikb1s8al5to78pXVXKazjj8Aih+Orl1QKdaTfx9XKIHA0zE1zLu/OUdMH/sLaLCDmcayh05ofM8Ikkx6JepYUoGQXCdJlLaqItmp5Alo0diKUrhHrpnJFB20AoOrfIOSXSn44dEHqw= 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=E+MspX7W; arc=none smtp.client-ip=17.58.6.54 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="E+MspX7W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907084; bh=vn7YLlTMs35v/+bzgOIOZMQXRYeYPFiSPDi8rm2sJcM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=E+MspX7WdtzMGksSBtYzuCb3l2CAHvMSFZM2LLyF+T3joqiOZ/rDl5PlWfxbRUHvS oP5y/QQjPOVahyAoGRYDaALJoRVazqjCd+A5jcOmlL7eybgY20DgPeN0WeYqMvXdn/ eYasYgV5yfNSbMUVUOqRPdyGDDPqexbJRUYI5X7zyYm1tcttn23HUU+FgeCta6GFOd JA1reKNHhUiveMC6c5AK+nIhRs41A9M8PysGcgRuCSqIyQSRtLAP9h7OPIG5UVU7tf D3xE01op17lutnlWIg0mn+LNRhqzdCCKGK8OXhi2+pVHrTNFH5SO5UbMg0cmVxdszF ZWunrT5nuMGNg== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 932873A0A06; Wed, 6 Nov 2024 15:31:12 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:21 +0800 Subject: [PATCH v5 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: <20241106-phy_core_fix-v5-5-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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: sPXWQqURoU3m9fe4K3pZkqREUZjSNIng X-Proofpoint-ORIG-GUID: sPXWQqURoU3m9fe4K3pZkqREUZjSNIng X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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. Fix 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 b88fbda6c046..413f76e2d174 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 07:57:07 2024 Received: from pv50p00im-tydg10021701.me.com (pv50p00im-tydg10021701.me.com [17.58.6.54]) (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 502EF2038DF for ; Wed, 6 Nov 2024 15:31:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.6.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907098; cv=none; b=jj2OcmVq0sJyk/DmEu+KToL6e33R+hYQl4SnCMXt5GEjEY786KxCAF+P93cUOeCH/EfpVd8FrXlef9hPSATI7DEFK+jxNmXsAdDjhWegSNBHCW5TK2hFXHeHb9fSIj1wDxgTuf/1k3HgqddPCukFauqFKvnBo9dW0stj6hBAx90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730907098; c=relaxed/simple; bh=gXaXARKv5b4OWg1hPek1EmKa2Ed3DJsIdKbNZu4ebFk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mBB2r8nxjzw0bcifBa1z58/ZMC4z/ZlPRW0GDCuCGJ5Xy93v6kT4ddfS1C1ZBlbHYowUEeK2XTghBROLJtGmKXvM7LFEXz5dLaJRo00ox4STKK4QK2jFX32K4aM85UQ2DNODf140a5n6B7tygOozpHePR0ltURnQGyGJSewYTVk= 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=PPNC1YMJ; arc=none smtp.client-ip=17.58.6.54 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="PPNC1YMJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1730907097; bh=SyatfIV8TYuY4KBrfs0SWiSBpZQ2QH8QB6djYTU8Jpc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To: x-icloud-hme; b=PPNC1YMJJZheWJEXr7hFXaJvYx12jTX11+AiqxIoWfpiyRDWf8b6Zn8qhDYt4W8bJ XMRxsmPdWip/GMN8wiREpHiurL8lF+Uplbd+yuEqxRqTcsMaotIb984+Oa/JNqZUF5 TD+r6kQ0fpIydMPPbAsG9kimntUytQ8vFYeGC6WgjxORjEeEFF+NqR+xhwFwmrV7RC VQ9WLC1nbi+xRwChBF4EGxbnckMqL2DgOKPdSzBgFmuI7gYDbnzfswd6o0pY97nziE WxI3LC4VDTkuYpXf1l/E156ZkweAL0gU1GYGQgSwQH6gWVWi/i3yfqGJQ2d4gr5hXk rRWJjXdOcts9A== Received: from [192.168.1.26] (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-tydg10021701.me.com (Postfix) with ESMTPSA id 77F483A10B8; Wed, 6 Nov 2024 15:31:24 +0000 (UTC) From: Zijun Hu Date: Wed, 06 Nov 2024 23:29:22 +0800 Subject: [PATCH v5 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: <20241106-phy_core_fix-v5-6-9771652eb88c@quicinc.com> References: <20241106-phy_core_fix-v5-0-9771652eb88c@quicinc.com> In-Reply-To: <20241106-phy_core_fix-v5-0-9771652eb88c@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: zwvertWuy8IcK0I14C7v_mzF4MXFQOMu X-Proofpoint-ORIG-GUID: zwvertWuy8IcK0I14C7v_mzF4MXFQOMu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-11-06_09,2024-11-06_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 phishscore=0 clxscore=1015 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2411060121 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 413f76e2d174..1dbb854672d3 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