aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r--drivers/usb/serial/spcp8x5.c46
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. 160static 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 */
163static 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;
195cleanup:
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 */ 193static int spcp8x5_port_remove(struct usb_serial_port *port)
205static 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