Commit a49bcabe authored by Jesper Juhl's avatar Jesper Juhl Committed by Marc Kleine-Budde

can: usb: PCAN-USB Pro: fix mem leaks in pcan_usb_pro_init() on error paths

If either call to pcan_usb_pro_send_req() in
drivers/net/can/usb/peak_usb/pcan_usb_pro.c::pcan_usb_pro_init()
fails, we'll leak the memory we allocated to 'usb_if' with kzalloc()
when the 'usb_if' variable goes out of scope without having been
assigned to anything as we 'return err;'.
Fix this by adding appropriate kfree(usb_if) calls to the error paths.
Signed-off-by: default avatarJesper Juhl <jj@chaosbits.net>
Acked-by: default avatarStephane Grosjean <s.grosjean@peak-system.com>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 8a9a0ea6
...@@ -875,6 +875,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev) ...@@ -875,6 +875,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev)
PCAN_USBPRO_INFO_FW, PCAN_USBPRO_INFO_FW,
&fi, sizeof(fi)); &fi, sizeof(fi));
if (err) { if (err) {
kfree(usb_if);
dev_err(dev->netdev->dev.parent, dev_err(dev->netdev->dev.parent,
"unable to read %s firmware info (err %d)\n", "unable to read %s firmware info (err %d)\n",
pcan_usb_pro.name, err); pcan_usb_pro.name, err);
...@@ -885,6 +886,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev) ...@@ -885,6 +886,7 @@ static int pcan_usb_pro_init(struct peak_usb_device *dev)
PCAN_USBPRO_INFO_BL, PCAN_USBPRO_INFO_BL,
&bi, sizeof(bi)); &bi, sizeof(bi));
if (err) { if (err) {
kfree(usb_if);
dev_err(dev->netdev->dev.parent, dev_err(dev->netdev->dev.parent,
"unable to read %s bootloader info (err %d)\n", "unable to read %s bootloader info (err %d)\n",
pcan_usb_pro.name, err); pcan_usb_pro.name, 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