Skip to contentSkip to conversation

idmouse cleanup and overflow fix

PATCH New Al Viro 1 participant 1 message Oct 29, 2005 USB

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 1/1 idmouse cleanup and overflow fix

switched to simple_read_from_buffer(), killed broken use of min().
Incidentally, that use of min() had been fixed once, only to be reintroduced in
[PATCH] USB: upgrade of the idmouse driver
[snip]
- if (count > IMGSIZE - *ppos)
- count = IMGSIZE - *ppos;
+ count = min ((loff_t)count, IMGSIZE - (*ppos));

Note the lovely use of cast to shut the warning about misuse of min() up...

----

drivers/usb/misc/idmouse.c +2 -14
diff -urN RC14-base/drivers/usb/misc/idmouse.c current/drivers/usb/misc/idmouse.c
@@ -319,20 +319,8 @@
 		return -ENODEV;
 	}
 
-	if (*ppos >= IMGSIZE) {
-		up (&dev->sem);
-		return 0;
-	}
-
-	count = min ((loff_t)count, IMGSIZE - (*ppos));
-
-	if (copy_to_user (buffer, dev->bulk_in_buffer + *ppos, count)) {
-		result = -EFAULT;
-	} else {
-		result = count;
-		*ppos += count;
-	}
-
+	result = simple_read_from_buffer(buffer, count, ppos,
+					dev->bulk_in_buffer, IMGSIZE);
 	/* unlock the device */
 	up(&dev->sem);
 	return result;