Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164980
b: refs/heads/master
c: 665d766
h: refs/heads/master
v: v3
  • Loading branch information
Guus Sliepen authored and Greg Kroah-Hartman committed Sep 23, 2009
1 parent 1818d30 commit afa206e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a9d43091c5be1e7a60d5abe84be4f3050236b26a
refs/heads/master: 665d7662d15441b4b3e54131a9418a1a198d0d31
22 changes: 18 additions & 4 deletions trunk/drivers/usb/class/usbtmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
{
struct usbtmc_device_data *data;
struct device *dev;
unsigned long int n_characters;
u32 n_characters;
u8 *buffer;
int actual;
int done;
int remaining;
size_t done;
size_t remaining;
int retval;
int this_part;
size_t this_part;

/* Get pointer to private data structure */
data = filp->private_data;
Expand Down Expand Up @@ -461,6 +461,18 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
(buffer[6] << 16) +
(buffer[7] << 24);

/* Ensure the instrument doesn't lie about it */
if(n_characters > actual - 12) {
dev_err(dev, "Device lies about message size: %zu > %zu\n", n_characters, actual - 12);
n_characters = actual - 12;
}

/* Ensure the instrument doesn't send more back than requested */
if(n_characters > this_part) {
dev_err(dev, "Device returns more than requested: %zu > %zu\n", done + n_characters, done + this_part);
n_characters = this_part;
}

/* Copy buffer to user space */
if (copy_to_user(buf + done, &buffer[12], n_characters)) {
/* There must have been an addressing problem */
Expand All @@ -471,6 +483,8 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
done += n_characters;
if (n_characters < USBTMC_SIZE_IOBUFFER)
remaining = 0;
else
remaining -= n_characters;
}

/* Update file position value */
Expand Down

0 comments on commit afa206e

Please sign in to comment.