Commit b9c52f15 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

cyberjack: Coding style

Coding style fixups
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ff7eb602
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include <linux/tty_flip.h> #include <linux/tty_flip.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
...@@ -65,7 +65,7 @@ static void cyberjack_close(struct tty_struct *tty, ...@@ -65,7 +65,7 @@ static void cyberjack_close(struct tty_struct *tty,
struct usb_serial_port *port, struct file *filp); struct usb_serial_port *port, struct file *filp);
static int cyberjack_write(struct tty_struct *tty, static int cyberjack_write(struct tty_struct *tty,
struct usb_serial_port *port, const unsigned char *buf, int count); struct usb_serial_port *port, const unsigned char *buf, int count);
static int cyberjack_write_room( struct tty_struct *tty); static int cyberjack_write_room(struct tty_struct *tty);
static void cyberjack_read_int_callback(struct urb *urb); static void cyberjack_read_int_callback(struct urb *urb);
static void cyberjack_read_bulk_callback(struct urb *urb); static void cyberjack_read_bulk_callback(struct urb *urb);
static void cyberjack_write_bulk_callback(struct urb *urb); static void cyberjack_write_bulk_callback(struct urb *urb);
...@@ -75,7 +75,7 @@ static struct usb_device_id id_table [] = { ...@@ -75,7 +75,7 @@ static struct usb_device_id id_table [] = {
{ } /* Terminating entry */ { } /* Terminating entry */
}; };
MODULE_DEVICE_TABLE (usb, id_table); MODULE_DEVICE_TABLE(usb, id_table);
static struct usb_driver cyberjack_driver = { static struct usb_driver cyberjack_driver = {
.name = "cyberjack", .name = "cyberjack",
...@@ -138,20 +138,20 @@ static int cyberjack_startup(struct usb_serial *serial) ...@@ -138,20 +138,20 @@ static int cyberjack_startup(struct usb_serial *serial)
for (i = 0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) {
int result; int result;
serial->port[i]->interrupt_in_urb->dev = serial->dev; serial->port[i]->interrupt_in_urb->dev = serial->dev;
result = usb_submit_urb(serial->port[i]->interrupt_in_urb, result = usb_submit_urb(serial->port[i]->interrupt_in_urb,
GFP_KERNEL); GFP_KERNEL);
if (result) if (result)
err(" usb_submit_urb(read int) failed"); err(" usb_submit_urb(read int) failed");
dbg("%s - usb_submit_urb(int urb)", __func__); dbg("%s - usb_submit_urb(int urb)", __func__);
} }
return( 0 ); return 0;
} }
static void cyberjack_shutdown(struct usb_serial *serial) static void cyberjack_shutdown(struct usb_serial *serial)
{ {
int i; int i;
dbg("%s", __func__); dbg("%s", __func__);
for (i = 0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) {
...@@ -161,7 +161,7 @@ static void cyberjack_shutdown(struct usb_serial *serial) ...@@ -161,7 +161,7 @@ static void cyberjack_shutdown(struct usb_serial *serial)
usb_set_serial_port_data(serial->port[i], NULL); usb_set_serial_port_data(serial->port[i], NULL);
} }
} }
static int cyberjack_open(struct tty_struct *tty, static int cyberjack_open(struct tty_struct *tty,
struct usb_serial_port *port, struct file *filp) struct usb_serial_port *port, struct file *filp)
{ {
...@@ -171,7 +171,7 @@ static int cyberjack_open(struct tty_struct *tty, ...@@ -171,7 +171,7 @@ static int cyberjack_open(struct tty_struct *tty,
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
dbg("%s - usb_clear_halt", __func__ ); dbg("%s - usb_clear_halt", __func__);
usb_clear_halt(port->serial->dev, port->write_urb->pipe); usb_clear_halt(port->serial->dev, port->write_urb->pipe);
/* force low_latency on so that our tty_push actually forces /* force low_latency on so that our tty_push actually forces
...@@ -230,7 +230,7 @@ static int cyberjack_write(struct tty_struct *tty, ...@@ -230,7 +230,7 @@ static int cyberjack_write(struct tty_struct *tty,
spin_lock_irqsave(&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) { if (count+priv->wrfilled > sizeof(priv->wrbuf)) {
/* To much data for buffer. Reset buffer. */ /* To much data for buffer. Reset buffer. */
priv->wrfilled = 0; priv->wrfilled = 0;
port->write_urb_busy = 0; port->write_urb_busy = 0;
...@@ -239,42 +239,43 @@ static int cyberjack_write(struct tty_struct *tty, ...@@ -239,42 +239,43 @@ static int cyberjack_write(struct tty_struct *tty,
} }
/* Copy data */ /* Copy data */
memcpy (priv->wrbuf+priv->wrfilled, buf, count); memcpy(priv->wrbuf + priv->wrfilled, buf, count);
usb_serial_debug_data(debug, &port->dev, __func__, count, usb_serial_debug_data(debug, &port->dev, __func__, count,
priv->wrbuf+priv->wrfilled); priv->wrbuf + priv->wrfilled);
priv->wrfilled += count; priv->wrfilled += count;
if( priv->wrfilled >= 3 ) { if (priv->wrfilled >= 3) {
wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
dbg("%s - expected data: %d", __func__, wrexpected); dbg("%s - expected data: %d", __func__, wrexpected);
} else { } else
wrexpected = sizeof(priv->wrbuf); wrexpected = sizeof(priv->wrbuf);
}
if( priv->wrfilled >= wrexpected ) { if (priv->wrfilled >= wrexpected) {
/* We have enough data to begin transmission */ /* We have enough data to begin transmission */
int length; int length;
dbg("%s - transmitting data (frame 1)", __func__); dbg("%s - transmitting data (frame 1)", __func__);
length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected; length = (wrexpected > port->bulk_out_size) ?
port->bulk_out_size : wrexpected;
memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length ); memcpy(port->write_urb->transfer_buffer, priv->wrbuf, length);
priv->wrsent=length; priv->wrsent = length;
/* set up our urb */ /* set up our urb */
usb_fill_bulk_urb(port->write_urb, serial->dev, usb_fill_bulk_urb(port->write_urb, serial->dev,
usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress), usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
port->write_urb->transfer_buffer, length, port->write_urb->transfer_buffer, length,
((serial->type->write_bulk_callback) ? ((serial->type->write_bulk_callback) ?
serial->type->write_bulk_callback : serial->type->write_bulk_callback :
cyberjack_write_bulk_callback), cyberjack_write_bulk_callback),
port); port);
/* send the data out the bulk port */ /* send the data out the bulk port */
result = usb_submit_urb(port->write_urb, GFP_ATOMIC); result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
if (result) { if (result) {
err("%s - failed submitting write urb, error %d", __func__, result); err("%s - failed submitting write urb, error %d",
__func__, result);
/* Throw away data. No better idea what to do with it. */ /* Throw away data. No better idea what to do with it. */
priv->wrfilled = 0; priv->wrfilled = 0;
priv->wrsent = 0; priv->wrsent = 0;
...@@ -283,12 +284,12 @@ static int cyberjack_write(struct tty_struct *tty, ...@@ -283,12 +284,12 @@ static int cyberjack_write(struct tty_struct *tty,
return 0; return 0;
} }
dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
if( priv->wrsent>=priv->wrfilled ) { if (priv->wrsent >= priv->wrfilled) {
dbg("%s - buffer cleaned", __func__); dbg("%s - buffer cleaned", __func__);
memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
priv->wrfilled = 0; priv->wrfilled = 0;
priv->wrsent = 0; priv->wrsent = 0;
} }
...@@ -296,8 +297,8 @@ static int cyberjack_write(struct tty_struct *tty, ...@@ -296,8 +297,8 @@ static int cyberjack_write(struct tty_struct *tty,
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
return (count); return count;
} }
static int cyberjack_write_room(struct tty_struct *tty) static int cyberjack_write_room(struct tty_struct *tty)
{ {
...@@ -319,10 +320,11 @@ static void cyberjack_read_int_callback(struct urb *urb) ...@@ -319,10 +320,11 @@ static void cyberjack_read_int_callback(struct urb *urb)
if (status) if (status)
return; return;
usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); usb_serial_debug_data(debug, &port->dev, __func__,
urb->actual_length, data);
/* React only to interrupts signaling a bulk_in transfer */ /* React only to interrupts signaling a bulk_in transfer */
if( (urb->actual_length == 4) && (data[0] == 0x01) ) { if (urb->actual_length == 4 && data[0] == 0x01) {
short old_rdtodo; short old_rdtodo;
/* This is a announcement of coming bulk_ins. */ /* This is a announcement of coming bulk_ins. */
...@@ -332,8 +334,8 @@ static void cyberjack_read_int_callback(struct urb *urb) ...@@ -332,8 +334,8 @@ static void cyberjack_read_int_callback(struct urb *urb)
old_rdtodo = priv->rdtodo; old_rdtodo = priv->rdtodo;
if( (old_rdtodo+size)<(old_rdtodo) ) { if (old_rdtodo + size < old_rdtodo) {
dbg( "To many bulk_in urbs to do." ); dbg("To many bulk_in urbs to do.");
spin_unlock(&priv->lock); spin_unlock(&priv->lock);
goto resubmit; goto resubmit;
} }
...@@ -345,10 +347,10 @@ static void cyberjack_read_int_callback(struct urb *urb) ...@@ -345,10 +347,10 @@ static void cyberjack_read_int_callback(struct urb *urb)
spin_unlock(&priv->lock); spin_unlock(&priv->lock);
if( !old_rdtodo ) { if (!old_rdtodo) {
port->read_urb->dev = port->serial->dev; port->read_urb->dev = port->serial->dev;
result = usb_submit_urb(port->read_urb, GFP_ATOMIC); result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if( result ) if (result)
err("%s - failed resubmitting read urb, error %d", __func__, result); err("%s - failed resubmitting read urb, error %d", __func__, result);
dbg("%s - usb_submit_urb(read urb)", __func__); dbg("%s - usb_submit_urb(read urb)", __func__);
} }
...@@ -374,7 +376,8 @@ static void cyberjack_read_bulk_callback(struct urb *urb) ...@@ -374,7 +376,8 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); usb_serial_debug_data(debug, &port->dev, __func__,
urb->actual_length, data);
if (status) { if (status) {
dbg("%s - nonzero read bulk status received: %d", dbg("%s - nonzero read bulk status received: %d",
__func__, status); __func__, status);
...@@ -389,15 +392,16 @@ static void cyberjack_read_bulk_callback(struct urb *urb) ...@@ -389,15 +392,16 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
if (urb->actual_length) { if (urb->actual_length) {
tty_buffer_request_room(tty, urb->actual_length); tty_buffer_request_room(tty, urb->actual_length);
tty_insert_flip_string(tty, data, urb->actual_length); tty_insert_flip_string(tty, data, urb->actual_length);
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
} }
spin_lock(&priv->lock); spin_lock(&priv->lock);
/* Reduce urbs to do by one. */ /* Reduce urbs to do by one. */
priv->rdtodo-=urb->actual_length; priv->rdtodo -= urb->actual_length;
/* Just to be sure */ /* Just to be sure */
if ( priv->rdtodo<0 ) priv->rdtodo = 0; if (priv->rdtodo < 0)
priv->rdtodo = 0;
todo = priv->rdtodo; todo = priv->rdtodo;
spin_unlock(&priv->lock); spin_unlock(&priv->lock);
...@@ -405,11 +409,12 @@ static void cyberjack_read_bulk_callback(struct urb *urb) ...@@ -405,11 +409,12 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
dbg("%s - rdtodo: %d", __func__, todo); dbg("%s - rdtodo: %d", __func__, todo);
/* Continue to read if we have still urbs to do. */ /* Continue to read if we have still urbs to do. */
if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) { if (todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/) {
port->read_urb->dev = port->serial->dev; port->read_urb->dev = port->serial->dev;
result = usb_submit_urb(port->read_urb, GFP_ATOMIC); result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (result) if (result)
err("%s - failed resubmitting read urb, error %d", __func__, result); err("%s - failed resubmitting read urb, error %d",
__func__, result);
dbg("%s - usb_submit_urb(read urb)", __func__); dbg("%s - usb_submit_urb(read urb)", __func__);
} }
} }
...@@ -432,7 +437,7 @@ static void cyberjack_write_bulk_callback(struct urb *urb) ...@@ -432,7 +437,7 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
spin_lock(&priv->lock); spin_lock(&priv->lock);
/* only do something if we have more data to send */ /* only do something if we have more data to send */
if( priv->wrfilled ) { if (priv->wrfilled) {
int length, blksize, result; int length, blksize, result;
dbg("%s - transmitting data (frame n)", __func__); dbg("%s - transmitting data (frame n)", __func__);
...@@ -440,37 +445,39 @@ static void cyberjack_write_bulk_callback(struct urb *urb) ...@@ -440,37 +445,39 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ? length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
port->bulk_out_size : (priv->wrfilled - priv->wrsent); port->bulk_out_size : (priv->wrfilled - priv->wrsent);
memcpy (port->write_urb->transfer_buffer, priv->wrbuf + priv->wrsent, memcpy(port->write_urb->transfer_buffer,
length ); priv->wrbuf + priv->wrsent, length);
priv->wrsent+=length; priv->wrsent += length;
/* set up our urb */ /* set up our urb */
usb_fill_bulk_urb(port->write_urb, port->serial->dev, usb_fill_bulk_urb(port->write_urb, port->serial->dev,
usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress), usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
port->write_urb->transfer_buffer, length, port->write_urb->transfer_buffer, length,
((port->serial->type->write_bulk_callback) ? ((port->serial->type->write_bulk_callback) ?
port->serial->type->write_bulk_callback : port->serial->type->write_bulk_callback :
cyberjack_write_bulk_callback), cyberjack_write_bulk_callback),
port); port);
/* send the data out the bulk port */ /* send the data out the bulk port */
result = usb_submit_urb(port->write_urb, GFP_ATOMIC); result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
if (result) { if (result) {
err("%s - failed submitting write urb, error %d", __func__, result); err("%s - failed submitting write urb, error %d",
__func__, result);
/* Throw away data. No better idea what to do with it. */ /* Throw away data. No better idea what to do with it. */
priv->wrfilled = 0; priv->wrfilled = 0;
priv->wrsent = 0; priv->wrsent = 0;
goto exit; goto exit;
} }
dbg("%s - priv->wrsent=%d", __func__,priv->wrsent); dbg("%s - priv->wrsent=%d", __func__, priv->wrsent);
dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled); dbg("%s - priv->wrfilled=%d", __func__, priv->wrfilled);
blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3; blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) { if (priv->wrsent >= priv->wrfilled ||
priv->wrsent >= blksize) {
dbg("%s - buffer cleaned", __func__); dbg("%s - buffer cleaned", __func__);
memset( priv->wrbuf, 0, sizeof(priv->wrbuf) ); memset(priv->wrbuf, 0, sizeof(priv->wrbuf));
priv->wrfilled = 0; priv->wrfilled = 0;
priv->wrsent = 0; priv->wrsent = 0;
} }
...@@ -481,14 +488,14 @@ static void cyberjack_write_bulk_callback(struct urb *urb) ...@@ -481,14 +488,14 @@ static void cyberjack_write_bulk_callback(struct urb *urb)
usb_serial_port_softint(port); usb_serial_port_softint(port);
} }
static int __init cyberjack_init (void) static int __init cyberjack_init(void)
{ {
int retval; int retval;
retval = usb_serial_register(&cyberjack_device); retval = usb_serial_register(&cyberjack_device);
if (retval) if (retval)
goto failed_usb_serial_register; goto failed_usb_serial_register;
retval = usb_register(&cyberjack_driver); retval = usb_register(&cyberjack_driver);
if (retval) if (retval)
goto failed_usb_register; goto failed_usb_register;
info(DRIVER_VERSION " " DRIVER_AUTHOR); info(DRIVER_VERSION " " DRIVER_AUTHOR);
...@@ -501,18 +508,18 @@ static int __init cyberjack_init (void) ...@@ -501,18 +508,18 @@ static int __init cyberjack_init (void)
return retval; return retval;
} }
static void __exit cyberjack_exit (void) static void __exit cyberjack_exit(void)
{ {
usb_deregister (&cyberjack_driver); usb_deregister(&cyberjack_driver);
usb_serial_deregister (&cyberjack_device); usb_serial_deregister(&cyberjack_device);
} }
module_init(cyberjack_init); module_init(cyberjack_init);
module_exit(cyberjack_exit); module_exit(cyberjack_exit);
MODULE_AUTHOR( DRIVER_AUTHOR ); MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION( DRIVER_DESC ); MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_VERSION( DRIVER_VERSION ); MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
module_param(debug, bool, S_IRUGO | S_IWUSR); module_param(debug, bool, S_IRUGO | S_IWUSR);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment