This series fixes two similar issues in tegra_210_xusb_padctl_probe().
Two resources (device_node *np and the device within struct platform_device *pdev) are acquired, but never released after they are no longer needed. To avoid leaking such resources, calls to of_node_put() and put_device() must be added.
In this case, the resources are not assigned anywhere in the probe function, and they must be released in the error and success paths. If I overlooked any assignment, please report it as an error.
I have tried to affect the existing code and execution paths as less as possible by releasing the device and device_node as soon as possible, but if goto jumps to labels for the cleanup are desired, I can go for that approach instead.
This series has been compiled successfully, but not tested on real hardware as I don't have access to it. Any validation with the affected hardware is always welcome.
Signed-off-by: Javier Carrasco javier.carrasco.cruz@gmail.com --- Javier Carrasco (2): phy: tegra: xusb: fix device release in tegra210_xusb_padctl_probe phy: tegra: xusb: fix device node release in tegra210_xusb_padctl_probe
drivers/phy/tegra/xusb-tegra210.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- base-commit: dec9255a128e19c5fcc3bdb18175d78094cc624d change-id: 20241028-phy-tegra-xusb-tegra210-put_device-ff7ae76403b4
Best regards,
A reference to a device acquired via of_find_device_by_node() needs to be released when it is no longer required by decrementing its refcount, which avoids leaking the resource.
Add the missing call to platform_device_put() as soon as 'pdev' is no longer required.
Cc: stable@vger.kernel.org Fixes: 2d1021487273 ("phy: tegra: xusb: Add wake/sleepwalk for Tegra210") Signed-off-by: Javier Carrasco javier.carrasco.cruz@gmail.com --- 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..9c7fdd29b7c4 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -3169,13 +3169,17 @@ tegra210_xusb_padctl_probe(struct device *dev, goto out; }
- if (!platform_get_drvdata(pdev)) + if (!platform_get_drvdata(pdev)) { + platform_device_put(pdev); 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");
+ platform_device_put(pdev); + out: return &padctl->base; }
A device_node acquired via of_parse_phandle() needs a call to of_node_put() when the it is no longer required to decrement its refcount and avoid leaking the resource.
Add the missing call to of_node_put() as soon as 'np' is no longer required.
Cc: stable@vger.kernel.org Fixes: 2d1021487273 ("phy: tegra: xusb: Add wake/sleepwalk for Tegra210") Signed-off-by: Javier Carrasco javier.carrasco.cruz@gmail.com --- drivers/phy/tegra/xusb-tegra210.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/phy/tegra/xusb-tegra210.c b/drivers/phy/tegra/xusb-tegra210.c index 9c7fdd29b7c4..a77127d6c4fa 100644 --- a/drivers/phy/tegra/xusb-tegra210.c +++ b/drivers/phy/tegra/xusb-tegra210.c @@ -3164,6 +3164,7 @@ 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;
linux-stable-mirror@lists.linaro.org