From nobody Sun Nov 24 10:28:31 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