aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2010-05-15 11:53:49 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-20 16:21:48 -0400
commit214916f2ec6701e1c9972f26c60b3dc37d3153c6 (patch)
treed3aa9b0e5d0861ff9b17fdd99982b639a6fe9c81
parent199b113978015309dd02c69844c19a1be3f4dbcf (diff)
USB: visor: reimplement using generic framework
Kill custom read and write implementations (dynamically allocated write urbs). Note that I chose to remove the stat module parameter which was supposed to keep count of the amount of data sent and received, but which has been broken for three years (since b308e74d9c708ee2a9af14fbe235e0a41216f4ed "USB: visor driver adapted to new tty buffering" -- bytes_in was incorrectly updated and was thus always reported as 0). Compile-only tested. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/usb/serial/visor.c342
1 files changed, 13 insertions, 329 deletions
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index fb7fc4068fb6..17fd8822d07f 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -38,17 +38,9 @@
38/* function prototypes for a handspring visor */ 38/* function prototypes for a handspring visor */
39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port); 39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port);
40static void visor_close(struct usb_serial_port *port); 40static void visor_close(struct usb_serial_port *port);
41static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
42 const unsigned char *buf, int count);
43static int visor_write_room(struct tty_struct *tty);
44static void visor_throttle(struct tty_struct *tty);
45static void visor_unthrottle(struct tty_struct *tty);
46static int visor_probe(struct usb_serial *serial, 41static int visor_probe(struct usb_serial *serial,
47 const struct usb_device_id *id); 42 const struct usb_device_id *id);
48static int visor_calc_num_ports(struct usb_serial *serial); 43static int visor_calc_num_ports(struct usb_serial *serial);
49static void visor_release(struct usb_serial *serial);
50static void visor_write_bulk_callback(struct urb *urb);
51static void visor_read_bulk_callback(struct urb *urb);
52static void visor_read_int_callback(struct urb *urb); 44static void visor_read_int_callback(struct urb *urb);
53static int clie_3_5_startup(struct usb_serial *serial); 45static int clie_3_5_startup(struct usb_serial *serial);
54static int treo_attach(struct usb_serial *serial); 46static int treo_attach(struct usb_serial *serial);
@@ -196,16 +188,11 @@ static struct usb_serial_driver handspring_device = {
196 .num_ports = 2, 188 .num_ports = 2,
197 .open = visor_open, 189 .open = visor_open,
198 .close = visor_close, 190 .close = visor_close,
199 .throttle = visor_throttle, 191 .throttle = usb_serial_generic_throttle,
200 .unthrottle = visor_unthrottle, 192 .unthrottle = usb_serial_generic_unthrottle,
201 .attach = treo_attach, 193 .attach = treo_attach,
202 .probe = visor_probe, 194 .probe = visor_probe,
203 .calc_num_ports = visor_calc_num_ports, 195 .calc_num_ports = visor_calc_num_ports,
204 .release = visor_release,
205 .write = visor_write,
206 .write_room = visor_write_room,
207 .write_bulk_callback = visor_write_bulk_callback,
208 .read_bulk_callback = visor_read_bulk_callback,
209 .read_int_callback = visor_read_int_callback, 196 .read_int_callback = visor_read_int_callback,
210}; 197};
211 198
@@ -221,16 +208,11 @@ static struct usb_serial_driver clie_5_device = {
221 .num_ports = 2, 208 .num_ports = 2,
222 .open = visor_open, 209 .open = visor_open,
223 .close = visor_close, 210 .close = visor_close,
224 .throttle = visor_throttle, 211 .throttle = usb_serial_generic_throttle,
225 .unthrottle = visor_unthrottle, 212 .unthrottle = usb_serial_generic_unthrottle,
226 .attach = clie_5_attach, 213 .attach = clie_5_attach,
227 .probe = visor_probe, 214 .probe = visor_probe,
228 .calc_num_ports = visor_calc_num_ports, 215 .calc_num_ports = visor_calc_num_ports,
229 .release = visor_release,
230 .write = visor_write,
231 .write_room = visor_write_room,
232 .write_bulk_callback = visor_write_bulk_callback,
233 .read_bulk_callback = visor_read_bulk_callback,
234 .read_int_callback = visor_read_int_callback, 216 .read_int_callback = visor_read_int_callback,
235}; 217};
236 218
@@ -246,38 +228,16 @@ static struct usb_serial_driver clie_3_5_device = {
246 .num_ports = 1, 228 .num_ports = 1,
247 .open = visor_open, 229 .open = visor_open,
248 .close = visor_close, 230 .close = visor_close,
249 .throttle = visor_throttle, 231 .throttle = usb_serial_generic_throttle,
250 .unthrottle = visor_unthrottle, 232 .unthrottle = usb_serial_generic_unthrottle,
251 .attach = clie_3_5_startup, 233 .attach = clie_3_5_startup,
252 .release = visor_release,
253 .write = visor_write,
254 .write_room = visor_write_room,
255 .write_bulk_callback = visor_write_bulk_callback,
256 .read_bulk_callback = visor_read_bulk_callback,
257}; 234};
258 235
259struct visor_private {
260 spinlock_t lock;
261 int bytes_in;
262 int bytes_out;
263 int outstanding_urbs;
264 unsigned char throttled;
265 unsigned char actually_throttled;
266};
267
268/* number of outstanding urbs to prevent userspace DoS from happening */
269#define URB_UPPER_LIMIT 42
270
271static int stats;
272
273/****************************************************************************** 236/******************************************************************************
274 * Handspring Visor specific driver functions 237 * Handspring Visor specific driver functions
275 ******************************************************************************/ 238 ******************************************************************************/
276static int visor_open(struct tty_struct *tty, struct usb_serial_port *port) 239static int visor_open(struct tty_struct *tty, struct usb_serial_port *port)
277{ 240{
278 struct usb_serial *serial = port->serial;
279 struct visor_private *priv = usb_get_serial_port_data(port);
280 unsigned long flags;
281 int result = 0; 241 int result = 0;
282 242
283 dbg("%s - port %d", __func__, port->number); 243 dbg("%s - port %d", __func__, port->number);
@@ -288,26 +248,10 @@ static int visor_open(struct tty_struct *tty, struct usb_serial_port *port)
288 return -ENODEV; 248 return -ENODEV;
289 } 249 }
290 250
291 spin_lock_irqsave(&priv->lock, flags);
292 priv->bytes_in = 0;
293 priv->bytes_out = 0;
294 priv->throttled = 0;
295 spin_unlock_irqrestore(&priv->lock, flags);
296
297 /* Start reading from the device */ 251 /* Start reading from the device */
298 usb_fill_bulk_urb(port->read_urb, serial->dev, 252 result = usb_serial_generic_open(tty, port);
299 usb_rcvbulkpipe(serial->dev, 253 if (result)
300 port->bulk_in_endpointAddress),
301 port->read_urb->transfer_buffer,
302 port->read_urb->transfer_buffer_length,
303 visor_read_bulk_callback, port);
304 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
305 if (result) {
306 dev_err(&port->dev,
307 "%s - failed submitting read urb, error %d\n",
308 __func__, result);
309 goto exit; 254 goto exit;
310 }
311 255
312 if (port->interrupt_in_urb) { 256 if (port->interrupt_in_urb) {
313 dbg("%s - adding interrupt input for treo", __func__); 257 dbg("%s - adding interrupt input for treo", __func__);
@@ -324,13 +268,12 @@ exit:
324 268
325static void visor_close(struct usb_serial_port *port) 269static void visor_close(struct usb_serial_port *port)
326{ 270{
327 struct visor_private *priv = usb_get_serial_port_data(port);
328 unsigned char *transfer_buffer; 271 unsigned char *transfer_buffer;
329 272
330 dbg("%s - port %d", __func__, port->number); 273 dbg("%s - port %d", __func__, port->number);
331 274
332 /* shutdown our urbs */ 275 /* shutdown our urbs */
333 usb_kill_urb(port->read_urb); 276 usb_serial_generic_close(port);
334 usb_kill_urb(port->interrupt_in_urb); 277 usb_kill_urb(port->interrupt_in_urb);
335 278
336 mutex_lock(&port->serial->disc_mutex); 279 mutex_lock(&port->serial->disc_mutex);
@@ -347,192 +290,6 @@ static void visor_close(struct usb_serial_port *port)
347 } 290 }
348 } 291 }
349 mutex_unlock(&port->serial->disc_mutex); 292 mutex_unlock(&port->serial->disc_mutex);
350
351 if (stats)
352 dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n",
353 priv->bytes_in, priv->bytes_out);
354}
355
356
357static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
358 const unsigned char *buf, int count)
359{
360 struct visor_private *priv = usb_get_serial_port_data(port);
361 struct usb_serial *serial = port->serial;
362 struct urb *urb;