[PATCH] phy: tegra: xusb: fix wrong cleanup function in tegra_xusb_pad_init()

Salah Triki posted 1 patch 1 week ago
drivers/phy/tegra/xusb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] phy: tegra: xusb: fix wrong cleanup function in tegra_xusb_pad_init()
Posted by Salah Triki 1 week ago
In `tegra_xusb_pad_init()`, the code currently calls `device_unregister()`
if `dev_set_name()` or `device_add()` fails. This is technically incorrect.

`device_unregister()` is a combination of `device_del()` and `put_device()`
Calling `device_del()` is only valid if the device has been successfully
added to the system via `device_add()`. If `device_add()` fails or has not
been called yet, we must only use `put_device()` to drop the reference
count initialized by `device_initialize()`.

Fix this by calling `put_device()` instead of `device_unregister()` in the
error path.

Fixes: 53d2a715c2403 ("phy: Add Tegra XUSB pad controller support")

Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
 drivers/phy/tegra/xusb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index c89df95aa6ca..2db5586401e5 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -180,7 +180,7 @@ int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
 	return 0;
 
 unregister:
-	device_unregister(&pad->dev);
+	put_device(&pad->dev);
 	return err;
 }
 
-- 
2.43.0