Skip to content

Commit

Permalink
USB: omninet: fix port-data memory leak
Browse files Browse the repository at this point in the history
Fix port-data memory leak by replacing attach and release with
port_probe and port_remove.

Since commit 0998d06 (device-core: Ensure drvdata = NULL when no
driver is bound) the port private data is no longer freed at release as
it is no longer accessible.

Compile-only tested.

Cc: <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Johan Hovold authored and Greg Kroah-Hartman committed Oct 25, 2012
1 parent 4230af5 commit feffa7c
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions drivers/usb/serial/omninet.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
const unsigned char *buf, int count);
static int omninet_write_room(struct tty_struct *tty);
static void omninet_disconnect(struct usb_serial *serial);
static void omninet_release(struct usb_serial *serial);
static int omninet_attach(struct usb_serial *serial);
static int omninet_port_probe(struct usb_serial_port *port);
static int omninet_port_remove(struct usb_serial_port *port);

static const struct usb_device_id id_table[] = {
{ USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
Expand All @@ -62,15 +62,15 @@ static struct usb_serial_driver zyxel_omninet_device = {
.description = "ZyXEL - omni.net lcd plus usb",
.id_table = id_table,
.num_ports = 1,
.attach = omninet_attach,
.port_probe = omninet_port_probe,
.port_remove = omninet_port_remove,
.open = omninet_open,
.close = omninet_close,
.write = omninet_write,
.write_room = omninet_write_room,
.read_bulk_callback = omninet_read_bulk_callback,
.write_bulk_callback = omninet_write_bulk_callback,
.disconnect = omninet_disconnect,
.release = omninet_release,
};

static struct usb_serial_driver * const serial_drivers[] = {
Expand Down Expand Up @@ -112,18 +112,26 @@ struct omninet_data {
__u8 od_outseq; /* Sequence number for bulk_out URBs */
};

static int omninet_attach(struct usb_serial *serial)
static int omninet_port_probe(struct usb_serial_port *port)
{
struct omninet_data *od;
struct usb_serial_port *port = serial->port[0];

od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL);
if (!od) {
dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n",
__func__, sizeof(struct omninet_data));
if (!od)
return -ENOMEM;
}

usb_set_serial_port_data(port, od);

return 0;
}

static int omninet_port_remove(struct usb_serial_port *port)
{
struct omninet_data *od;

od = usb_get_serial_port_data(port);
kfree(od);

return 0;
}

Expand Down Expand Up @@ -279,14 +287,6 @@ static void omninet_disconnect(struct usb_serial *serial)
usb_kill_urb(wport->write_urb);
}


static void omninet_release(struct usb_serial *serial)
{
struct usb_serial_port *port = serial->port[0];

kfree(usb_get_serial_port_data(port));
}

module_usb_serial_driver(serial_drivers, id_table);

MODULE_AUTHOR(DRIVER_AUTHOR);
Expand Down

0 comments on commit feffa7c

Please sign in to comment.