linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] phy: fix device leaks at unbind
@ 2025-07-24 13:12 Johan Hovold
  2025-07-24 13:12 ` [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe Johan Hovold
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Johan Hovold @ 2025-07-24 13:12 UTC (permalink / raw)
  To: Vinod Koul
  Cc: JC Kuo, Kishon Vijay Abraham I, Thierry Reding, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel, Johan Hovold

This series fixes device leaks due to failure to drop the reference
taken by of_find_device_by_node().

Johan

Johan Hovold (3):
  phy: tegra: xusb: fix device and OF node leak at probe
  phy: ti: omap-usb2: fix device leak at unbind
  phy: ti-pipe3: fix device leak at unbind

 drivers/phy/tegra/xusb-tegra210.c |  6 +++++-
 drivers/phy/ti/phy-omap-usb2.c    | 13 +++++++++++++
 drivers/phy/ti/phy-ti-pipe3.c     | 13 +++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

-- 
2.49.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe
  2025-07-24 13:12 [PATCH 0/3] phy: fix device leaks at unbind Johan Hovold
@ 2025-07-24 13:12 ` Johan Hovold
  2025-08-06 14:35   ` neil.armstrong
  2025-07-24 13:12 ` [PATCH 2/3] phy: ti: omap-usb2: fix device leak at unbind Johan Hovold
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Johan Hovold @ 2025-07-24 13:12 UTC (permalink / raw)
  To: Vinod Koul
  Cc: JC Kuo, Kishon Vijay Abraham I, Thierry Reding, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel, Johan Hovold, stable

Make sure to drop the references taken to the PMC OF node and device by
of_parse_phandle() and of_find_device_by_node() during probe.

Note the holding a reference to the PMC device does not prevent the
PMC regmap from going away (e.g. if the PMC driver is unbound) so there
is no need to keep the reference.

Fixes: 2d1021487273 ("phy: tegra: xusb: Add wake/sleepwalk for Tegra210")
Cc: stable@vger.kernel.org	# 5.14
Cc: JC Kuo <jckuo@nvidia.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/phy/tegra/xusb-tegra210.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c
index ebc8a7e21a31..3409924498e9 100644
--- a/drivers/phy/tegra/xusb-tegra210.c
+++ b/drivers/phy/tegra/xusb-tegra210.c
@@ -3164,18 +3164,22 @@ tegra210_xusb_padctl_probe(struct device *dev,
 	}
 
 	pdev = of_find_device_by_node(np);
+	of_node_put(np);
 	if (!pdev) {
 		dev_warn(dev, "PMC device is not available\n");
 		goto out;
 	}
 
-	if (!platform_get_drvdata(pdev))
+	if (!platform_get_drvdata(pdev)) {
+		put_device(&pdev->dev);
 		return ERR_PTR(-EPROBE_DEFER);
+	}
 
 	padctl->regmap = dev_get_regmap(&pdev->dev, "usb_sleepwalk");
 	if (!padctl->regmap)
 		dev_info(dev, "failed to find PMC regmap\n");
 
+	put_device(&pdev->dev);
 out:
 	return &padctl->base;
 }
-- 
2.49.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] phy: ti: omap-usb2: fix device leak at unbind
  2025-07-24 13:12 [PATCH 0/3] phy: fix device leaks at unbind Johan Hovold
  2025-07-24 13:12 ` [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe Johan Hovold
@ 2025-07-24 13:12 ` Johan Hovold
  2025-07-24 13:12 ` [PATCH 3/3] phy: ti-pipe3: " Johan Hovold
  2025-08-12 16:40 ` [PATCH 0/3] phy: fix device leaks " Vinod Koul
  3 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2025-07-24 13:12 UTC (permalink / raw)
  To: Vinod Koul
  Cc: JC Kuo, Kishon Vijay Abraham I, Thierry Reding, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel, Johan Hovold, stable,
	Roger Quadros

Make sure to drop the reference to the control device taken by
of_find_device_by_node() during probe when the driver is unbound.

Fixes: 478b6c7436c2 ("usb: phy: omap-usb2: Don't use omap_get_control_dev()")
Cc: stable@vger.kernel.org	# 3.13
Cc: Roger Quadros <rogerq@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/phy/ti/phy-omap-usb2.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/phy/ti/phy-omap-usb2.c b/drivers/phy/ti/phy-omap-usb2.c
index c1a0ef979142..c444bb2530ca 100644
--- a/drivers/phy/ti/phy-omap-usb2.c
+++ b/drivers/phy/ti/phy-omap-usb2.c
@@ -363,6 +363,13 @@ static void omap_usb2_init_errata(struct omap_usb *phy)
 		phy->flags |= OMAP_USB2_DISABLE_CHRG_DET;
 }
 
+static void omap_usb2_put_device(void *_dev)
+{
+	struct device *dev = _dev;
+
+	put_device(dev);
+}
+
 static int omap_usb2_probe(struct platform_device *pdev)
 {
 	struct omap_usb	*phy;
@@ -373,6 +380,7 @@ static int omap_usb2_probe(struct platform_device *pdev)
 	struct device_node *control_node;
 	struct platform_device *control_pdev;
 	const struct usb_phy_data *phy_data;
+	int ret;
 
 	phy_data = device_get_match_data(&pdev->dev);
 	if (!phy_data)
@@ -423,6 +431,11 @@ static int omap_usb2_probe(struct platform_device *pdev)
 			return -EINVAL;
 		}
 		phy->control_dev = &control_pdev->dev;
+
+		ret = devm_add_action_or_reset(&pdev->dev, omap_usb2_put_device,
+					       phy->control_dev);
+		if (ret)
+			return ret;
 	} else {
 		if (of_property_read_u32_index(node,
 					       "syscon-phy-power", 1,
-- 
2.49.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] phy: ti-pipe3: fix device leak at unbind
  2025-07-24 13:12 [PATCH 0/3] phy: fix device leaks at unbind Johan Hovold
  2025-07-24 13:12 ` [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe Johan Hovold
  2025-07-24 13:12 ` [PATCH 2/3] phy: ti: omap-usb2: fix device leak at unbind Johan Hovold
@ 2025-07-24 13:12 ` Johan Hovold
  2025-08-12 16:40 ` [PATCH 0/3] phy: fix device leaks " Vinod Koul
  3 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2025-07-24 13:12 UTC (permalink / raw)
  To: Vinod Koul
  Cc: JC Kuo, Kishon Vijay Abraham I, Thierry Reding, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel, Johan Hovold, stable,
	Roger Quadros

Make sure to drop the reference to the control device taken by
of_find_device_by_node() during probe when the driver is unbound.

Fixes: 918ee0d21ba4 ("usb: phy: omap-usb3: Don't use omap_get_control_dev()")
Cc: stable@vger.kernel.org	# 3.13
Cc: Roger Quadros <rogerq@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/phy/ti/phy-ti-pipe3.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/phy/ti/phy-ti-pipe3.c b/drivers/phy/ti/phy-ti-pipe3.c
index da2cbacb982c..ae764d6524c9 100644
--- a/drivers/phy/ti/phy-ti-pipe3.c
+++ b/drivers/phy/ti/phy-ti-pipe3.c
@@ -667,12 +667,20 @@ static int ti_pipe3_get_clk(struct ti_pipe3 *phy)
 	return 0;
 }
 
+static void ti_pipe3_put_device(void *_dev)
+{
+	struct device *dev = _dev;
+
+	put_device(dev);
+}
+
 static int ti_pipe3_get_sysctrl(struct ti_pipe3 *phy)
 {
 	struct device *dev = phy->dev;
 	struct device_node *node = dev->of_node;
 	struct device_node *control_node;
 	struct platform_device *control_pdev;
+	int ret;
 
 	phy->phy_power_syscon = syscon_regmap_lookup_by_phandle(node,
 							"syscon-phy-power");
@@ -704,6 +712,11 @@ static int ti_pipe3_get_sysctrl(struct ti_pipe3 *phy)
 		}
 
 		phy->control_dev = &control_pdev->dev;
+
+		ret = devm_add_action_or_reset(dev, ti_pipe3_put_device,
+					       phy->control_dev);
+		if (ret)
+			return ret;
 	}
 
 	if (phy->mode == PIPE3_MODE_PCIE) {
-- 
2.49.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe
  2025-07-24 13:12 ` [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe Johan Hovold
@ 2025-08-06 14:35   ` neil.armstrong
  0 siblings, 0 replies; 6+ messages in thread
From: neil.armstrong @ 2025-08-06 14:35 UTC (permalink / raw)
  To: Johan Hovold, Vinod Koul
  Cc: JC Kuo, Kishon Vijay Abraham I, Thierry Reding, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel, stable

On 24/07/2025 15:12, Johan Hovold wrote:
> Make sure to drop the references taken to the PMC OF node and device by
> of_parse_phandle() and of_find_device_by_node() during probe.
> 
> Note the holding a reference to the PMC device does not prevent the
> PMC regmap from going away (e.g. if the PMC driver is unbound) so there
> is no need to keep the reference.
> 
> Fixes: 2d1021487273 ("phy: tegra: xusb: Add wake/sleepwalk for Tegra210")
> Cc: stable@vger.kernel.org	# 5.14
> Cc: JC Kuo <jckuo@nvidia.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>   drivers/phy/tegra/xusb-tegra210.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 

<snip>


Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] phy: fix device leaks at unbind
  2025-07-24 13:12 [PATCH 0/3] phy: fix device leaks at unbind Johan Hovold
                   ` (2 preceding siblings ...)
  2025-07-24 13:12 ` [PATCH 3/3] phy: ti-pipe3: " Johan Hovold
@ 2025-08-12 16:40 ` Vinod Koul
  3 siblings, 0 replies; 6+ messages in thread
From: Vinod Koul @ 2025-08-12 16:40 UTC (permalink / raw)
  To: Johan Hovold
  Cc: JC Kuo, Kishon Vijay Abraham I, Thierry Reding, Jonathan Hunter,
	linux-phy, linux-tegra, linux-kernel


On Thu, 24 Jul 2025 15:12:03 +0200, Johan Hovold wrote:
> This series fixes device leaks due to failure to drop the reference
> taken by of_find_device_by_node().
> 
> Johan
> 
> Johan Hovold (3):
>   phy: tegra: xusb: fix device and OF node leak at probe
>   phy: ti: omap-usb2: fix device leak at unbind
>   phy: ti-pipe3: fix device leak at unbind
> 
> [...]

Applied, thanks!

[1/3] phy: tegra: xusb: fix device and OF node leak at probe
      commit: bca065733afd1e3a89a02f05ffe14e966cd5f78e
[2/3] phy: ti: omap-usb2: fix device leak at unbind
      commit: 64961557efa1b98f375c0579779e7eeda1a02c42
[3/3] phy: ti-pipe3: fix device leak at unbind
      commit: e19bcea99749ce8e8f1d359f68ae03210694ad56

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-12 16:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24 13:12 [PATCH 0/3] phy: fix device leaks at unbind Johan Hovold
2025-07-24 13:12 ` [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe Johan Hovold
2025-08-06 14:35   ` neil.armstrong
2025-07-24 13:12 ` [PATCH 2/3] phy: ti: omap-usb2: fix device leak at unbind Johan Hovold
2025-07-24 13:12 ` [PATCH 3/3] phy: ti-pipe3: " Johan Hovold
2025-08-12 16:40 ` [PATCH 0/3] phy: fix device leaks " Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).