提交 638b9e15 编写于 作者: J Johan Hovold 提交者: Greg Kroah-Hartman

USB: ssu100: 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>
上级 51ef847d
...@@ -67,13 +67,6 @@ struct ssu100_port_private { ...@@ -67,13 +67,6 @@ struct ssu100_port_private {
struct async_icount icount; struct async_icount icount;
}; };
static void ssu100_release(struct usb_serial *serial)
{
struct ssu100_port_private *priv = usb_get_serial_port_data(*serial->port);
kfree(priv);
}
static inline int ssu100_control_msg(struct usb_device *dev, static inline int ssu100_control_msg(struct usb_device *dev,
u8 request, u16 data, u16 index) u8 request, u16 data, u16 index)
{ {
...@@ -441,22 +434,34 @@ static int ssu100_ioctl(struct tty_struct *tty, ...@@ -441,22 +434,34 @@ static int ssu100_ioctl(struct tty_struct *tty,
} }
static int ssu100_attach(struct usb_serial *serial) static int ssu100_attach(struct usb_serial *serial)
{
return ssu100_initdevice(serial->dev);
}
static int ssu100_port_probe(struct usb_serial_port *port)
{ {
struct ssu100_port_private *priv; struct ssu100_port_private *priv;
struct usb_serial_port *port = *serial->port;
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv)
dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
sizeof(*priv));
return -ENOMEM; return -ENOMEM;
}
spin_lock_init(&priv->status_lock); spin_lock_init(&priv->status_lock);
init_waitqueue_head(&priv->delta_msr_wait); init_waitqueue_head(&priv->delta_msr_wait);
usb_set_serial_port_data(port, priv); usb_set_serial_port_data(port, priv);
return ssu100_initdevice(serial->dev); return 0;
}
static int ssu100_port_remove(struct usb_serial_port *port)
{
struct ssu100_port_private *priv;
priv = usb_get_serial_port_data(port);
kfree(priv);
return 0;
} }
static int ssu100_tiocmget(struct tty_struct *tty) static int ssu100_tiocmget(struct tty_struct *tty)
...@@ -647,7 +652,8 @@ static struct usb_serial_driver ssu100_device = { ...@@ -647,7 +652,8 @@ static struct usb_serial_driver ssu100_device = {
.open = ssu100_open, .open = ssu100_open,
.close = ssu100_close, .close = ssu100_close,
.attach = ssu100_attach, .attach = ssu100_attach,
.release = ssu100_release, .port_probe = ssu100_port_probe,
.port_remove = ssu100_port_remove,
.dtr_rts = ssu100_dtr_rts, .dtr_rts = ssu100_dtr_rts,
.process_read_urb = ssu100_process_read_urb, .process_read_urb = ssu100_process_read_urb,
.tiocmget = ssu100_tiocmget, .tiocmget = ssu100_tiocmget,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册