staging: comedi: dt9812: tidy up usb_bulk_msg() calls
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 14 May 2013 21:22:39 +0000 (14:22 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 16 May 2013 23:25:54 +0000 (16:25 -0700)
To clarify the code, add a local variable for the struct usb_device
pointer used in the usb_blk_msg() calls.

It's not necessary to initialize the 'count' when writing to the
usb device. The 'count' variable is used to get back the number
of bytes actually sent.

Just return the usb_blk_msg() result when it is the last operation
in a function.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/dt9812.c

index b797517e2ddbb4a8789820a4ac233cdc38914d55..17a738c86b8861abc548d27f01f7f96e9102e33d 100644 (file)
@@ -307,8 +307,9 @@ static void dt9812_delete(struct kref *kref)
 static int dt9812_read_info(struct usb_dt9812 *dev, int offset, void *buf,
                            size_t buf_size)
 {
+       struct usb_device *usb = dev->udev;
        struct dt9812_usb_cmd cmd;
-       int count, retval;
+       int count, ret;
 
        cmd.cmd = cpu_to_le32(DT9812_R_FLASH_DATA);
        cmd.u.flash_data_info.address =
@@ -316,25 +317,21 @@ static int dt9812_read_info(struct usb_dt9812 *dev, int offset, void *buf,
        cmd.u.flash_data_info.numbytes = cpu_to_le16(buf_size);
 
        /* DT9812 only responds to 32 byte writes!! */
-       count = 32;
-       retval = usb_bulk_msg(dev->udev,
-                             usb_sndbulkpipe(dev->udev,
-                                             dev->command_write.addr),
-                             &cmd, 32, &count, HZ * 1);
-       if (retval)
-               return retval;
-       retval = usb_bulk_msg(dev->udev,
-                             usb_rcvbulkpipe(dev->udev,
-                                             dev->command_read.addr),
-                             buf, buf_size, &count, HZ * 1);
-       return retval;
+       ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, dev->command_write.addr),
+                          &cmd, 32, &count, HZ * 1);
+       if (ret)
+               return ret;
+
+       return usb_bulk_msg(usb, usb_rcvbulkpipe(usb, dev->command_read.addr),
+                           buf, buf_size, &count, HZ * 1);
 }
 
 static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count,
                                          u8 *address, u8 *value)
 {
+       struct usb_device *usb = dev->udev;
        struct dt9812_usb_cmd cmd;
-       int i, count, retval;
+       int i, count, ret;
 
        cmd.cmd = cpu_to_le32(DT9812_R_MULTI_BYTE_REG);
        cmd.u.read_multi_info.count = reg_count;
@@ -342,26 +339,22 @@ static int dt9812_read_multiple_registers(struct usb_dt9812 *dev, int reg_count,
                cmd.u.read_multi_info.address[i] = address[i];
 
        /* DT9812 only responds to 32 byte writes!! */
-       count = 32;
-       retval = usb_bulk_msg(dev->udev,
-                             usb_sndbulkpipe(dev->udev,
-                                             dev->command_write.addr),
-                             &cmd, 32, &count, HZ * 1);
-       if (retval)
-               return retval;
-       retval = usb_bulk_msg(dev->udev,
-                             usb_rcvbulkpipe(dev->udev,
-                                             dev->command_read.addr),
-                             value, reg_count, &count, HZ * 1);
-       return retval;
+       ret = usb_bulk_msg(usb, usb_sndbulkpipe(usb, dev->command_write.addr),
+                          &cmd, 32, &count, HZ * 1);
+       if (ret)
+               return ret;
+
+       return usb_bulk_msg(usb, usb_rcvbulkpipe(usb, dev->command_read.addr),
+                           value, reg_count, &count, HZ * 1);
 }
 
 static int dt9812_write_multiple_registers(struct usb_dt9812 *dev,
                                           int reg_count, u8 *address,
                                           u8 *value)
 {
+       struct usb_device *usb = dev->udev;
        struct dt9812_usb_cmd cmd;
-       int i, count, retval;
+       int i, count;
 
        cmd.cmd = cpu_to_le32(DT9812_W_MULTI_BYTE_REG);
        cmd.u.read_multi_info.count = reg_count;
@@ -369,19 +362,18 @@ static int dt9812_write_multiple_registers(struct usb_dt9812 *dev,
                cmd.u.write_multi_info.write[i].address = address[i];
                cmd.u.write_multi_info.write[i].value = value[i];
        }
+
        /* DT9812 only responds to 32 byte writes!! */
-       retval = usb_bulk_msg(dev->udev,
-                             usb_sndbulkpipe(dev->udev,
-                                             dev->command_write.addr),
-                             &cmd, 32, &count, HZ * 1);
-       return retval;
+       return usb_bulk_msg(usb, usb_sndbulkpipe(usb, dev->command_write.addr),
+                           &cmd, 32, &count, HZ * 1);
 }
 
 static int dt9812_rmw_multiple_registers(struct usb_dt9812 *dev, int reg_count,
                                         struct dt9812_rmw_byte *rmw)
 {
+       struct usb_device *usb = dev->udev;
        struct dt9812_usb_cmd cmd;
-       int i, count, retval;
+       int i, count;
 
        cmd.cmd = cpu_to_le32(DT9812_RMW_MULTI_BYTE_REG);
        cmd.u.rmw_multi_info.count = reg_count;
@@ -389,11 +381,8 @@ static int dt9812_rmw_multiple_registers(struct usb_dt9812 *dev, int reg_count,
                cmd.u.rmw_multi_info.rmw[i] = rmw[i];
 
        /* DT9812 only responds to 32 byte writes!! */
-       retval = usb_bulk_msg(dev->udev,
-                             usb_sndbulkpipe(dev->udev,
-                                             dev->command_write.addr),
-                             &cmd, 32, &count, HZ * 1);
-       return retval;
+       return usb_bulk_msg(usb, usb_sndbulkpipe(usb, dev->command_write.addr),
+                           &cmd, 32, &count, HZ * 1);
 }
 
 static int dt9812_digital_in(struct slot_dt9812 *slot, u8 *bits)