Commit 68822f4e authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

can: gs_usb: gs_make_candev(): clean up error handling

Introduce a label to free the allocated candev in case of an error and
make use of if. Fix a memory leak if the extended bit timing cannot be
read. Extend the error messages to print the number of the failing
channel and the symbolic error name.

Link: https://lore.kernel.org/all/20220921193902.575416-4-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 3814ed27
...@@ -1100,8 +1100,8 @@ static struct gs_can *gs_make_candev(unsigned int channel, ...@@ -1100,8 +1100,8 @@ static struct gs_can *gs_make_candev(unsigned int channel,
if (rc) { if (rc) {
dev_err(&intf->dev, dev_err(&intf->dev,
"Couldn't get bit timing const for channel (err=%d)\n", "Couldn't get bit timing const for channel %d (%pe)\n",
rc); channel, ERR_PTR(rc));
return ERR_PTR(rc); return ERR_PTR(rc);
} }
...@@ -1215,9 +1215,9 @@ static struct gs_can *gs_make_candev(unsigned int channel, ...@@ -1215,9 +1215,9 @@ static struct gs_can *gs_make_candev(unsigned int channel,
1000, GFP_KERNEL); 1000, GFP_KERNEL);
if (rc) { if (rc) {
dev_err(&intf->dev, dev_err(&intf->dev,
"Couldn't get extended bit timing const for channel (err=%d)\n", "Couldn't get extended bit timing const for channel %d (%pe)\n",
rc); channel, ERR_PTR(rc));
return ERR_PTR(rc); goto out_free_candev;
} }
strcpy(dev->data_bt_const.name, KBUILD_MODNAME); strcpy(dev->data_bt_const.name, KBUILD_MODNAME);
...@@ -1237,12 +1237,17 @@ static struct gs_can *gs_make_candev(unsigned int channel, ...@@ -1237,12 +1237,17 @@ static struct gs_can *gs_make_candev(unsigned int channel,
rc = register_candev(dev->netdev); rc = register_candev(dev->netdev);
if (rc) { if (rc) {
free_candev(dev->netdev); dev_err(&intf->dev,
dev_err(&intf->dev, "Couldn't register candev (err=%d)\n", rc); "Couldn't register candev for channel %d (%pe)\n",
return ERR_PTR(rc); channel, ERR_PTR(rc));
goto out_free_candev;
} }
return dev; return dev;
out_free_candev:
free_candev(dev->netdev);
return ERR_PTR(rc);
} }
static void gs_destroy_candev(struct gs_can *dev) static void gs_destroy_candev(struct gs_can *dev)
......
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