diff mbox series

phy: tegra: xusb: fix error handing in tegra_xusb_{pad|port}_init()

Message ID 20221102015732.1332099-1-yangyingliang@huawei.com
State Changes Requested
Headers show
Series phy: tegra: xusb: fix error handing in tegra_xusb_{pad|port}_init() | expand

Commit Message

Yang Yingliang Nov. 2, 2022, 1:57 a.m. UTC
If device_add() is not called successful, it can not call
device_unregister(), it will lead a kernel crash because
of deleting not added device. Fix these by using put_device()
instead.

Fixes: 53d2a715c240 ("phy: Add Tegra XUSB pad controller support")
Cc: JC Kuo <jckuo@nvidia.com>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Vinod Koul <vkoul@kernel.org>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/phy/tegra/xusb.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 95091876c422..65e15dcde02f 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -165,16 +165,16 @@  int tegra_xusb_pad_init(struct tegra_xusb_pad *pad,
 
 	err = dev_set_name(&pad->dev, "%s", pad->soc->name);
 	if (err < 0)
-		goto unregister;
+		goto put_dev;
 
 	err = device_add(&pad->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_dev;
 
 	return 0;
 
-unregister:
-	device_unregister(&pad->dev);
+put_dev:
+	put_device(&pad->dev);
 	return err;
 }
 
@@ -542,16 +542,16 @@  static int tegra_xusb_port_init(struct tegra_xusb_port *port,
 
 	err = dev_set_name(&port->dev, "%s-%u", name, index);
 	if (err < 0)
-		goto unregister;
+		goto put_dev;
 
 	err = device_add(&port->dev);
 	if (err < 0)
-		goto unregister;
+		goto put_dev;
 
 	return 0;
 
-unregister:
-	device_unregister(&port->dev);
+put_dev:
+	put_device(&port->dev);
 	return err;
 }