Skip to content

Commit

Permalink
usb: cdc_acm: Do not leak URB buffers
Browse files Browse the repository at this point in the history
When the ACM TTY port is disconnected, the URBs it uses must be killed, and
then the buffers must be freed. Unfortunately a previous refactor removed
the code freeing the buffers because it looked extremely similar to the
code killing the URBs.

As a result, there were many new leaks for each plug/unplug cycle of a
CDC-ACM device, that were detected by kmemleak.

Restore the missing code, and the memory leak is removed.

Fixes: ba8c931 ("cdc-acm: refactor killing urbs")
Signed-off-by: Romain Izard <[email protected]>
Acked-by: Oliver Neukum <[email protected]>
Cc: stable <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
romain-izard-pro authored and gregkh committed Oct 2, 2018
1 parent dcb44ac commit f2924d4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/usb/class/cdc-acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ static void acm_disconnect(struct usb_interface *intf)
{
struct acm *acm = usb_get_intfdata(intf);
struct tty_struct *tty;
int i;

/* sibling interface is already cleaning up */
if (!acm)
Expand Down Expand Up @@ -1544,6 +1545,11 @@ static void acm_disconnect(struct usb_interface *intf)

tty_unregister_device(acm_tty_driver, acm->minor);

usb_free_urb(acm->ctrlurb);
for (i = 0; i < ACM_NW; i++)
usb_free_urb(acm->wb[i].urb);
for (i = 0; i < acm->rx_buflimit; i++)
usb_free_urb(acm->read_urbs[i]);
acm_write_buffers_free(acm);
usb_free_coherent(acm->dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
acm_read_buffers_free(acm);
Expand Down

0 comments on commit f2924d4

Please sign in to comment.