aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/belkin_sa.c
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2012-10-15 12:20:53 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-10-16 13:25:54 -0400
commitfa919751a2d26a88140fc5810124dd81644efe51 (patch)
treebd4e1504fa5a5279f49e7e698023aa3f4db34dcd /drivers/usb/serial/belkin_sa.c
parenta9556040119a63d06fd5238d47f5b683fba4178b (diff)
USB: belkin_sa: 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. Note that the write waitqueue was initialised but never used. 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/usb/serial/belkin_sa.c')
-rw-r--r--drivers/usb/serial/belkin_sa.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 99449424193f..ea29556f0d72 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -45,8 +45,8 @@
45#define DRIVER_DESC "USB Belkin Serial converter driver" 45#define DRIVER_DESC "USB Belkin Serial converter driver"
46 46
47/* function prototypes for a Belkin USB Serial Adapter F5U103 */ 47/* function prototypes for a Belkin USB Serial Adapter F5U103 */
48static int belkin_sa_startup(struct usb_serial *serial); 48static int belkin_sa_port_probe(struct usb_serial_port *port);
49static void belkin_sa_release(struct usb_serial *serial); 49static int belkin_sa_port_remove(struct usb_serial_port *port);
50static int belkin_sa_open(struct tty_struct *tty, 50static int belkin_sa_open(struct tty_struct *tty,
51 struct usb_serial_port *port); 51 struct usb_serial_port *port);
52static void belkin_sa_close(struct usb_serial_port *port); 52static void belkin_sa_close(struct usb_serial_port *port);
@@ -88,8 +88,8 @@ static struct usb_serial_driver belkin_device = {
88 .break_ctl = belkin_sa_break_ctl, 88 .break_ctl = belkin_sa_break_ctl,
89 .tiocmget = belkin_sa_tiocmget, 89 .tiocmget = belkin_sa_tiocmget,
90 .tiocmset = belkin_sa_tiocmset, 90 .tiocmset = belkin_sa_tiocmset,
91 .attach = belkin_sa_startup, 91 .port_probe = belkin_sa_port_probe,
92 .release = belkin_sa_release, 92 .port_remove = belkin_sa_port_remove,
93}; 93};
94 94
95static struct usb_serial_driver * const serial_drivers[] = { 95static struct usb_serial_driver * const serial_drivers[] = {
@@ -118,17 +118,15 @@ struct belkin_sa_private {
118 (c), BELKIN_SA_SET_REQUEST_TYPE, \ 118 (c), BELKIN_SA_SET_REQUEST_TYPE, \
119 (v), 0, NULL, 0, WDR_TIMEOUT) 119 (v), 0, NULL, 0, WDR_TIMEOUT)
120 120
121/* do some startup allocations not currently performed by usb_serial_probe() */ 121static int belkin_sa_port_probe(struct usb_serial_port *port)
122static int belkin_sa_startup(struct usb_serial *serial)
123{ 122{
124 struct usb_device *dev = serial->dev; 123 struct usb_device *dev = port->serial->dev;
125 struct belkin_sa_private *priv; 124 struct belkin_sa_private *priv;
126 125
127 /* allocate the private data structure */
128 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL); 126 priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL);
129 if (!priv) 127 if (!priv)
130 return -1; /* error */ 128 return -ENOMEM;
131 /* set initial values for control structures */ 129
132 spin_lock_init(&priv->lock); 130 spin_lock_init(&priv->lock);
133 priv->control_state = 0; 131 priv->control_state = 0;
134 priv->last_lsr = 0; 132 priv->last_lsr = 0;
@@ -140,18 +138,19 @@ static int belkin_sa_startup(struct usb_serial *serial)
140 le16_to_cpu(dev->descriptor.bcdDevice), 138 le16_to_cpu(dev->descriptor.bcdDevice),
141 priv->bad_flow_control); 139 priv->bad_flow_control);
142 140
143 init_waitqueue_head(&serial->port[0]->write_wait); 141 usb_set_serial_port_data(port, priv);
144 usb_set_serial_port_data(serial->port[0], priv);
145 142
146 return 0; 143 return 0;
147} 144}
148 145
149static void belkin_sa_release(struct usb_serial *serial) 146static int belkin_sa_port_remove(struct usb_serial_port *port)
150{ 147{
151 int i; 148 struct belkin_sa_private *priv;
152 149
153 for (i = 0; i < serial->num_ports; ++i) 150 priv = usb_get_serial_port_data(port);
154 kfree(usb_get_serial_port_data(serial->port[i])); 151 kfree(priv);
152
153 return 0;
155} 154}
156 155
157static int belkin_sa_open(struct tty_struct *tty, 156static int belkin_sa_open(struct tty_struct *tty,