提交 289b076f 编写于 作者: J Johan Hovold 提交者: Greg Kroah-Hartman

USB: oti6858: fix port-data memory leak

Fix port-data memory leak by replacing attach and release with
port_probe and port_remove.

Since commit 0998d063 (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: NJohan Hovold <jhovold@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 53636555
...@@ -137,8 +137,8 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty); ...@@ -137,8 +137,8 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty);
static int oti6858_tiocmget(struct tty_struct *tty); static int oti6858_tiocmget(struct tty_struct *tty);
static int oti6858_tiocmset(struct tty_struct *tty, static int oti6858_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear); unsigned int set, unsigned int clear);
static int oti6858_startup(struct usb_serial *serial); static int oti6858_port_probe(struct usb_serial_port *port);
static void oti6858_release(struct usb_serial *serial); static int oti6858_port_remove(struct usb_serial_port *port);
/* device info */ /* device info */
static struct usb_serial_driver oti6858_device = { static struct usb_serial_driver oti6858_device = {
...@@ -161,8 +161,8 @@ static struct usb_serial_driver oti6858_device = { ...@@ -161,8 +161,8 @@ static struct usb_serial_driver oti6858_device = {
.write_bulk_callback = oti6858_write_bulk_callback, .write_bulk_callback = oti6858_write_bulk_callback,
.write_room = oti6858_write_room, .write_room = oti6858_write_room,
.chars_in_buffer = oti6858_chars_in_buffer, .chars_in_buffer = oti6858_chars_in_buffer,
.attach = oti6858_startup, .port_probe = oti6858_port_probe,
.release = oti6858_release, .port_remove = oti6858_port_remove,
}; };
static struct usb_serial_driver * const serial_drivers[] = { static struct usb_serial_driver * const serial_drivers[] = {
...@@ -331,36 +331,33 @@ static void send_data(struct work_struct *work) ...@@ -331,36 +331,33 @@ static void send_data(struct work_struct *work)
usb_serial_port_softint(port); usb_serial_port_softint(port);
} }
static int oti6858_startup(struct usb_serial *serial) static int oti6858_port_probe(struct usb_serial_port *port)
{ {
struct usb_serial_port *port = serial->port[0];
struct oti6858_private *priv; struct oti6858_private *priv;
int i;
for (i = 0; i < serial->num_ports; ++i) { priv = kzalloc(sizeof(*priv), GFP_KERNEL);
priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL);
if (!priv) if (!priv)
break; return -ENOMEM;
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
init_waitqueue_head(&priv->intr_wait); init_waitqueue_head(&priv->intr_wait);
/* INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); */
/* INIT_WORK(&priv->write_work, send_data, serial->port[i]); */
priv->port = port; priv->port = port;
INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line); INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line);
INIT_DELAYED_WORK(&priv->delayed_write_work, send_data); INIT_DELAYED_WORK(&priv->delayed_write_work, send_data);
usb_set_serial_port_data(serial->port[i], priv); usb_set_serial_port_data(port, priv);
}
if (i == serial->num_ports)
return 0; return 0;
}
for (--i; i >= 0; --i) { static int oti6858_port_remove(struct usb_serial_port *port)
priv = usb_get_serial_port_data(serial->port[i]); {
struct oti6858_private *priv;
priv = usb_get_serial_port_data(port);
kfree(priv); kfree(priv);
usb_set_serial_port_data(serial->port[i], NULL);
} return 0;
return -ENOMEM;
} }
static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port, static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
...@@ -709,15 +706,6 @@ static int oti6858_ioctl(struct tty_struct *tty, ...@@ -709,15 +706,6 @@ static int oti6858_ioctl(struct tty_struct *tty,
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
static void oti6858_release(struct usb_serial *serial)
{
int i;
for (i = 0; i < serial->num_ports; ++i)
kfree(usb_get_serial_port_data(serial->port[i]));
}
static void oti6858_read_int_callback(struct urb *urb) static void oti6858_read_int_callback(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册