Skip to contentSkip to conversation

phy: fix device leaks at unbind

PATCH Applied Johan Hovold 3 participants 6 messages Jul 24, 2025 – Aug 12, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover phy: fix device leaks at unbind

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(-)
Signature · 1 line
2.49.1
#1 lore raw

PATCH 1/3 phy: tegra: xusb: fix device and OF node leak at probe

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 JC Kuo <[email protected]>
---
 drivers/phy/tegra/xusb-tegra210.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/phy/tegra/xusb-tegra210.c +5 -1
index ebc8a7e21a31..3409924498e9 100644
@@ -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;
 }
Signature · 1 line
2.49.1
reviewer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] phy: tegra: xusb: fix device and OF node leak at probe

Quoted 15 lines · Johan Hovold

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 JC Kuo <[email protected]>
---
  drivers/phy/tegra/xusb-tegra210.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)

<snip>

#3 lore raw

PATCH 2/3 phy: ti: omap-usb2: fix device leak at unbind

In reply to Johan Hovold

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 Roger Quadros <[email protected]>
---
 drivers/phy/ti/phy-omap-usb2.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/phy/ti/phy-omap-usb2.c +13 -0
index c1a0ef979142..c444bb2530ca 100644
@@ -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,
Signature · 1 line
2.49.1
#4 lore raw

PATCH 3/3 phy: ti-pipe3: fix device leak at unbind

In reply to Johan Hovold

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 Roger Quadros <[email protected]>
---
 drivers/phy/ti/phy-ti-pipe3.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/phy/ti/phy-ti-pipe3.c +13 -0
index da2cbacb982c..ae764d6524c9 100644
@@ -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) {
Signature · 1 line
2.49.1
maintainer Applied
#5 lore raw
In reply to Johan Hovold
Quoted 11 lines · 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

[...]

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,

Signature · 1 line
~Vinod