Commit e1f20f1d authored by Stephane Grosjean's avatar Stephane Grosjean Committed by Jiri Slaby

can: peak_usb: fix cleanup sequence order in case of error during init

commit af35d0f1 upstream.

This patch sets the correct reverse sequence order to the instructions
set to run, when any failure occurs during the initialization steps.
It also adds the missing unregistration call of the can device if the
failure appears after having been registered.
Signed-off-by: default avatarStephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 5dc24dd1
...@@ -734,7 +734,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -734,7 +734,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL); dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL);
if (!dev->cmd_buf) { if (!dev->cmd_buf) {
err = -ENOMEM; err = -ENOMEM;
goto lbl_set_intf_data; goto lbl_free_candev;
} }
dev->udev = usb_dev; dev->udev = usb_dev;
...@@ -773,7 +773,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -773,7 +773,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
err = register_candev(netdev); err = register_candev(netdev);
if (err) { if (err) {
dev_err(&intf->dev, "couldn't register CAN device: %d\n", err); dev_err(&intf->dev, "couldn't register CAN device: %d\n", err);
goto lbl_free_cmd_buf; goto lbl_restore_intf_data;
} }
if (dev->prev_siblings) if (dev->prev_siblings)
...@@ -786,14 +786,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -786,14 +786,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
if (dev->adapter->dev_init) { if (dev->adapter->dev_init) {
err = dev->adapter->dev_init(dev); err = dev->adapter->dev_init(dev);
if (err) if (err)
goto lbl_free_cmd_buf; goto lbl_unregister_candev;
} }
/* set bus off */ /* set bus off */
if (dev->adapter->dev_set_bus) { if (dev->adapter->dev_set_bus) {
err = dev->adapter->dev_set_bus(dev, 0); err = dev->adapter->dev_set_bus(dev, 0);
if (err) if (err)
goto lbl_free_cmd_buf; goto lbl_unregister_candev;
} }
/* get device number early */ /* get device number early */
...@@ -805,11 +805,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter, ...@@ -805,11 +805,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
return 0; return 0;
lbl_free_cmd_buf: lbl_unregister_candev:
kfree(dev->cmd_buf); unregister_candev(netdev);
lbl_set_intf_data: lbl_restore_intf_data:
usb_set_intfdata(intf, dev->prev_siblings); usb_set_intfdata(intf, dev->prev_siblings);
kfree(dev->cmd_buf);
lbl_free_candev:
free_candev(netdev); free_candev(netdev);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment