Re: [PATCH] usb: image: mdc800: fixed various style issues
From: Varka Bhadram
Date: Fri Apr 24 2015 - 05:56:17 EST
On 04/24/2015 05:29 AM, Jason Eastman wrote:
> Fixed several style issues with: comments, function perenthesis,
> indentation, and conditional braces
>
> Signed-off-by: Jason Eastman <eastman.jason.linux@xxxxxxxxx>
> ---
> drivers/usb/image/mdc800.c | 769 +++++++++++++++++++-------------------------
> 1 file changed, 336 insertions(+), 433 deletions(-)
>
> diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
> index 5cf2633..c9b9ec0 100644
> --- a/drivers/usb/image/mdc800.c
> +++ b/drivers/usb/image/mdc800.c
> @@ -29,19 +29,19 @@
> * mknod /dev/mustek c 180 32
> *
> * The driver supports only one camera.
> - *
> + *
> * Fix: mdc800 used sleep_on and slept with io_lock held.
> * Converted sleep_on to waitqueues with schedule_timeout and made io_lock
> * a semaphore from a spinlock.
> * by Oliver Neukum <oliver@xxxxxxxxxxx>
> * (02/12/2001)
> - *
> + *
> * Identify version on module load.
> * (08/04/2001) gb
> *
> * version 0.7.5
> * Fixed potential SMP races with Spinlocks.
> - * Thanks to Oliver Neukum <oliver@xxxxxxxxxxx> who
> + * Thanks to Oliver Neukum <oliver@xxxxxxxxxxx> who
> * noticed the race conditions.
> * (30/10/2000)
> *
> @@ -108,7 +108,7 @@
> #define DRIVER_DESC "USB Driver for Mustek MDC800 Digital Camera"
>
> /* Vendor and Product Information */
> -#define MDC800_VENDOR_ID 0x055f
> +#define MDC800_VENDOR_ID 0x055f
> #define MDC800_PRODUCT_ID 0xa800
>
> /* Timeouts (msec) */
> @@ -116,7 +116,7 @@
> #define TO_DOWNLOAD_GET_BUSY 1500
> #define TO_WRITE_GET_READY 1000
> #define TO_DEFAULT_COMMAND 5000
> -#define TO_READ_FROM_IRQ TO_DEFAULT_COMMAND
> +#define TO_READ_FROM_IRQ TO_DEFAULT_COMMAND
> #define TO_GET_READY TO_DEFAULT_COMMAND
>
> /* Minor Number of the device (create with mknod /dev/mustek c 180 32) */
> @@ -134,124 +134,119 @@ typedef enum {
>
>
> /* Data for the driver */
> -struct mdc800_data
> -{
> - struct usb_device * dev; // Device Data
> - mdc800_state state;
> +struct mdc800_data {
> + struct usb_device *dev; /* Device Data */
> + mdc800_state state;
>
> unsigned int endpoint [4];
>
> - struct urb * irq_urb;
> + struct urb *irq_urb;
> wait_queue_head_t irq_wait;
> int irq_woken;
> - char* irq_urb_buffer;
> + char *irq_urb_buffer;
>
> - int camera_busy; // is camera busy ?
> - int camera_request_ready; // Status to synchronize with irq
> - char camera_response [8]; // last Bytes send after busy
> + int camera_busy; /* is camera busy ? */
> + int camera_request_ready; /* Status to synchronize with irq */
> + char camera_response[8]; /* last Bytes send after busy */
>
> - struct urb * write_urb;
> - char* write_urb_buffer;
> + struct urb *write_urb;
> + char *write_urb_buffer;
> wait_queue_head_t write_wait;
> int written;
>
>
> - struct urb * download_urb;
> - char* download_urb_buffer;
> + struct urb *download_urb;
> + char *download_urb_buffer;
> wait_queue_head_t download_wait;
> int downloaded;
> - int download_left; // Bytes left to download ?
> + int download_left; /* Bytes left to download ? */
>
>
> /* Device Data */
> - char out [64]; // Answer Buffer
> - int out_ptr; // Index to the first not readen byte
> - int out_count; // Bytes in the buffer
> + char out[64]; /* Answer Buffer */
> + int out_ptr; /* Index to the first not readen byte */
> + int out_count; /* Bytes in the buffer */
>
> - int open; // Camera device open ?
> - struct mutex io_lock; // IO -lock
> + int open; /* Camera device open ? */
> + struct mutex io_lock; /* IO -lock */
>
> - char in [8]; // Command Input Buffer
> - int in_count;
> + char in[8]; /* Command Input Buffer */
> + int in_count;
>
> - int pic_index; // Cache for the Imagesize (-1 for nothing cached )
> + int pic_index; /* Cache for the Imagesize (-1 for nothing cached ) */
> int pic_len;
> int minor;
> };
>
>
> /* Specification of the Endpoints */
> -static struct usb_endpoint_descriptor mdc800_ed [4] =
> -{
> - {
> - .bLength = 0,
> +static struct usb_endpoint_descriptor mdc800_ed[4] = {
> + {
> + .bLength = 0,
> .bDescriptorType = 0,
> .bEndpointAddress = 0x01,
> - .bmAttributes = 0x02,
> + .bmAttributes = 0x02,
> .wMaxPacketSize = cpu_to_le16(8),
> - .bInterval = 0,
> - .bRefresh = 0,
> - .bSynchAddress = 0,
> + .bInterval = 0,
> + .bRefresh = 0,
> + .bSynchAddress = 0,
> },
> {
> - .bLength = 0,
> - .bDescriptorType = 0,
> - .bEndpointAddress = 0x82,
> - .bmAttributes = 0x03,
> - .wMaxPacketSize = cpu_to_le16(8),
> - .bInterval = 0,
> - .bRefresh = 0,
> - .bSynchAddress = 0,
> + .bLength = 0,
> + .bDescriptorType = 0,
> + .bEndpointAddress = 0x82,
> + .bmAttributes = 0x03,
> + .wMaxPacketSize = cpu_to_le16(8),
> + .bInterval = 0,
> + .bRefresh = 0,
> + .bSynchAddress = 0,
> },
> {
> - .bLength = 0,
> - .bDescriptorType = 0,
> - .bEndpointAddress = 0x03,
> - .bmAttributes = 0x02,
> - .wMaxPacketSize = cpu_to_le16(64),
> - .bInterval = 0,
> - .bRefresh = 0,
> - .bSynchAddress = 0,
> + .bLength = 0,
> + .bDescriptorType = 0,
> + .bEndpointAddress = 0x03,
> + .bmAttributes = 0x02,
> + .wMaxPacketSize = cpu_to_le16(64),
> + .bInterval = 0,
> + .bRefresh = 0,
> + .bSynchAddress = 0,
> },
> {
> - .bLength = 0,
> - .bDescriptorType = 0,
> - .bEndpointAddress = 0x84,
> - .bmAttributes = 0x02,
> - .wMaxPacketSize = cpu_to_le16(64),
> - .bInterval = 0,
> - .bRefresh = 0,
> - .bSynchAddress = 0,
> + .bLength = 0,
> + .bDescriptorType = 0,
> + .bEndpointAddress = 0x84,
> + .bmAttributes = 0x02,
> + .wMaxPacketSize = cpu_to_le16(64),
> + .bInterval = 0,
> + .bRefresh = 0,
> + .bSynchAddress = 0,
> },
> };
>
> /* The Variable used by the driver */
> -static struct mdc800_data* mdc800;
> +static struct mdc800_data *mdc800;
>
>
> /***************************************************************************
> The USB Part of the driver
> ****************************************************************************/
>
> -static int mdc800_endpoint_equals (struct usb_endpoint_descriptor *a,struct usb_endpoint_descriptor *b)
> +static int mdc800_endpoint_equals(struct usb_endpoint_descriptor *a, struct usb_endpoint_descriptor *b)
> {
> return (
> - ( a->bEndpointAddress == b->bEndpointAddress )
> - && ( a->bmAttributes == b->bmAttributes )
> - && ( a->wMaxPacketSize == b->wMaxPacketSize )
> + (a->bEndpointAddress == b->bEndpointAddress)
> + && (a->bmAttributes == b->bmAttributes)
> + && (a->wMaxPacketSize == b->wMaxPacketSize)
> );
> }
>
> -
> -/*
> - * Checks whether the camera responds busy
> - */
> -static int mdc800_isBusy (char* ch)
> +/* Checks whether the camera responds busy */
> +static int mdc800_isBusy(char *ch)
> {
> - int i=0;
> - while (i<8)
> - {
> - if (ch [i] != (char)0x99)
> + int i = 0;
> +
> + while (i < 8) {
> + if (ch[i] != (char)0x99)
> return 0;
> i++;
> }
> @@ -259,15 +254,13 @@ static int mdc800_isBusy (char* ch)
> }
>
>
> -/*
> - * Checks whether the Camera is ready
> - */
> -static int mdc800_isReady (char *ch)
> +/* Checks whether the Camera is ready */
> +static int mdc800_isReady(char *ch)
> {
> - int i=0;
> - while (i<8)
> - {
> - if (ch [i] != (char)0xbb)
> + int i = 0;
> +
> + while (i < 8) {
> + if (ch[i] != (char)0xbb)
> return 0;
> i++;
> }
> @@ -276,44 +269,36 @@ static int mdc800_isReady (char *ch)
>
>
>
> -/*
> - * USB IRQ Handler for InputLine
> - */
> -static void mdc800_usb_irq (struct urb *urb)
> +/* USB IRQ Handler for InputLine */
> +static void mdc800_usb_irq(struct urb *urb)
> {
> - int data_received=0, wake_up;
> - unsigned char* b=urb->transfer_buffer;
> - struct mdc800_data* mdc800=urb->context;
> + int data_received = 0, wake_up;
> + unsigned char *b = urb->transfer_buffer;
> + struct mdc800_data *mdc800 = urb->context;
> struct device *dev = &mdc800->dev->dev;
> int status = urb->status;
>
> if (status >= 0) {
> - if (mdc800_isBusy (b))
> - {
> - if (!mdc800->camera_busy)
> - {
> - mdc800->camera_busy=1;
> + if (mdc800_isBusy(b)) {
> + if (!mdc800->camera_busy) {
> + mdc800->camera_busy = 1;
> dev_dbg(dev, "gets busy\n");
> }
> - }
> - else
> - {
> - if (mdc800->camera_busy && mdc800_isReady (b))
> - {
> - mdc800->camera_busy=0;
> + } else {
> + if (mdc800->camera_busy && mdc800_isReady(b)) {
> + mdc800->camera_busy = 0;
> dev_dbg(dev, "gets ready\n");
> }
> }
> - if (!(mdc800_isBusy (b) || mdc800_isReady (b)))
> - {
> + if (!(mdc800_isBusy(b) || mdc800_isReady(b))) {
> /* Store Data in camera_answer field */
> - dev_dbg(dev, "%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]);
> + dev_dbg(dev, "%i %i %i %i %i %i %i %i\n", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
>
> - memcpy (mdc800->camera_response,b,8);
> - data_received=1;
> + memcpy(mdc800->camera_response, b, 8);
> + data_received = 1;
> }
> }
> - wake_up= ( mdc800->camera_request_ready > 0 )
> + wake_up = (mdc800->camera_request_ready > 0)
> &&
> (
> ((mdc800->camera_request_ready == 1) && (!mdc800->camera_busy))
> @@ -325,93 +310,82 @@ static void mdc800_usb_irq (struct urb *urb)
> (status < 0)
> );
>
> - if (wake_up)
> - {
> - mdc800->camera_request_ready=0;
> - mdc800->irq_woken=1;
> - wake_up (&mdc800->irq_wait);
> + if (wake_up) {
> + mdc800->camera_request_ready = 0;
> + mdc800->irq_woken = 1;
> + wake_up(&mdc800->irq_wait);
> }
> }
>
>
> -/*
> - * Waits a while until the irq responds that camera is ready
> - *
> - * mode : 0: Wait for camera gets ready
> - * 1: Wait for receiving data
> - * 2: Wait for camera gets busy
> - *
> - * msec: Time to wait
> - */
> -static int mdc800_usb_waitForIRQ (int mode, int msec)
> +/* Waits a while until the irq responds that camera is ready
> +
> + mode : 0: Wait for camera gets ready
> + 1: Wait for receiving data
> + 2: Wait for camera gets busy
> +
> + msec: Time to wait */
> +
> +static int mdc800_usb_waitForIRQ(int mode, int msec)
> {
> - mdc800->camera_request_ready=1+mode;
> + mdc800->camera_request_ready = 1+mode;
>
> wait_event_timeout(mdc800->irq_wait, mdc800->irq_woken,
> msecs_to_jiffies(msec));
> mdc800->irq_woken = 0;
>
> - if (mdc800->camera_request_ready>0)
> - {
> - mdc800->camera_request_ready=0;
> + if (mdc800->camera_request_ready > 0) {
> + mdc800->camera_request_ready = 0;
> dev_err(&mdc800->dev->dev, "timeout waiting for camera.\n");
> return -1;
> }
> -
> - if (mdc800->state == NOT_CONNECTED)
> - {
> - printk(KERN_WARNING "mdc800: Camera gets disconnected "
> - "during waiting for irq.\n");
> - mdc800->camera_request_ready=0;
> +
> + if (mdc800->state == NOT_CONNECTED) {
> + printk(KERN_WARNING "mdc800: Camera gets disconnected during waiting for irq.\n");
> + mdc800->camera_request_ready = 0;
> return -2;
> }
> -
> +
> return 0;
> }
>
>
> -/*
> - * The write_urb callback function
> - */
> -static void mdc800_usb_write_notify (struct urb *urb)
> +/* The write_urb callback function */
> +static void mdc800_usb_write_notify(struct urb *urb)
> {
> - struct mdc800_data* mdc800=urb->context;
> + struct mdc800_data *mdc800 = urb->context;
> int status = urb->status;
>
> if (status != 0)
> dev_err(&mdc800->dev->dev,
> "writing command fails (status=%i)\n", status);
> else
> - mdc800->state=READY;
> + mdc800->state = READY;
> mdc800->written = 1;
> - wake_up (&mdc800->write_wait);
> + wake_up(&mdc800->write_wait);
> }
>
>
> -/*
> - * The download_urb callback function
> - */
> -static void mdc800_usb_download_notify (struct urb *urb)
> +/* The download_urb callback function */
> +static void mdc800_usb_download_notify(struct urb *urb)
> {
> - struct mdc800_data* mdc800=urb->context;
> + struct mdc800_data *mdc800 = urb->context;
> int status = urb->status;
>
> if (status == 0) {
> /* Fill output buffer with these data */
> - memcpy (mdc800->out, urb->transfer_buffer, 64);
> - mdc800->out_count=64;
> - mdc800->out_ptr=0;
> - mdc800->download_left-=64;
> + memcpy(mdc800->out, urb->transfer_buffer, 64);
> + mdc800->out_count = 64;
> + mdc800->out_ptr = 0;
> + mdc800->download_left -= 64;
> if (mdc800->download_left == 0)
> - {
> - mdc800->state=READY;
> - }
> + mdc800->state = READY;
> } else {
> dev_err(&mdc800->dev->dev,
> "request bytes fails (status:%i)\n", status);
> }
> mdc800->downloaded = 1;
> - wake_up (&mdc800->download_wait);
> + wake_up(&mdc800->download_wait);
> }
>
>
> @@ -428,29 +402,25 @@ static struct usb_class_driver mdc800_class = {
> };
>
>
> -/*
> - * Callback to search the Mustek MDC800 on the USB Bus
> - */
> -static int mdc800_usb_probe (struct usb_interface *intf,
> +/* Callback to search the Mustek MDC800 on the USB Bus */
> +static int mdc800_usb_probe(struct usb_interface *intf,
> const struct usb_device_id *id)
> {
> - int i,j;
> + int i, j;
> struct usb_host_interface *intf_desc;
> - struct usb_device *dev = interface_to_usbdev (intf);
> - int irq_interval=0;
> + struct usb_device *dev = interface_to_usbdev(intf);
> + int irq_interval = 0;
> int retval;
>
> dev_dbg(&intf->dev, "(%s) called.\n", __func__);
>
>
> - if (mdc800->dev != NULL)
> - {
> + if (mdc800->dev != NULL) {
> dev_warn(&intf->dev, "only one Mustek MDC800 is supported.\n");
> return -ENODEV;
> }
>
> - if (dev->descriptor.bNumConfigurations != 1)
> - {
> + if (dev->descriptor.bNumConfigurations != 1) {
> dev_err(&intf->dev,
> "probe fails -> wrong Number of Configuration\n");
> return -ENODEV;
> @@ -458,33 +428,26 @@ static int mdc800_usb_probe (struct usb_interface *intf,
> intf_desc = intf->cur_altsetting;
>
> if (
> - ( intf_desc->desc.bInterfaceClass != 0xff )
> - || ( intf_desc->desc.bInterfaceSubClass != 0 )
> - || ( intf_desc->desc.bInterfaceProtocol != 0 )
> - || ( intf_desc->desc.bNumEndpoints != 4)
> - )
> - {
> + (intf_desc->desc.bInterfaceClass != 0xff)
> + || (intf_desc->desc.bInterfaceSubClass != 0)
> + || (intf_desc->desc.bInterfaceProtocol != 0)
> + || (intf_desc->desc.bNumEndpoints != 4)
> + ) {
> dev_err(&intf->dev, "probe fails -> wrong Interface\n");
> return -ENODEV;
> }
>
> /* Check the Endpoints */
> - for (i=0; i<4; i++)
> - {
> - mdc800->endpoint[i]=-1;
> - for (j=0; j<4; j++)
> - {
> - if (mdc800_endpoint_equals (&intf_desc->endpoint [j].desc,&mdc800_ed [i]))
> - {
> - mdc800->endpoint[i]=intf_desc->endpoint [j].desc.bEndpointAddress ;
> - if (i==1)
> - {
> - irq_interval=intf_desc->endpoint [j].desc.bInterval;
> - }
> + for (i = 0; i < 4; i++) {
> + mdc800->endpoint[i] = -1;
> + for (j = 0; j < 4; j++) {
> + if (mdc800_endpoint_equals(&intf_desc->endpoint[j].desc, &mdc800_ed[i])) {
> + mdc800->endpoint[i] = intf_desc->endpoint[j].desc.bEndpointAddress;
> + if (i == 1)
> + irq_interval = intf_desc->endpoint [j].desc.bInterval;
> }
> }
> - if (mdc800->endpoint[i] == -1)
> - {
> + if (mdc800->endpoint[i] == -1) {
> dev_err(&intf->dev, "probe fails -> Wrong Endpoints.\n");
> return -ENODEV;
> }
> @@ -502,14 +465,14 @@ static int mdc800_usb_probe (struct usb_interface *intf,
> return -ENODEV;
> }
>
> - mdc800->dev=dev;
> - mdc800->open=0;
> + mdc800->dev = dev;
> + mdc800->open = 0;
>
> /* Setup URB Structs */
> - usb_fill_int_urb (
> + usb_fill_int_urb(
> mdc800->irq_urb,
> mdc800->dev,
> - usb_rcvintpipe (mdc800->dev,mdc800->endpoint [1]),
> + usb_rcvintpipe(mdc800->dev, mdc800->endpoint[1]),
> mdc800->irq_urb_buffer,
> 8,
> mdc800_usb_irq,
> @@ -517,41 +480,39 @@ static int mdc800_usb_probe (struct usb_interface *intf,
> irq_interval
> );
>
> - usb_fill_bulk_urb (
> + usb_fill_bulk_urb(
> mdc800->write_urb,
> mdc800->dev,
> - usb_sndbulkpipe (mdc800->dev, mdc800->endpoint[0]),
> + usb_sndbulkpipe(mdc800->dev, mdc800->endpoint[0]),
> mdc800->write_urb_buffer,
> 8,
> mdc800_usb_write_notify,
> mdc800
> );
>
> - usb_fill_bulk_urb (
> + usb_fill_bulk_urb(
> mdc800->download_urb,
> mdc800->dev,
> - usb_rcvbulkpipe (mdc800->dev, mdc800->endpoint [3]),
> + usb_rcvbulkpipe(mdc800->dev, mdc800->endpoint[3]),
> mdc800->download_urb_buffer,
> 64,
> mdc800_usb_download_notify,
> mdc800
> );
>
> - mdc800->state=READY;
> + mdc800->state = READY;
>
> mutex_unlock(&mdc800->io_lock);
> -
> +
> usb_set_intfdata(intf, mdc800);
> return 0;
> }
>
>
> -/*
> - * Disconnect USB device (maybe the MDC800)
> - */
> -static void mdc800_usb_disconnect (struct usb_interface *intf)
> +/* Disconnect USB device (maybe the MDC800) */
> +static void mdc800_usb_disconnect(struct usb_interface *intf)
> {
> - struct mdc800_data* mdc800 = usb_get_intfdata(intf);
> + struct mdc800_data *mdc800 = usb_get_intfdata(intf);
>
> dev_dbg(&intf->dev, "(%s) called\n", __func__);
>
> @@ -564,7 +525,7 @@ static void mdc800_usb_disconnect (struct usb_interface *intf)
> /* must be under lock to make sure no URB
> is submitted after usb_kill_urb() */
> mutex_lock(&mdc800->io_lock);
> - mdc800->state=NOT_CONNECTED;
> + mdc800->state = NOT_CONNECTED;
>
> usb_kill_urb(mdc800->irq_urb);
> usb_kill_urb(mdc800->write_urb);
> @@ -582,71 +543,64 @@ static void mdc800_usb_disconnect (struct usb_interface *intf)
> The Misc device Part (file_operations)
> ****************************************************************************/
>
> -/*
> - * This Function calc the Answersize for a command.
> - */
> -static int mdc800_getAnswerSize (char command)
> +/* This Function calc the Answersize for a command. */
> +static int mdc800_getAnswerSize(char command)
> {
> - switch ((unsigned char) command)
> - {
> - case 0x2a:
> - case 0x49:
> - case 0x51:
> - case 0x0d:
> - case 0x20:
> - case 0x07:
> - case 0x01:
> - case 0x25:
> - case 0x00:
> - return 8;
> -
> - case 0x05:
> - case 0x3e:
> - return mdc800->pic_len;
> -
> - case 0x09:
> - return 4096;
> -
> - default:
> - return 0;
> + switch ((unsigned char) command) {
> + case 0x2a:
> + case 0x49:
> + case 0x51:
> + case 0x0d:
> + case 0x20:
> + case 0x07:
> + case 0x01:
> + case 0x25:
> + case 0x00:
> + return 8;
> +
> + case 0x05:
> + case 0x3e:
> + return mdc800->pic_len;
> +
> + case 0x09:
> + return 4096;
> +
> + default:
> + return 0;
> }
> }
>
>
> -/*
> - * Init the device: (1) alloc mem (2) Increase MOD Count ..
> - */
> -static int mdc800_device_open (struct inode* inode, struct file *file)
> +/* Init the device: (1) alloc mem (2) Increase MOD Count .. */
> +static int mdc800_device_open(struct inode *inode, struct file *file)
> {
> - int retval=0;
> - int errn=0;
> + int retval = 0;
> + int errn = 0;
>
> mutex_lock(&mdc800->io_lock);
> -
> - if (mdc800->state == NOT_CONNECTED)
> - {
> - errn=-EBUSY;
> +
> + if (mdc800->state == NOT_CONNECTED) {
> + errn = -EBUSY;
> goto error_out;
> }
> - if (mdc800->open)
> - {
> - errn=-EBUSY;
> + if (mdc800->open) {
> + errn = -EBUSY;
> goto error_out;
> }
>
> - mdc800->in_count=0;
> - mdc800->out_count=0;
> - mdc800->out_ptr=0;
> - mdc800->pic_index=0;
> - mdc800->pic_len=-1;
> - mdc800->download_left=0;
> + mdc800->in_count = 0;
> + mdc800->out_count = 0;
> + mdc800->out_ptr = 0;
> + mdc800->pic_index = 0;
> + mdc800->pic_len = -1;
> + mdc800->download_left = 0;
>
> - mdc800->camera_busy=0;
> - mdc800->camera_request_ready=0;
> + mdc800->camera_busy = 0;
> + mdc800->camera_request_ready = 0;
>
> - retval=0;
> + retval = 0;
> mdc800->irq_urb->dev = mdc800->dev;
> - retval = usb_submit_urb (mdc800->irq_urb, GFP_KERNEL);
> + retval = usb_submit_urb(mdc800->irq_urb, GFP_KERNEL);
> if (retval) {
> dev_err(&mdc800->dev->dev,
> "request USB irq fails (submit_retval=%i).\n", retval);
> @@ -654,7 +608,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
> goto error_out;
> }
>
> - mdc800->open=1;
> + mdc800->open = 1;
> dev_dbg(&mdc800->dev->dev, "Mustek MDC800 device opened.\n");
>
> error_out:
> @@ -663,24 +617,19 @@ error_out:
> }
>
>
> -/*
> - * Close the Camera and release Memory
> - */
> -static int mdc800_device_release (struct inode* inode, struct file *file)
> +/* Close the Camera and release Memory */
> +static int mdc800_device_release(struct inode *inode, struct file *file)
> {
> - int retval=0;
> + int retval = 0;
>
> mutex_lock(&mdc800->io_lock);
> - if (mdc800->open && (mdc800->state != NOT_CONNECTED))
> - {
> + if (mdc800->open && (mdc800->state != NOT_CONNECTED)) {
> usb_kill_urb(mdc800->irq_urb);
> usb_kill_urb(mdc800->write_urb);
> usb_kill_urb(mdc800->download_urb);
> - mdc800->open=0;
> - }
> - else
> - {
> - retval=-EIO;
> + mdc800->open = 0;
> + } else {
> + retval = -EIO;
> }
>
> mutex_unlock(&mdc800->io_lock);
> @@ -688,59 +637,48 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
> }
>
>
> -/*
> - * The Device read callback Function
> - */
> -static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t len, loff_t *pos)
> +/* The Device read callback Function */
> +static ssize_t mdc800_device_read(struct file *file, char __user *buf, size_t len, loff_t *pos)
> {
> - size_t left=len, sts=len; /* single transfer size */
> + size_t left = len, sts = len; /* single transfer size */
> char __user *ptr = buf;
> int retval;
>
> mutex_lock(&mdc800->io_lock);
> - if (mdc800->state == NOT_CONNECTED)
> - {
> + if (mdc800->state == NOT_CONNECTED) {
> mutex_unlock(&mdc800->io_lock);
> return -EBUSY;
> }
> - if (mdc800->state == WORKING)
> - {
> - printk(KERN_WARNING "mdc800: Illegal State \"working\""
> - "reached during read ?!\n");
> + if (mdc800->state == WORKING) {
> + printk(KERN_WARNING "mdc800: Illegal State \"working\" reached during read ?!\n");
> mutex_unlock(&mdc800->io_lock);
> return -EBUSY;
> }
> - if (!mdc800->open)
> - {
> + if (!mdc800->open) {
> mutex_unlock(&mdc800->io_lock);
> return -EBUSY;
> }
>
> - while (left)
> - {
> - if (signal_pending (current))
> - {
> + while (left) {
> + if (signal_pending(current)) {
> mutex_unlock(&mdc800->io_lock);
> return -EINTR;
> }
>
> - sts=left > (mdc800->out_count-mdc800->out_ptr)?mdc800->out_count-mdc800->out_ptr:left;
> + sts = left > (mdc800->out_count-mdc800->out_ptr)?mdc800->out_count-mdc800->out_ptr:left;
>
> - if (sts <= 0)
> - {
> + if (sts <= 0) {
> /* Too less Data in buffer */
> - if (mdc800->state == DOWNLOAD)
> - {
> - mdc800->out_count=0;
> - mdc800->out_ptr=0;
> + if (mdc800->state == DOWNLOAD) {
> + mdc800->out_count = 0;
> + mdc800->out_ptr = 0;
>
> /* Download -> Request new bytes */
> mdc800->download_urb->dev = mdc800->dev;
> - retval = usb_submit_urb (mdc800->download_urb, GFP_KERNEL);
> + retval = usb_submit_urb(mdc800->download_urb, GFP_KERNEL);
> if (retval) {
> dev_err(&mdc800->dev->dev,
> - "Can't submit download urb "
> - "(retval=%i)\n", retval);
> + "Can't submit download urb (retval=%i)\n", retval);
> mutex_unlock(&mdc800->io_lock);
> return len-left;
> }
> @@ -748,34 +686,28 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
> mdc800->downloaded,
> msecs_to_jiffies(TO_DOWNLOAD_GET_READY));
> mdc800->downloaded = 0;
> - if (mdc800->download_urb->status != 0)
> - {
> + if (mdc800->download_urb->status != 0) {
> dev_err(&mdc800->dev->dev,
> - "request download-bytes fails "
> - "(status=%i)\n",
> + "request download-bytes fails (status=%i)\n",
> mdc800->download_urb->status);
> mutex_unlock(&mdc800->io_lock);
> return len-left;
> }
> - }
> - else
> - {
> + } else {
> /* No more bytes -> that's an error*/
> mutex_unlock(&mdc800->io_lock);
> return -EIO;
> }
> - }
> - else
> - {
> + } else {
> /* Copy Bytes */
> - if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
> + if (copy_to_user(ptr, &mdc800->out[mdc800->out_ptr],
> sts)) {
> mutex_unlock(&mdc800->io_lock);
> return -EFAULT;
> }
> - ptr+=sts;
> - left-=sts;
> - mdc800->out_ptr+=sts;
> + ptr += sts;
> + left -= sts;
> + mdc800->out_ptr += sts;
> }
> }
>
> @@ -784,164 +716,141 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
> }
>
>
> -/*
> - * The Device write callback Function
> - * If a 8Byte Command is received, it will be send to the camera.
> - * After this the driver initiates the request for the answer or
> - * just waits until the camera becomes ready.
> - */
> -static ssize_t mdc800_device_write (struct file *file, const char __user *buf, size_t len, loff_t *pos)
> +/* The Device write callback Function
> + If a 8Byte Command is received, it will be send to the camera.
> + After this the driver initiates the request for the answer or
> + just waits until the camera becomes ready. */
> +static ssize_t mdc800_device_write(struct file *file, const char __user *buf, size_t len, loff_t *pos)
> {
> - size_t i=0;
> + size_t i = 0;
> int retval;
>
> mutex_lock(&mdc800->io_lock);
> - if (mdc800->state != READY)
> - {
> + if (mdc800->state != READY) {
> mutex_unlock(&mdc800->io_lock);
> return -EBUSY;
> }
> - if (!mdc800->open )
> - {
> + if (!mdc800->open) {
> mutex_unlock(&mdc800->io_lock);
> return -EBUSY;
> }
>
> - while (i<len)
> - {
> + while (i < len) {
> unsigned char c;
> - if (signal_pending (current))
> - {
> +
> + if (signal_pending(current)) {
> mutex_unlock(&mdc800->io_lock);
> return -EINTR;
> }
> -
> - if(get_user(c, buf+i))
> - {
> +
> + if (get_user(c, buf+i)) {
> mutex_unlock(&mdc800->io_lock);
> return -EFAULT;
> }
>
> /* check for command start */
> - if (c == 0x55)
> - {
> - mdc800->in_count=0;
> - mdc800->out_count=0;
> - mdc800->out_ptr=0;
> - mdc800->download_left=0;
> + if (c == 0x55) {
> + mdc800->in_count = 0;
> + mdc800->out_count = 0;
> + mdc800->out_ptr = 0;
> + mdc800->download_left = 0;
> }
>
> /* save command byte */
> - if (mdc800->in_count < 8)
> - {
> + if (mdc800->in_count < 8) {
> mdc800->in[mdc800->in_count] = c;
> mdc800->in_count++;
> - }
> - else
> - {
> + } else {
> mutex_unlock(&mdc800->io_lock);
> return -EIO;
> }
>
> /* Command Buffer full ? -> send it to camera */
> - if (mdc800->in_count == 8)
> - {
> + if (mdc800->in_count == 8) {
> int answersize;
>
> - if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
> - {
> + if (mdc800_usb_waitForIRQ(0, TO_GET_READY)) {
> dev_err(&mdc800->dev->dev,
> "Camera didn't get ready.\n");
> mutex_unlock(&mdc800->io_lock);
> return -EIO;
> }
>
> - answersize=mdc800_getAnswerSize (mdc800->in[1]);
> + answersize = mdc800_getAnswerSize(mdc800->in[1]);
>
> - mdc800->state=WORKING;
> - memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8);
> + mdc800->state = WORKING;
> + memcpy(mdc800->write_urb->transfer_buffer, mdc800->in, 8);
> mdc800->write_urb->dev = mdc800->dev;
> - retval = usb_submit_urb (mdc800->write_urb, GFP_KERNEL);
> + retval = usb_submit_urb(mdc800->write_urb, GFP_KERNEL);
> if (retval) {
> dev_err(&mdc800->dev->dev,
> - "submitting write urb fails "
> - "(retval=%i)\n", retval);
> + "submitting write urb fails (retval=%i)\n", retval);
> mutex_unlock(&mdc800->io_lock);
> return -EIO;
> }
> wait_event_timeout(mdc800->write_wait, mdc800->written,
> msecs_to_jiffies(TO_WRITE_GET_READY));
> mdc800->written = 0;
> - if (mdc800->state == WORKING)
> - {
> + if (mdc800->state == WORKING) {
> usb_kill_urb(mdc800->write_urb);
> mutex_unlock(&mdc800->io_lock);
> return -EIO;
> }
>
> - switch ((unsigned char) mdc800->in[1])
> - {
> - case 0x05: /* Download Image */
> - case 0x3e: /* Take shot in Fine Mode (WCam Mode) */
> - if (mdc800->pic_len < 0)
> - {
> - dev_err(&mdc800->dev->dev,
> - "call 0x07 before "
> - "0x05,0x3e\n");
> - mdc800->state=READY;
> - mutex_unlock(&mdc800->io_lock);
> - return -EIO;
> - }
> - mdc800->pic_len=-1;
> -
> - case 0x09: /* Download Thumbnail */
> - mdc800->download_left=answersize+64;
> - mdc800->state=DOWNLOAD;
> - mdc800_usb_waitForIRQ (0,TO_DOWNLOAD_GET_BUSY);
> - break;
> + switch ((unsigned char) mdc800->in[1]) {
> + case 0x05: /* Download Image */
> + case 0x3e: /* Take shot in Fine Mode (WCam Mode) */
> + if (mdc800->pic_len < 0) {
> + dev_err(&mdc800->dev->dev,
> + "call 0x07 before 0x05,0x3e\n");
> + mdc800->state = READY;
> + mutex_unlock(&mdc800->io_lock);
> + return -EIO;
> + }
> + mdc800->pic_len = -1;
>
> + case 0x09: /* Download Thumbnail */
> + mdc800->download_left = answersize+64;
> + mdc800->state = DOWNLOAD;
> + mdc800_usb_waitForIRQ(0, TO_DOWNLOAD_GET_BUSY);
> + break;
>
> - default:
> - if (answersize)
> - {
>
> - if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ))
> - {
> - dev_err(&mdc800->dev->dev, "requesting answer from irq fails\n");
> - mutex_unlock(&mdc800->io_lock);
> - return -EIO;
> - }
> + default:
> + if (answersize) {
>
> - /* Write dummy data, (this is ugly but part of the USB Protocol */
> - /* if you use endpoint 1 as bulk and not as irq) */
> - memcpy (mdc800->out, mdc800->camera_response,8);
> + if (mdc800_usb_waitForIRQ(1, TO_READ_FROM_IRQ)) {
> + dev_err(&mdc800->dev->dev, "requesting answer from irq fails\n");
> + mutex_unlock(&mdc800->io_lock);
> + return -EIO;
> + }
>
> - /* This is the interpreted answer */
> - memcpy (&mdc800->out[8], mdc800->camera_response,8);
> + /* Write dummy data, (this is ugly but part of the USB Protocol */
> + /* if you use endpoint 1 as bulk and not as irq) */
> + memcpy(mdc800->out, mdc800->camera_response, 8);
>
> - mdc800->out_ptr=0;
> - mdc800->out_count=16;
> + /* This is the interpreted answer */
> + memcpy(&mdc800->out[8], mdc800->camera_response, 8);
>
> - /* Cache the Imagesize, if command was getImageSize */
> - if (mdc800->in [1] == (char) 0x07)
> - {
> - mdc800->pic_len=(int) 65536*(unsigned char) mdc800->camera_response[0]+256*(unsigned char) mdc800->camera_response[1]+(unsigned char) mdc800->camera_response[2];
> + mdc800->out_ptr = 0;
> + mdc800->out_count = 16;
>
> - dev_dbg(&mdc800->dev->dev, "cached imagesize = %i\n", mdc800->pic_len);
> - }
> + /* Cache the Imagesize, if command was getImageSize */
> + if (mdc800->in[1] == (char) 0x07) {
> + mdc800->pic_len = (int) 65536*(unsigned char) mdc800->camera_response[0]+256*(unsigned char) mdc800->camera_response[1]+(unsigned char) mdc800->camera_response[2];
>
> + dev_dbg(&mdc800->dev->dev, "cached imagesize = %i\n", mdc800->pic_len);
> }
> - else
> - {
> - if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND))
> - {
> - dev_err(&mdc800->dev->dev, "Command Timeout.\n");
> - mutex_unlock(&mdc800->io_lock);
> - return -EIO;
> - }
> +
> + } else {
> + if (mdc800_usb_waitForIRQ(0, TO_DEFAULT_COMMAND)) {
> + dev_err(&mdc800->dev->dev, "Command Timeout.\n");
> + mutex_unlock(&mdc800->io_lock);
> + return -EIO;
> }
> - mdc800->state=READY;
> - break;
> + }
> + mdc800->state = READY;
> + break;
> }
> }
> i++;
> @@ -956,8 +865,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
> ****************************************************************************/
>
> /* File Operations of this drivers */
> -static const struct file_operations mdc800_device_ops =
> -{
> +static const struct file_operations mdc800_device_ops = {
> .owner = THIS_MODULE,
> .read = mdc800_device_read,
> .write = mdc800_device_write,
> @@ -973,12 +881,9 @@ static const struct usb_device_id mdc800_table[] = {
> { } /* Terminating entry */
> };
>
> -MODULE_DEVICE_TABLE (usb, mdc800_table);
> -/*
> - * USB Driver Struct for this device
> - */
> -static struct usb_driver mdc800_usb_driver =
> -{
> +MODULE_DEVICE_TABLE(usb, mdc800_table);
> +/* USB Driver Struct for this device */
> +static struct usb_driver mdc800_usb_driver = {
> .name = "mdc800",
> .probe = mdc800_usb_probe,
> .disconnect = mdc800_usb_disconnect,
> @@ -991,43 +896,43 @@ static struct usb_driver mdc800_usb_driver =
> Init and Cleanup this driver (Main Functions)
> *************************************************************************/
>
> -static int __init usb_mdc800_init (void)
> +static int __init usb_mdc800_init(void)
> {
> int retval = -ENODEV;
> /* Allocate Memory */
> - mdc800=kzalloc (sizeof (struct mdc800_data), GFP_KERNEL);
> + mdc800 = kzalloc(sizeof(struct mdc800_data), GFP_KERNEL);
> if (!mdc800)
> goto cleanup_on_fail;
>
> mdc800->dev = NULL;
> - mdc800->state=NOT_CONNECTED;
> - mutex_init (&mdc800->io_lock);
> + mdc800->state = NOT_CONNECTED;
> + mutex_init(&mdc800->io_lock);
>
> - init_waitqueue_head (&mdc800->irq_wait);
> - init_waitqueue_head (&mdc800->write_wait);
> - init_waitqueue_head (&mdc800->download_wait);
> + init_waitqueue_head(&mdc800->irq_wait);
> + init_waitqueue_head(&mdc800->write_wait);
> + init_waitqueue_head(&mdc800->download_wait);
>
> mdc800->irq_woken = 0;
> mdc800->downloaded = 0;
> mdc800->written = 0;
>
> - mdc800->irq_urb_buffer=kmalloc (8, GFP_KERNEL);
> + mdc800->irq_urb_buffer = kmalloc(8, GFP_KERNEL);
> if (!mdc800->irq_urb_buffer)
> goto cleanup_on_fail;
> - mdc800->write_urb_buffer=kmalloc (8, GFP_KERNEL);
> + mdc800->write_urb_buffer = kmalloc(8, GFP_KERNEL);
> if (!mdc800->write_urb_buffer)
> goto cleanup_on_fail;
> - mdc800->download_urb_buffer=kmalloc (64, GFP_KERNEL);
> + mdc800->download_urb_buffer = kmalloc(64, GFP_KERNEL);
> if (!mdc800->download_urb_buffer)
> goto cleanup_on_fail;
>
> - mdc800->irq_urb=usb_alloc_urb (0, GFP_KERNEL);
> + mdc800->irq_urb = usb_alloc_urb(0, GFP_KERNEL);
> if (!mdc800->irq_urb)
> goto cleanup_on_fail;
> - mdc800->download_urb=usb_alloc_urb (0, GFP_KERNEL);
> + mdc800->download_urb = usb_alloc_urb(0, GFP_KERNEL);
> if (!mdc800->download_urb)
> goto cleanup_on_fail;
> - mdc800->write_urb=usb_alloc_urb (0, GFP_KERNEL);
> + mdc800->write_urb = usb_alloc_urb(0, GFP_KERNEL);
> if (!mdc800->write_urb)
> goto cleanup_on_fail;
>
> @@ -1045,8 +950,7 @@ static int __init usb_mdc800_init (void)
>
> cleanup_on_fail:
>
> - if (mdc800 != NULL)
> - {
> + if (mdc800 != NULL) {
> printk(KERN_ERR "mdc800: can't alloc memory!\n");
>
> kfree(mdc800->download_urb_buffer);
> @@ -1057,33 +961,32 @@ cleanup_on_fail:
> usb_free_urb(mdc800->download_urb);
> usb_free_urb(mdc800->irq_urb);
>
> - kfree (mdc800);
> + kfree(mdc800);
> }
> mdc800 = NULL;
> return retval;
> }
>
>
> -static void __exit usb_mdc800_cleanup (void)
> +static void __exit usb_mdc800_cleanup(void)
> {
> - usb_deregister (&mdc800_usb_driver);
> + usb_deregister(&mdc800_usb_driver);
>
> - usb_free_urb (mdc800->irq_urb);
> - usb_free_urb (mdc800->download_urb);
> - usb_free_urb (mdc800->write_urb);
> + usb_free_urb(mdc800->irq_urb);
> + usb_free_urb(mdc800->download_urb);
> + usb_free_urb(mdc800->write_urb);
>
> - kfree (mdc800->irq_urb_buffer);
> - kfree (mdc800->write_urb_buffer);
> - kfree (mdc800->download_urb_buffer);
> + kfree(mdc800->irq_urb_buffer);
> + kfree(mdc800->write_urb_buffer);
> + kfree(mdc800->download_urb_buffer);
>
> - kfree (mdc800);
> + kfree(mdc800);
> mdc800 = NULL;
> }
>
> -module_init (usb_mdc800_init);
> -module_exit (usb_mdc800_cleanup);
> +module_init(usb_mdc800_init);
> +module_exit(usb_mdc800_cleanup);
>
> -MODULE_AUTHOR( DRIVER_AUTHOR );
> -MODULE_DESCRIPTION( DRIVER_DESC );
> +MODULE_AUTHOR(DRIVER_AUTHOR);
> +MODULE_DESCRIPTION(DRIVER_DESC);
> MODULE_LICENSE("GPL");
> -
Ran checkpatch on this.
Result:
total: 0 errors, 28 warnings, 1231 lines checked
0001-usb-image-mdc800-fixed-various-style-issues.patch has style problems, please review.
Thanks
--
Varka Bhadram
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/