Skip to content

Commit 35968b3

Browse files
Ma Kegregkh
Ma Ke
authored andcommitted
phy: Fix error handling in tegra_xusb_port_init
commit b2ea5f4 upstream. If device_add() fails, do not use device_unregister() for error handling. device_unregister() consists two functions: device_del() and put_device(). device_unregister() should only be called after device_add() succeeded because device_del() undoes what device_add() does if successful. Change device_unregister() to put_device() call before returning from the function. As comment of device_add() says, 'if device_add() succeeds, you should call device_del() when you want to get rid of it. If device_add() has not succeeded, use only put_device() to drop the reference count'. Found by code review. Cc: [email protected] Fixes: 53d2a71 ("phy: Add Tegra XUSB pad controller support") Signed-off-by: Ma Ke <[email protected]> Acked-by: Thierry Reding <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 72b4e7e commit 35968b3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/phy/tegra/xusb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,16 @@ static int tegra_xusb_port_init(struct tegra_xusb_port *port,
542542

543543
err = dev_set_name(&port->dev, "%s-%u", name, index);
544544
if (err < 0)
545-
goto unregister;
545+
goto put_device;
546546

547547
err = device_add(&port->dev);
548548
if (err < 0)
549-
goto unregister;
549+
goto put_device;
550550

551551
return 0;
552552

553-
unregister:
554-
device_unregister(&port->dev);
553+
put_device:
554+
put_device(&port->dev);
555555
return err;
556556
}
557557

0 commit comments

Comments
 (0)