aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2012-10-17 07:34:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-17 16:47:58 -0400
commit3124d1d71d3df59d40b913b5481df58099e811d1 (patch)
treea3b907fa3b42d74b35c312adbbd6dcd65024c0f5 /drivers
parentc27f3efc56080a246f6ab7f57f0a6f56d256d769 (diff)
USB: f81232: fix port-data memory leak
Fix port-data memory leak by replacing attach and release with port_probe and port_remove. Since commit 0998d0631001288 (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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/serial/f81232.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index 244477107e2f..6e4eb57d0177 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -318,39 +318,30 @@ static int f81232_ioctl(struct tty_struct *tty,
318 return -ENOIOCTLCMD; 318 return -ENOIOCTLCMD;
319} 319}
320 320
321static int f81232_startup(struct usb_serial *serial) 321static int f81232_port_probe(struct usb_serial_port *port)
322{ 322{
323 struct f81232_private *priv; 323 struct f81232_private *priv;
324 int i;
325 324
326 for (i = 0; i < serial->num_ports; ++i) { 325 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
327 priv = kzalloc(sizeof(struct f81232_private), GFP_KERNEL); 326 if (!priv)
328 if (!priv) 327 return -ENOMEM;
329 goto cleanup;
330 spin_lock_init(&priv->lock);
331 init_waitqueue_head(&priv->delta_msr_wait);
332 usb_set_serial_port_data(serial->port[i], priv);
333 }
334 return 0;
335 328
336cleanup: 329 spin_lock_init(&priv->lock);
337 for (--i; i >= 0; --i) { 330 init_waitqueue_head(&priv->delta_msr_wait);
338 priv = usb_get_serial_port_data(serial->port[i]); 331
339 kfree(priv); 332 usb_set_serial_port_data(port, priv);
340 usb_set_serial_port_data(serial->port[i], NULL); 333
341 } 334 return 0;
342 return -ENOMEM;
343} 335}
344 336
345static void f81232_release(struct usb_serial *serial) 337static int f81232_port_remove(struct usb_serial_port *port)
346{ 338{
347 int i;
348 struct f81232_private *priv; 339 struct f81232_private *priv;
349 340
350 for (i = 0; i < serial->num_ports; ++i) { 341 priv = usb_get_serial_port_data(port);
351 priv = usb_get_serial_port_data(serial->port[i]); 342 kfree(priv);
352 kfree(priv); 343
353 } 344 return 0;
354} 345}
355 346
356static struct usb_serial_driver f81232_device = { 347static struct usb_serial_driver f81232_device = {
@@ -373,8 +364,8 @@ static struct usb_serial_driver f81232_device = {
373 .tiocmset = f81232_tiocmset, 364 .tiocmset = f81232_tiocmset,
374 .process_read_urb = f81232_process_read_urb, 365 .process_read_urb = f81232_process_read_urb,
375 .read_int_callback = f81232_read_int_callback, 366 .read_int_callback = f81232_read_int_callback,
376 .attach = f81232_startup, 367 .port_probe = f81232_port_probe,
377 .release = f81232_release, 368 .port_remove = f81232_port_remove,
378}; 369};
379 370
380static struct usb_serial_driver * const serial_drivers[] = { 371static struct usb_serial_driver * const serial_drivers[] = {