aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:10:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:23 -0400
commitb9c52f155f86eca9c4625b254b5f41dc151431be (patch)
tree8366bb49db4b5982960f18011011214e0ba22077
parentff7eb602605cc0100f089d57966fcd347e137137 (diff)
cyberjack: Coding style
Coding style fixups Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/usb/serial/cyberjack.c131
1 files changed, 69 insertions, 62 deletions
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 546178ea6f2d..b4d72351cb96 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -37,7 +37,7 @@
37#include <linux/tty_flip.h> 37#include <linux/tty_flip.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <asm/uaccess.h> 40#include <linux/uaccess.h>
41#include <linux/usb.h> 41#include <linux/usb.h>
42#include <linux/usb/serial.h> 42#include <linux/usb/serial.h>
43 43
@@ -65,7 +65,7 @@ static void cyberjack_close(struct tty_struct *tty,
65 struct usb_serial_port *port, struct file *filp); 65 struct usb_serial_port *port, struct file *filp);
66static int cyberjack_write(struct tty_struct *tty, 66static int cyberjack_write(struct tty_struct *tty,
67 struct usb_serial_port *port, const unsigned char *buf, int count); 67 struct usb_serial_port *port, const unsigned char *buf, int count);
68static int cyberjack_write_room( struct tty_struct *tty); 68static int cyberjack_write_room(struct tty_struct *tty);
69static void cyberjack_read_int_callback(struct urb *urb); 69static void cyberjack_read_int_callback(struct urb *urb);
70static void cyberjack_read_bulk_callback(struct urb *urb); 70static void cyberjack_read_bulk_callback(struct urb *urb);
71static void cyberjack_write_bulk_callback(struct urb *urb); 71static void cyberjack_write_bulk_callback(struct urb *urb);
@@ -75,7 +75,7 @@ static struct usb_device_id id_table [] = {
75 { } /* Terminating entry */ 75 { } /* Terminating entry */
76}; 76};
77 77
78MODULE_DEVICE_TABLE (usb, id_table); 78MODULE_DEVICE_TABLE(usb, id_table);
79 79
80static struct usb_driver cyberjack_driver = { 80static struct usb_driver cyberjack_driver = {
81 .name = "cyberjack", 81 .name = "cyberjack",
@@ -138,20 +138,20 @@ static int cyberjack_startup(struct usb_serial *serial)
138 for (i = 0; i < serial->num_ports; ++i) { 138 for (i = 0; i < serial->num_ports; ++i) {
139 int result; 139 int result;
140 serial->port[i]->interrupt_in_urb->dev = serial->dev; 140 serial->port[i]->interrupt_in_urb->dev = serial->dev;
141 result = usb_submit_urb(serial->port[i]->interrupt_in_urb, 141 result = usb_submit_urb(serial->port[i]->interrupt_in_urb,
142 GFP_KERNEL); 142 GFP_KERNEL);
143 if (result) 143 if (result)
144 err(" usb_submit_urb(read int) failed"); 144 err(" usb_submit_urb(read int) failed");
145 dbg("%s - usb_submit_urb(int urb)", __func__); 145 dbg("%s - usb_submit_urb(int urb)", __func__);
146 } 146 }
147 147
148 return( 0 ); 148 return 0;
149} 149}
150 150
151static void cyberjack_shutdown(struct usb_serial *serial) 151static void cyberjack_shutdown(struct usb_serial *serial)
152{ 152{
153 int i; 153 int i;
154 154
155 dbg("%s", __func__); 155 dbg("%s", __func__);
156 156
157 for (i = 0; i < serial->num_ports; ++i) { 157 for (i = 0; i < serial->num_ports; ++i) {
@@ -161,7 +161,7 @@ static void cyberjack_shutdown(struct usb_serial *serial)
161 usb_set_serial_port_data(serial->port[i], NULL); 161 usb_set_serial_port_data(serial->port[i], NULL);
162 } 162 }
163} 163}
164 164
165static int cyberjack_open(struct tty_struct *tty, 165static int cyberjack_open(struct tty_struct *tty,
166 struct usb_serial_port *port, struct file *filp) 166 struct usb_serial_port *port, struct file *filp)
167{ 167{
@@ -171,7 +171,7 @@ static int cyberjack_open(struct tty_struct *tty,
171 171
172 dbg("%s - port %d", __func__, port->number); 172 dbg("%s - port %d", __func__, port->number);
173 173
174 dbg("%s - usb_clear_halt", __func__ ); 174 dbg("%s - usb_clear_halt", __func__);
175 usb_clear_halt(port->serial->dev, port->write_urb->pipe); 175 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
176 176
177 /* force low_latency on so that our tty_push actually forces 177 /* force low_latency on so that our tty_push actually forces
@@ -230,7 +230,7 @@ static int cyberjack_write(struct tty_struct *tty,
230 230
231 spin_lock_irqsave(&priv->lock, flags); 231 spin_lock_irqsave(&priv->lock, flags);
232 232
233 if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) { 233 if (count+priv->wrfilled > sizeof(priv->wrbuf)) {
234 /* To much data for buffer. Reset buffer. */ 234 /* To much data for buffer. Reset buffer. */
235 priv->wrfilled = 0; 235 priv->wrfilled = 0;
236 port->write_urb_busy = 0; 236 port->write_urb_busy = 0;
@@ -239,42 +239,43 @@ static int cyberjack_write(struct tty_struct *tty,
239 } 239 }
240 240
241 /* Copy data */ 241 /* Copy data */
242 memcpy (priv->wrbuf+priv->wrfilled, buf, count); 242 memcpy(priv->wrbuf + priv->wrfilled, buf, count);
243 243
244 usb_serial_debug_data(debug, &port->dev, __func__, count, 244 usb_serial_debug_data(debug, &port->dev, __func__, count,
245 priv->wrbuf+priv->wrfilled); 245 priv->wrbuf + priv->wrfilled);
246 priv->wrfilled += count; 246 priv->wrfilled += count;
247 247
248 if( priv->wrfilled >= 3 ) { 248 if (priv->wrfilled >= 3) {
249 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 249 wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
250 dbg("%s - expected data: %d", __func__, wrexpected); 250 dbg("%s - expected data: %d", __func__, wrexpected);
251 } else { 251 } else
252 wrexpected = sizeof(priv->wrbuf); 252 wrexpected = sizeof(priv->wrbuf);
253 }
254 253
255 if( priv->wrfilled >= wrexpected ) { 254 if (priv->wrfilled >= wrexpected) {
256 /* We have enough data to begin transmission */ 255 /* We have enough data to begin transmission */
257 int length; 256 int length;
258 257
259 dbg("%s - transmitting data (frame 1)", __func__); 258 dbg("%s - transmitting data (frame 1)", __func__);
260 length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected; 259 length = (wrexpected > port->bulk_out_size) ?
260 port->bulk_out_size : wrexpected;
261 261
262 memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length ); 262 memcpy(port->write_urb->transfer_buffer, priv->wrbuf, length);
263 priv->wrsent=length; 263 priv->wrsent = length;
264 264
265 /* set up our urb */ 265 /* set up our urb */
266 usb_fill_bulk_urb(port->write_urb, serial->dev, 266 usb_fill_bulk_urb(port->write_urb, serial->dev,
267 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), 267 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
268 port->write_urb->transfer_buffer, length, 268 port->write_urb->transfer_buffer, length,
269 ((serial->type->write_bulk_callback) ? 269 ((serial->type->write_bulk_callback) ?
270 serial->type->write_bulk_callback : 270 serial->type->write_bulk_callback :
271 cyberjack_write_bulk_callback), 271 cyberjack_write_bulk_callback),
272 port); 272 port);
273 273
274 /* send the data out the bulk port */ 274 /* send the data out the bulk port */
275 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 275 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
276 if (result) { 276 if (result) {
277 err("%s - failed submitting write urb, error %d", __func__, result); 277 err("%s - failed submitting write urb, error %d",
278 __func__, result);
278 /* Throw away data. No better idea what to do with it. */ 279 /* Throw away data. No better idea what to do with it. */
279 priv->wrfilled = 0; 280 priv->wrfilled = 0;
280 priv->wrsent = 0; 281 priv->wrsent = 0;
@@ -283,12 +284,12 @@ static int cyberjack_write(struct tty_struct *tty,
283 return 0; 284 return 0;
284 } 285 }
285 286
286 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); 287 dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
287 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); 288 dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
288 289
289 if( priv->wrsent>=priv->wrfilled ) { 290 if (priv->wrsent >= priv->wrfilled) {
290 dbg("%s - buffer cleaned", __func__); 291 dbg("%s - buffer cleaned", __func__);
291 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 292 memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
292 priv->wrfilled = 0; 293 priv->wrfilled = 0;
293 priv->wrsent = 0; 294 priv->wrsent = 0;
294 } 295 }
@@ -296,8 +297,8 @@ static int cyberjack_write(struct tty_struct *tty,
296 297
297 spin_unlock_irqrestore(&priv->lock, flags); 298 spin_unlock_irqrestore(&priv->lock, flags);
298 299
299 return (count); 300 return count;
300} 301}
301 302
302static int cyberjack_write_room(struct tty_struct *tty) 303static int cyberjack_write_room(struct tty_struct *tty)
303{ 304{
@@ -319,10 +320,11 @@ static void cyberjack_read_int_callback(struct urb *urb)
319 if (status) 320 if (status)
320 return; 321 return;
321 322
322 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 323 usb_serial_debug_data(debug, &port->dev, __func__,
324 urb->actual_length, data);
323 325
324 /* React only to interrupts signaling a bulk_in transfer */ 326 /* React only to interrupts signaling a bulk_in transfer */
325 if( (urb->actual_length == 4) && (data[0] == 0x01) ) { 327 if (urb->actual_length == 4 && data[0] == 0x01) {
326 short old_rdtodo; 328 short old_rdtodo;
327 329
328 /* This is a announcement of coming bulk_ins. */ 330 /* This is a announcement of coming bulk_ins. */
@@ -332,8 +334,8 @@ static void cyberjack_read_int_callback(struct urb *urb)
332 334
333 old_rdtodo = priv->rdtodo; 335 old_rdtodo = priv->rdtodo;
334 336
335 if( (old_rdtodo+size)<(old_rdtodo) ) { 337 if (old_rdtodo + size < old_rdtodo) {
336 dbg( "To many bulk_in urbs to do." ); 338 dbg("To many bulk_in urbs to do.");
337 spin_unlock(&priv->lock); 339 spin_unlock(&priv->lock);
338 goto resubmit; 340 goto resubmit;
339 } 341 }
@@ -345,10 +347,10 @@ static void cyberjack_read_int_callback(struct urb *urb)
345 347
346 spin_unlock(&priv->lock); 348 spin_unlock(&priv->lock);
347 349
348 if( !old_rdtodo ) { 350 if (!old_rdtodo) {
349 port->read_urb->dev = port->serial->dev; 351 port->read_urb->dev = port->serial->dev;
350 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 352 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
351 if( result ) 353 if (result)
352 err("%s - failed resubmitting read urb, error %d", __func__, result); 354 err("%s - failed resubmitting read urb, error %d", __func__, result);
353 dbg("%s - usb_submit_urb(read urb)", __func__); 355 dbg("%s - usb_submit_urb(read urb)", __func__);
354 } 356 }
@@ -374,7 +376,8 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
374 376
375 dbg("%s - port %d", __func__, port->number); 377 dbg("%s - port %d", __func__, port->number);
376 378
377 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 379 usb_serial_debug_data(debug, &port->dev, __func__,
380 urb->actual_length, data);
378 if (status) { 381 if (status) {
379 dbg("%s - nonzero read bulk status received: %d", 382 dbg("%s - nonzero read bulk status received: %d",
380 __func__, status); 383 __func__, status);
@@ -389,15 +392,16 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
389 if (urb->actual_length) { 392 if (urb->actual_length) {
390 tty_buffer_request_room(tty, urb->actual_length); 393 tty_buffer_request_room(tty, urb->actual_length);
391 tty_insert_flip_string(tty, data, urb->actual_length); 394 tty_insert_flip_string(tty, data, urb->actual_length);
392 tty_flip_buffer_push(tty); 395 tty_flip_buffer_push(tty);
393 } 396 }
394 397
395 spin_lock(&priv->lock); 398 spin_lock(&priv->lock);
396 399
397 /* Reduce urbs to do by one. */ 400 /* Reduce urbs to do by one. */
398 priv->rdtodo-=urb->actual_length; 401 priv->rdtodo -= urb->actual_length;
399 /* Just to be sure */ 402 /* Just to be sure */
400 if ( priv->rdtodo<0 ) priv->rdtodo = 0; 403 if (priv->rdtodo < 0)
404 priv->rdtodo = 0;
401 todo = priv->rdtodo; 405 todo = priv->rdtodo;
402 406
403 spin_unlock(&priv->lock); 407 spin_unlock(&priv->lock);
@@ -405,11 +409,12 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
405 dbg("%s - rdtodo: %d", __func__, todo); 409 dbg("%s - rdtodo: %d", __func__, todo);
406 410
407 /* Continue to read if we have still urbs to do. */ 411 /* Continue to read if we have still urbs to do. */
408 if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) { 412 if (todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/) {
409 port->read_urb->dev = port->serial->dev; 413 port->read_urb->dev = port->serial->dev;
410 result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 414 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
411 if (result) 415 if (result)
412 err("%s - failed resubmitting read urb, error %d", __func__, result); 416 err("%s - failed resubmitting read urb, error %d",
417 __func__, result);
413 dbg("%s - usb_submit_urb(read urb)", __func__); 418 dbg("%s - usb_submit_urb(read urb)", __func__);
414 } 419 }
415} 420}
@@ -432,7 +437,7 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
432 spin_lock(&priv->lock); 437 spin_lock(&priv->lock);
433 438
434 /* only do something if we have more data to send */ 439 /* only do something if we have more data to send */
435 if( priv->wrfilled ) { 440 if (priv->wrfilled) {
436 int length, blksize, result; 441 int length, blksize, result;
437 442
438 dbg("%s - transmitting data (frame n)", __func__); 443 dbg("%s - transmitting data (frame n)", __func__);
@@ -440,37 +445,39 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
440 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? 445 length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
441 port->bulk_out_size : (priv->wrfilled - priv->wrsent); 446 port->bulk_out_size : (priv->wrfilled - priv->wrsent);
442 447
443 memcpy (port->write_urb->transfer_buffer, priv->wrbuf + priv->wrsent, 448 memcpy(port->write_urb->transfer_buffer,
444 length ); 449 priv->wrbuf + priv->wrsent, length);
445 priv->wrsent+=length; 450 priv->wrsent += length;
446 451
447 /* set up our urb */ 452 /* set up our urb */
448 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 453 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
449 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), 454 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
450 port->write_urb->transfer_buffer, length, 455 port->write_urb->transfer_buffer, length,
451 ((port->serial->type->write_bulk_callback) ? 456 ((port->serial->type->write_bulk_callback) ?
452 port->serial->type->write_bulk_callback : 457 port->serial->type->write_bulk_callback :
453 cyberjack_write_bulk_callback), 458 cyberjack_write_bulk_callback),
454 port); 459 port);
455 460
456 /* send the data out the bulk port */ 461 /* send the data out the bulk port */
457 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 462 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
458 if (result) { 463 if (result) {
459 err("%s - failed submitting write urb, error %d", __func__, result); 464 err("%s - failed submitting write urb, error %d",
465 __func__, result);
460 /* Throw away data. No better idea what to do with it. */ 466 /* Throw away data. No better idea what to do with it. */
461 priv->wrfilled = 0; 467 priv->wrfilled = 0;
462 priv->wrsent = 0; 468 priv->wrsent = 0;
463 goto exit; 469 goto exit;
464 } 470 }
465 471
466 dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); 472 dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
467 dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); 473 dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
468 474
469 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; 475 blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
470 476
471 if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) { 477 if (priv->wrsent >= priv->wrfilled ||
478 priv->wrsent >= blksize) {
472 dbg("%s - buffer cleaned", __func__); 479 dbg("%s - buffer cleaned", __func__);
473 memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); 480 memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
474 priv->wrfilled = 0; 481 priv->wrfilled = 0;
475 priv->wrsent = 0; 482 priv->wrsent = 0;
476 } 483 }
@@ -481,14 +488,14 @@ exit:
481 usb_serial_port_softint(port); 488 usb_serial_port_softint(port);
482} 489}
483 490
484static int __init cyberjack_init (void) 491static int __init cyberjack_init(void)
485{ 492{
486 int retval; 493 int retval;
487 retval = usb_serial_register(&cyberjack_device); 494 retval = usb_serial_register(&cyberjack_device);
488 if (retval) 495 if (retval)
489 goto failed_usb_serial_register; 496 goto failed_usb_serial_register;
490 retval = usb_register(&cyberjack_driver); 497 retval = usb_register(&cyberjack_driver);
491 if (retval) 498 if (retval)
492 goto failed_usb_register; 499 goto failed_usb_register;
493 500
494 info(DRIVER_VERSION " " DRIVER_AUTHOR); 501 info(DRIVER_VERSION " " DRIVER_AUTHOR);
@@ -501,18 +508,18 @@ failed_usb_serial_register:
501 return retval; 508 return retval;
502} 509}
503 510
504static void __exit cyberjack_exit (void) 511static void __exit cyberjack_exit(void)
505{ 512{
506 usb_deregister (&cyberjack_driver); 513 usb_deregister(&cyberjack_driver);
507 usb_serial_deregister (&cyberjack_device); 514 usb_serial_deregister(&cyberjack_device);
508} 515}
509 516
510module_init(cyberjack_init); 517module_init(cyberjack_init);
511module_exit(cyberjack_exit); 518module_exit(cyberjack_exit);
512 519
513MODULE_AUTHOR( DRIVER_AUTHOR ); 520MODULE_AUTHOR(DRIVER_AUTHOR);
514MODULE_DESCRIPTION( DRIVER_DESC ); 521MODULE_DESCRIPTION(DRIVER_DESC);
515MODULE_VERSION( DRIVER_VERSION ); 522MODULE_VERSION(DRIVER_VERSION);
516MODULE_LICENSE("GPL"); 523MODULE_LICENSE("GPL");
517 524
518module_param(debug, bool, S_IRUGO | S_IWUSR); 525module_param(debug, bool, S_IRUGO | S_IWUSR);