From: H Hartley Sweeten Date: Tue, 14 May 2013 21:22:39 +0000 (-0700) Subject: staging: comedi: dt9812: tidy up usb_bulk_msg() calls X-Git-Tag: firefly_0821_release~176^2~5845^2~631 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=0ec77d3499b10c75b279080a79a79e35e51b70a6;p=firefly-linux-kernel-4.4.55.git staging: comedi: dt9812: tidy up usb_bulk_msg() calls 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 Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index b797517e2ddb..17a738c86b88 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -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)