From nobody Mon May 25 05:56:33 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 68F982D2385 for ; Mon, 18 May 2026 02:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779070559; cv=none; b=Mge0NNt/gwdCfAnbB8GtGDEB2hyWwYRfoR46klUKi8/EaspgZQkNKVRVFqDZY4klkpe9eR8+rpvm/uQMyjvqjMWwQVsY1ldkJrnTTEvTvLXtxFuFEtvF1CYqb8qel3+7fJ2CLV/l66yz00b92io+Xtg3w5I27FvieSEZ2tTDCgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779070559; c=relaxed/simple; bh=NbeRoqwwlkJZ5hfSjaRZVEFeGo6f9tc66fueO8lJ0YY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b18bfIXmyVxBproCRNit60ebwkc3liLbTQ8CbrrqoNeZqR6QgsZxL08IrMGaXsFYsnl5vSIBb9wESRL+g0LGyjC5hl4HCtLvINMhxFGl5+nw0hNJESxHqaZZUgraqBnkQ6W5oBclRx5O0Oj9s/+d2u7vFWvLyFRvAMBvrtI5b7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 7a0e2f26525f11f1aa26b74ffac11d73-20260518 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:b258e95c-bcf4-47f0-8741-cd10c5537833,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7bac3a,CLOUDID:cb1f2070f5963447efb4c3d07357c0b5,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|850|865|898,TC:nil,Content:0|1 5|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI :0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 7a0e2f26525f11f1aa26b74ffac11d73-20260518 X-User: zenghongling@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1130665006; Mon, 18 May 2026 10:15:44 +0800 From: Hongling Zeng To: vkoul@kernel.org, neil.armstrong@linaro.org, johan@kernel.org, kishon@kernel.org, rogerq@ti.com Cc: linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, zhongling0719@126.com, Hongling Zeng Subject: [PATCH v4 1/2] phy: ti: pipe3: Fix clock resource leak on probe errors Date: Mon, 18 May 2026 10:15:38 +0800 Message-Id: <20260518021539.14890-2-zenghongling@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260518021539.14890-1-zenghongling@kylinos.cn> References: <20260518021539.14890-1-zenghongling@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When devm_phy_create() or devm_of_phy_provider_register() fails, the refclk that was enabled earlier is not disabled, causing a resource leak. Fix this by adding an error handling path to disable the clock when these functions fail. Fixes: 234738ea3390 ("phy: ti-pipe3: move clk initialization to a separate = function") Signed-off-by: Hongling Zeng --- Change in v2: -Add pm_runtime_disable() in error path (reported by Sashiko AI). --- change in v3: -Fix unbalanced clock disable by checking clk_prepare_enable()return valu= e and setting sata_refclk_enabledonly on success. -Fix error path teardown order to match ti_pipe3_remove()(disable clock b= efore disabling runtime PM). --- change in v4: -Fix the patch version --- drivers/phy/ti/phy-ti-pipe3.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c index b5543b5c674c..58fbc3b27813 100644 --- a/drivers/phy/ti/phy-ti-pipe3.c +++ b/drivers/phy/ti/phy-ti-pipe3.c @@ -831,21 +831,39 @@ static int ti_pipe3_probe(struct platform_device *pde= v) */ if (phy->mode =3D=3D PIPE3_MODE_SATA) { if (!IS_ERR(phy->refclk)) { - clk_prepare_enable(phy->refclk); + ret =3D clk_prepare_enable(phy->refclk); + if (ret) { + dev_err(dev, "Failed to enable refclk %d\n", ret); + goto err_pm_disable; + } phy->sata_refclk_enabled =3D true; } } =20 generic_phy =3D devm_phy_create(dev, NULL, &ops); - if (IS_ERR(generic_phy)) - return PTR_ERR(generic_phy); + if (IS_ERR(generic_phy)) { + ret =3D PTR_ERR(generic_phy); + goto err_clk_disable; + } =20 phy_set_drvdata(generic_phy, phy); =20 ti_pipe3_power_off(generic_phy); =20 phy_provider =3D devm_of_phy_provider_register(dev, of_phy_simple_xlate); - return PTR_ERR_OR_ZERO(phy_provider); + if (IS_ERR(phy_provider)) { + ret =3D PTR_ERR(phy_provider); + goto err_clk_disable; + } + + return 0; + +err_clk_disable: + if (phy->sata_refclk_enabled && !IS_ERR(phy->refclk)) + clk_disable_unprepare(phy->refclk); +err_pm_disable: + pm_runtime_disable(dev); + return ret; } =20 static void ti_pipe3_remove(struct platform_device *pdev) --=20 2.25.1 From nobody Mon May 25 05:56:33 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 62B81299948 for ; Mon, 18 May 2026 02:15:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779070560; cv=none; b=XoRvbYuBy4A3wDJCi8QubhLzUmWMW6EOHiCI9YSLomEa+XFrYAowC0EWpjWa6mHM9jJCbwDqo1vzTtzNx5ClSF5zPzM24rd9ktyodNoPcD5VaE00EHTkj91Dwyx8QfWaNUm/eZHN/R5UhpVbiccwkctXp6TFIkxg4XmPPFVuzP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779070560; c=relaxed/simple; bh=TdNIpUj/DPHUEE29Hb6wMxNsXJmHQbzTj2IMhbjA5Ek=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Fy7pvZkeEL/EZGiT2JXzM5QmKHoSLL/rBG8aiULG0bcaGVP9/i9zS5OhO1GzW6pkXeAvPQ99Kcs/iL5N4CMC1REpzHkszOPcZkRE2gMtgEd/Um9Y+3Od38FSGNaGL3qUwRbbcRRT8ahqUxgMCCrAu1E3xxfxqUvhrBFe/n+ZWm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 7a6e504a525f11f1aa26b74ffac11d73-20260518 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:9e5aced4-2f41-4ee2-b7e8-3b9d26e509d0,IP:0,U RL:0,TC:0,Content:0,EDM:-25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:e7bac3a,CLOUDID:273f3d18aae427d7b845cd55aae378d7,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|850|865|898,TC:nil,Content:0|1 5|50,EDM:2,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI: 0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 7a6e504a525f11f1aa26b74ffac11d73-20260518 X-User: zenghongling@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1563261354; Mon, 18 May 2026 10:15:45 +0800 From: Hongling Zeng To: vkoul@kernel.org, neil.armstrong@linaro.org, johan@kernel.org, kishon@kernel.org, rogerq@ti.com Cc: linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, zhongling0719@126.com, Hongling Zeng Subject: [PATCH v4 2/2] phy: ti-pipe3: Fix EPROBE_DEFER handling for clock resources Date: Mon, 18 May 2026 10:15:39 +0800 Message-Id: <20260518021539.14890-3-zenghongling@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260518021539.14890-1-zenghongling@kylinos.cn> References: <20260518021539.14890-1-zenghongling@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ti_pipe3_get_clk() has two issues with -EPROBE_DEFER error handling: 1. When devm_clk_get() for sysclk fails, the function returns -EINVAL instead of propagating the actual error code. This masks -EPROBE_DEFER to -EINVAL, breaking the probe deferral mechanism and causing permanent driver initialization failure on systems with non-deterministic probe ordering. 2. For SATA PHY refclk, the function ignores all errors to support older DTBs missing the refclk property. However, this incorrectly ignores -EPROBE_DEFER as well, causing the driver to proceed without waiting for the clock provider to become available. Fix both issues: - Return PTR_ERR(phy->sys_clk) instead of -EINVAL to propagate all error codes including -EPROBE_DEFER - For SATA refclk, only ignore -ENOENT (clock not found in old DTBs) but propagate other errors like -EPROBE_DEFER Fixes: a70143bbef6b ("drivers: phy: usb3/pipe3: Adapt pipe3 driver to Gener= ic PHY Framework") Fixes: 7f33912d2978 ("phy: ti-pipe3: Fix SATA across suspend/resume") Signed-off-by: Hongling Zeng --- Change in v4: - Merge refclk leak fix and EPROBE_DEFER fix into a single patch - Use devm_clk_get_optional() for SATA refclk - Drop manual -ENOENT handling - Ensure error paths are fully symmetric --- drivers/phy/ti/phy-ti-pipe3.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c index 58fbc3b27813..e0ab7d21e99c 100644 --- a/drivers/phy/ti/phy-ti-pipe3.c +++ b/drivers/phy/ti/phy-ti-pipe3.c @@ -605,14 +605,21 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy) struct clk *clk; struct device *dev =3D phy->dev; =20 - phy->refclk =3D devm_clk_get(dev, "refclk"); + /* + * refclk is optional for SATA PHY to support older DTBs, but + * required for other modes. Use devm_clk_get_optional() for SATA + * which returns NULL for -ENOENT, allowing us to propagate all + * other errors including -EPROBE_DEFER. + */ + if (phy->mode =3D=3D PIPE3_MODE_SATA) { + phy->refclk =3D devm_clk_get_optional(dev, "refclk"); + } else { + phy->refclk =3D devm_clk_get(dev, "refclk"); + } + if (IS_ERR(phy->refclk)) { dev_err(dev, "unable to get refclk\n"); - /* older DTBs have missing refclk in SATA PHY - * so don't bail out in case of SATA PHY. - */ - if (phy->mode !=3D PIPE3_MODE_SATA) - return PTR_ERR(phy->refclk); + return PTR_ERR(phy->refclk); } =20 if (phy->mode !=3D PIPE3_MODE_SATA) { @@ -629,7 +636,7 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy) phy->sys_clk =3D devm_clk_get(dev, "sysclk"); if (IS_ERR(phy->sys_clk)) { dev_err(dev, "unable to get sysclk\n"); - return -EINVAL; + return PTR_ERR(phy->sys_clk); } } =20 --=20 2.25.1