diff options
author | Johan Hovold <jhovold@gmail.com> | 2012-10-17 10:31:33 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-10-17 16:48:00 -0400 |
commit | bf90ff5f3b8f67e5b42df4ea4fd543f8010a2676 (patch) | |
tree | b29ae0d832c7aa83b74e0c19c90eeb11b7027df2 /drivers/usb/serial | |
parent | 638b9e15233c9570bce65301aa9877235316b9f0 (diff) |
USB: spcp8x5: 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/usb/serial')
-rw-r--r-- | drivers/usb/serial/spcp8x5.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c index 9716efe92955..769c137f8975 100644 --- a/drivers/usb/serial/spcp8x5.c +++ b/drivers/usb/serial/spcp8x5.c | |||
@@ -157,13 +157,10 @@ struct spcp8x5_private { | |||
157 | u8 line_status; | 157 | u8 line_status; |
158 | }; | 158 | }; |
159 | 159 | ||
160 | /* desc : when device plug in,this function would be called. | 160 | static int spcp8x5_port_probe(struct usb_serial_port *port) |
161 | * thanks to usb_serial subsystem,then do almost every things for us. And what | ||
162 | * we should do just alloc the buffer */ | ||
163 | static int spcp8x5_startup(struct usb_serial *serial) | ||
164 | { | 161 | { |
162 | struct usb_serial *serial = port->serial; | ||
165 | struct spcp8x5_private *priv; | 163 | struct spcp8x5_private *priv; |
166 | int i; | ||
167 | enum spcp8x5_type type = SPCP825_007_TYPE; | 164 | enum spcp8x5_type type = SPCP825_007_TYPE; |
168 | u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); | 165 | u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); |
169 | 166 | ||
@@ -180,34 +177,27 @@ static int spcp8x5_startup(struct usb_serial *serial) | |||
180 | type = SPCP825_PHILIP_TYPE; | 177 | type = SPCP825_PHILIP_TYPE; |
181 | dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type); | 178 | dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type); |
182 | 179 | ||
183 | for (i = 0; i < serial->num_ports; ++i) { | 180 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
184 | priv = kzalloc(sizeof(struct spcp8x5_private), GFP_KERNEL); | 181 | if (!priv) |
185 | if (!priv) | 182 | return -ENOMEM; |
186 | goto cleanup; | ||
187 | 183 | ||
188 | spin_lock_init(&priv->lock); | 184 | spin_lock_init(&priv->lock); |
189 | init_waitqueue_head(&priv->delta_msr_wait); | 185 | init_waitqueue_head(&priv->delta_msr_wait); |
190 | priv->type = type; | 186 | priv->type = type; |
191 | usb_set_serial_port_data(serial->port[i] , priv); | 187 | |
192 | } | 188 | usb_set_serial_port_data(port , priv); |
193 | 189 | ||
194 | return 0; | 190 | return 0; |
195 | cleanup: | ||
196 | for (--i; i >= 0; --i) { | ||
197 | priv = usb_get_serial_port_data(serial->port[i]); | ||
198 | kfree(priv); | ||
199 | usb_set_serial_port_data(serial->port[i] , NULL); | ||
200 | } | ||
201 | return -ENOMEM; | ||
202 | } | 191 | } |
203 | 192 | ||
204 | /* call when the device plug out. free all the memory alloced by probe */ | 193 | static int spcp8x5_port_remove(struct usb_serial_port *port) |
205 | static void spcp8x5_release(struct usb_serial *serial) | ||
206 | { | 194 | { |
207 | int i; | 195 | struct spcp8x5_private *priv; |
208 | 196 | ||
209 | for (i = 0; i < serial->num_ports; i++) | 197 | priv = usb_get_serial_port_data(port); |
210 | kfree(usb_get_serial_port_data(serial->port[i])); | 198 | kfree(priv); |
199 | |||
200 | return 0; | ||
211 | } | 201 | } |
212 | 202 | ||
213 | /* set the modem control line of the device. | 203 | /* set the modem control line of the device. |
@@ -649,8 +639,8 @@ static struct usb_serial_driver spcp8x5_device = { | |||
649 | .ioctl = spcp8x5_ioctl, | 639 | .ioctl = spcp8x5_ioctl, |
650 | .tiocmget = spcp8x5_tiocmget, | 640 | .tiocmget = spcp8x5_tiocmget, |
651 | .tiocmset = spcp8x5_tiocmset, | 641 | .tiocmset = spcp8x5_tiocmset, |
652 | .attach = spcp8x5_startup, | 642 | .port_probe = spcp8x5_port_probe, |
653 | .release = spcp8x5_release, | 643 | .port_remove = spcp8x5_port_remove, |
654 | .process_read_urb = spcp8x5_process_read_urb, | 644 | .process_read_urb = spcp8x5_process_read_urb, |
655 | }; | 645 | }; |
656 | 646 | ||