aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Grosjean <s.grosjean@peak-system.com>2014-11-28 07:49:10 -0500
committerMarc Kleine-Budde <mkl@pengutronix.de>2014-12-06 13:11:18 -0500
commitaf35d0f1cce7a990286e2b94c260a2c2d2a0e4b0 (patch)
treec4ffdebf2e27f251c90540877c251d0454e583ca
parentdc50ddcd4c58a5a0226038307d6ef884bec9f8c2 (diff)
can: peak_usb: fix cleanup sequence order in case of error during init
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: Stephane Grosjean <s.grosjean@peak-system.com> Cc: linux-stable <stable@vger.kernel.org> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r--drivers/net/can/usb/peak_usb/pcan_usb_core.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index 644e6ab8a489..dc807e10f802 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -735,7 +735,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
735 dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL); 735 dev->cmd_buf = kmalloc(PCAN_USB_MAX_CMD_LEN, GFP_KERNEL);
736 if (!dev->cmd_buf) { 736 if (!dev->cmd_buf) {
737 err = -ENOMEM; 737 err = -ENOMEM;
738 goto lbl_set_intf_data; 738 goto lbl_free_candev;
739 } 739 }
740 740
741 dev->udev = usb_dev; 741 dev->udev = usb_dev;
@@ -775,7 +775,7 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
775 err = register_candev(netdev); 775 err = register_candev(netdev);
776 if (err) { 776 if (err) {
777 dev_err(&intf->dev, "couldn't register CAN device: %d\n", err); 777 dev_err(&intf->dev, "couldn't register CAN device: %d\n", err);
778 goto lbl_free_cmd_buf; 778 goto lbl_restore_intf_data;
779 } 779 }
780 780
781 if (dev->prev_siblings) 781 if (dev->prev_siblings)
@@ -788,14 +788,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
788 if (dev->adapter->dev_init) { 788 if (dev->adapter->dev_init) {
789 err = dev->adapter->dev_init(dev); 789 err = dev->adapter->dev_init(dev);
790 if (err) 790 if (err)
791 goto lbl_free_cmd_buf; 791 goto lbl_unregister_candev;
792 } 792 }
793 793
794 /* set bus off */ 794 /* set bus off */
795 if (dev->adapter->dev_set_bus) { 795 if (dev->adapter->dev_set_bus) {
796 err = dev->adapter->dev_set_bus(dev, 0); 796 err = dev->adapter->dev_set_bus(dev, 0);
797 if (err) 797 if (err)
798 goto lbl_free_cmd_buf; 798 goto lbl_unregister_candev;
799 } 799 }
800 800
801 /* get device number early */ 801 /* get device number early */
@@ -807,11 +807,14 @@ static int peak_usb_create_dev(struct peak_usb_adapter *peak_usb_adapter,
807 807
808 return 0; 808 return 0;
809 809
810lbl_free_cmd_buf: 810lbl_unregister_candev:
811 kfree(dev->cmd_buf); 811 unregister_candev(netdev);
812 812
813lbl_set_intf_data: 813lbl_restore_intf_data:
814 usb_set_intfdata(intf, dev->prev_siblings); 814 usb_set_intfdata(intf, dev->prev_siblings);
815 kfree(dev->cmd_buf);
816
817lbl_free_candev:
815 free_candev(netdev); 818 free_candev(netdev);
816 819
817 return err; 820 return err;