Commit 34f8e761 authored by Pete Zaitcev's avatar Pete Zaitcev Committed by Greg Kroah-Hartman

[PATCH] USB: fix usb-serial leaks, oopses on disconnect

This fix addresses two issues:
- Unattached port structures were not freed
- My initial fix for crash when eventd runs a work in a freed port
  did not go far enough
Signed-off-by: default avatarPete Zaitcev <zaitcev@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 92164c5d
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/" #define DRIVER_AUTHOR "Greg Kroah-Hartman, greg@kroah.com, http://www.kroah.com/linux/"
#define DRIVER_DESC "USB Serial Driver core" #define DRIVER_DESC "USB Serial Driver core"
static void port_free(struct usb_serial_port *port);
/* Driver structure we register with the USB core */ /* Driver structure we register with the USB core */
static struct usb_driver usb_serial_driver = { static struct usb_driver usb_serial_driver = {
.name = "usbserial", .name = "usbserial",
...@@ -146,23 +148,10 @@ static void destroy_serial(struct kref *kref) ...@@ -146,23 +148,10 @@ static void destroy_serial(struct kref *kref)
port = serial->port[i]; port = serial->port[i];
if (!port) if (!port)
continue; continue;
usb_kill_urb(port->read_urb); port_free(port);
usb_free_urb(port->read_urb);
usb_kill_urb(port->write_urb);
usb_free_urb(port->write_urb);
usb_kill_urb(port->interrupt_in_urb);
usb_free_urb(port->interrupt_in_urb);
usb_kill_urb(port->interrupt_out_urb);
usb_free_urb(port->interrupt_out_urb);
kfree(port->bulk_in_buffer);
kfree(port->bulk_out_buffer);
kfree(port->interrupt_in_buffer);
kfree(port->interrupt_out_buffer);
} }
} }
flush_scheduled_work(); /* port->work */
usb_put_dev(serial->dev); usb_put_dev(serial->dev);
/* free up any memory that we allocated */ /* free up any memory that we allocated */
...@@ -564,6 +553,11 @@ static void port_release(struct device *dev) ...@@ -564,6 +553,11 @@ static void port_release(struct device *dev)
struct usb_serial_port *port = to_usb_serial_port(dev); struct usb_serial_port *port = to_usb_serial_port(dev);
dbg ("%s - %s", __FUNCTION__, dev->bus_id); dbg ("%s - %s", __FUNCTION__, dev->bus_id);
port_free(port);
}
static void port_free(struct usb_serial_port *port)
{
usb_kill_urb(port->read_urb); usb_kill_urb(port->read_urb);
usb_free_urb(port->read_urb); usb_free_urb(port->read_urb);
usb_kill_urb(port->write_urb); usb_kill_urb(port->write_urb);
...@@ -576,6 +570,7 @@ static void port_release(struct device *dev) ...@@ -576,6 +570,7 @@ static void port_release(struct device *dev)
kfree(port->bulk_out_buffer); kfree(port->bulk_out_buffer);
kfree(port->interrupt_in_buffer); kfree(port->interrupt_in_buffer);
kfree(port->interrupt_out_buffer); kfree(port->interrupt_out_buffer);
flush_scheduled_work(); /* port->work */
kfree(port); kfree(port);
} }
......
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