mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] phy: tegra: xusb: Fix OF node reference leaks in enabled pad setup
@ 2026-11-26 15:59 Yige Jiang
  0 siblings, 0 replies; only message in thread
From: Yige Jiang @ 2026-11-26 15:59 UTC (permalink / raw)
  To: JC Kuo, Vinod Koul, Thierry Reding, Jonathan Hunter
  Cc: Yige Jiang, Neil Armstrong, Manivannan Sadhasivam, linux-phy,
	linux-tegra, linux-kernel

tegra_xusb_pad_create() looks up the node for an enabled pad and passes
it to the SoC probe. The pad device stores that pointer in dev.of_node.
Neither the probe caller nor the pad release callback drops the lookup
reference.

Give the pad device its own node reference before device_add() and drop
it in tegra_xusb_pad_release(). The caller can then put its lookup
reference as soon as the SoC probe returns, including on error.

tegra_xusb_pad_register() also looks up the "lanes" child. The PHY
provider takes its own reference to that node. Drop the local reference
after successful registration, as the error paths already do.

I used an AI coding assistant to trace the node references and prepare
the diff and commit message.

Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
Signed-off-by: Yige Jiang <yigejiang86@gmail.com>
---
Based on linux-next next-20261109 (630059a5a632).

Julia Lawall posted a separate fix for disabled pads in 2019:
https://lore.kernel.org/linux-tegra/1550928043-14889-5-git-send-email-Julia.Lawall@lip6.fr/

An earlier version including the disabled-pad change was compile-tested
on arm64 (GCC 14.2.0, W=1). This revision has not been compiled or
tested on Tegra hardware.

 drivers/phy/tegra/xusb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index cd1cd985f36a..aa6ede9f4a21 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -161,6 +161,7 @@ static void tegra_xusb_pad_release(struct device *dev)
 {
 	struct tegra_xusb_pad *pad = to_tegra_xusb_pad(dev);
 
+	of_node_put(pad->dev.of_node);
 	pad->soc->ops->remove(pad);
 }
 
@@ -178,7 +179,7 @@ int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
 	INIT_LIST_HEAD(&pad->list);
 	pad->dev.parent = padctl->dev;
 	pad->dev.type = &tegra_xusb_pad_type;
-	pad->dev.of_node = np;
+	pad->dev.of_node = of_node_get(np);
 	pad->padctl = padctl;
 
 	err = dev_set_name(&pad->dev, "%s", pad->soc->name);
@@ -249,6 +250,8 @@ int tegra_xusb_pad_register(struct tegra_xusb_pad *pad,
 		goto remove;
 	}
 
+	of_node_put(children);
+
 	return 0;
 
 remove:
@@ -285,6 +288,7 @@ tegra_xusb_pad_create(struct tegra_xusb_padctl *padctl,
 		return NULL;
 
 	pad = soc->ops->probe(padctl, soc, np);
+	of_node_put(np);
 	if (IS_ERR(pad)) {
 		err = PTR_ERR(pad);
 		dev_err(padctl->dev, "failed to create pad %s: %d\n",

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-26 15:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 15:59 [PATCH] phy: tegra: xusb: Fix OF node reference leaks in enabled pad setup Yige Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®