Commit 4850f26a authored by Daniel M German's avatar Daniel M German Committed by Greg Kroah-Hartman

usb: clean up some of the computations in adu_read

Replace ?: with min to calculate the number of bytes in the secondary buffer,
including changing the data type of data_in_secondary to size_t to be
type-consistent. data_in_secondary can never be negative.

Remove some spurious calculations (copy_to_user returns zero on success),
making one variable redundant (i)

This change does not alter the functionality of the code.
Signed-off-by: default avatarDaniel M German <dmg@turingmachine.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 235e6e0a
...@@ -343,7 +343,6 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, ...@@ -343,7 +343,6 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
struct adu_device *dev; struct adu_device *dev;
size_t bytes_read = 0; size_t bytes_read = 0;
size_t bytes_to_read = count; size_t bytes_to_read = count;
int i;
int retval = 0; int retval = 0;
int timeout = 0; int timeout = 0;
int should_submit = 0; int should_submit = 0;
...@@ -371,23 +370,22 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count, ...@@ -371,23 +370,22 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
timeout = COMMAND_TIMEOUT; timeout = COMMAND_TIMEOUT;
dev_dbg(&dev->udev->dev, "%s : about to start looping\n", __func__); dev_dbg(&dev->udev->dev, "%s : about to start looping\n", __func__);
while (bytes_to_read) { while (bytes_to_read) {
int data_in_secondary = dev->secondary_tail - dev->secondary_head; size_t data_in_secondary = dev->secondary_tail - dev->secondary_head;
dev_dbg(&dev->udev->dev, dev_dbg(&dev->udev->dev,
"%s : while, data_in_secondary=%d, status=%d\n", "%s : while, data_in_secondary=%zu, status=%d\n",
__func__, data_in_secondary, __func__, data_in_secondary,
dev->interrupt_in_urb->status); dev->interrupt_in_urb->status);
if (data_in_secondary) { if (data_in_secondary) {
/* drain secondary buffer */ /* drain secondary buffer */
int amount = bytes_to_read < data_in_secondary ? bytes_to_read : data_in_secondary; size_t amount = min(bytes_to_read, data_in_secondary);
i = copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount); if (copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount)) {
if (i) {
retval = -EFAULT; retval = -EFAULT;
goto exit; goto exit;
} }
dev->secondary_head += (amount - i); dev->secondary_head += amount;
bytes_read += (amount - i); bytes_read += amount;
bytes_to_read -= (amount - i); bytes_to_read -= amount;
} else { } else {
/* we check the primary buffer */ /* we check the primary buffer */
spin_lock_irqsave (&dev->buflock, flags); spin_lock_irqsave (&dev->buflock, flags);
......
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