Skip to content

Commit 3f978e3

Browse files
Abdun Nihaalkuba-moo
authored andcommitted
isdn: mISDN: hfcsusb: fix memory leak in hfcsusb_probe()
In hfcsusb_probe(), the memory allocated for ctrl_urb gets leaked when setup_instance() fails with an error code. Fix that by freeing the urb before freeing the hw structure. Also change the error paths to use the goto ladder style. Compile tested only. Issue found using a prototype static analysis tool. Fixes: 69f52ad ("mISDN: Add HFC USB driver") Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in> Link: https://patch.msgid.link/20251030042524.194812-1-nihaal@cse.iitm.ac.in Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f8e8486 commit 3f978e3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

drivers/isdn/hardware/mISDN/hfcsusb.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,13 +1904,13 @@ setup_instance(struct hfcsusb *hw, struct device *parent)
19041904
mISDN_freebchannel(&hw->bch[1]);
19051905
mISDN_freebchannel(&hw->bch[0]);
19061906
mISDN_freedchannel(&hw->dch);
1907-
kfree(hw);
19081907
return err;
19091908
}
19101909

19111910
static int
19121911
hfcsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
19131912
{
1913+
int err;
19141914
struct hfcsusb *hw;
19151915
struct usb_device *dev = interface_to_usbdev(intf);
19161916
struct usb_host_interface *iface = intf->cur_altsetting;
@@ -2101,20 +2101,28 @@ hfcsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
21012101
if (!hw->ctrl_urb) {
21022102
pr_warn("%s: No memory for control urb\n",
21032103
driver_info->vend_name);
2104-
kfree(hw);
2105-
return -ENOMEM;
2104+
err = -ENOMEM;
2105+
goto err_free_hw;
21062106
}
21072107

21082108
pr_info("%s: %s: detected \"%s\" (%s, if=%d alt=%d)\n",
21092109
hw->name, __func__, driver_info->vend_name,
21102110
conf_str[small_match], ifnum, alt_used);
21112111

2112-
if (setup_instance(hw, dev->dev.parent))
2113-
return -EIO;
2112+
if (setup_instance(hw, dev->dev.parent)) {
2113+
err = -EIO;
2114+
goto err_free_urb;
2115+
}
21142116

21152117
hw->intf = intf;
21162118
usb_set_intfdata(hw->intf, hw);
21172119
return 0;
2120+
2121+
err_free_urb:
2122+
usb_free_urb(hw->ctrl_urb);
2123+
err_free_hw:
2124+
kfree(hw);
2125+
return err;
21182126
}
21192127

21202128
/* function called when an active device is removed */

0 commit comments

Comments
 (0)