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

Yang Yingliang yangyingliang at huawei.com
Tue Nov 1 18:57:32 PDT 2022


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 at nvidia.com>
Cc: Kishon Vijay Abraham I <kishon at ti.com>
Cc: Vinod Koul <vkoul at kernel.org>
Cc: Thierry Reding <thierry.reding at gmail.com>
Cc: Jonathan Hunter <jonathanh at nvidia.com>
Signed-off-by: Yang Yingliang <yangyingliang at huawei.com>
---
 drivers/phy/tegra/xusb.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

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;
 }
 
-- 
2.25.1




More information about the linux-phy mailing list