aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRoel Kluin <roel.kluin@gmail.com>2009-03-13 07:19:18 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-03-24 19:20:45 -0400
commit71d2718f2507dc17501d04e2bdca7b8e694ce365 (patch)
treea633d1b4bcaf1d44013a07927a669503a9d36d65 /drivers
parentd2ad67b3fa61eed52b22491210c668a94c7bf17e (diff)
USB: more u32 conversion after transfer_buffer_length and actual_length
transfer_buffer_length and actual_length have become unsigned, therefore some additional conversion of local variables, function arguments and print specifications is desired. A test for a negative urb->transfer_buffer_length became obsolete; instead we ensure that it does not exceed INT_MAX. Also, urb->actual_length is always less than urb->transfer_buffer_length. rh_string() does no longer return -EPIPE in the case of an unsupported ID. Instead its only caller, rh_call_control() does the check. Signed-off-by: Roel Kluin <roel.kluin@gmail.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/hcd.c31
-rw-r--r--drivers/usb/core/hub.c2
-rw-r--r--drivers/usb/core/message.c2
-rw-r--r--drivers/usb/core/urb.c2
5 files changed, 18 insertions, 25 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index d3883f639604..df3c539f652a 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -302,7 +302,7 @@ static struct async *async_getpending(struct dev_state *ps,
302 302
303static void snoop_urb(struct urb *urb, void __user *userurb) 303static void snoop_urb(struct urb *urb, void __user *userurb)
304{ 304{
305 int j; 305 unsigned j;
306 unsigned char *data = urb->transfer_buffer; 306 unsigned char *data = urb->transfer_buffer;
307 307
308 if (!usbfs_snoop) 308 if (!usbfs_snoop)
@@ -311,9 +311,9 @@ static void snoop_urb(struct urb *urb, void __user *userurb)
311 dev_info(&urb->dev->dev, "direction=%s\n", 311 dev_info(&urb->dev->dev, "direction=%s\n",
312 usb_urb_dir_in(urb) ? "IN" : "OUT"); 312 usb_urb_dir_in(urb) ? "IN" : "OUT");
313 dev_info(&urb->dev->dev, "userurb=%p\n", userurb); 313 dev_info(&urb->dev->dev, "userurb=%p\n", userurb);
314 dev_info(&urb->dev->dev, "transfer_buffer_length=%d\n", 314 dev_info(&urb->dev->dev, "transfer_buffer_length=%u\n",
315 urb->transfer_buffer_length); 315 urb->transfer_buffer_length);
316 dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length); 316 dev_info(&urb->dev->dev, "actual_length=%u\n", urb->actual_length);
317 dev_info(&urb->dev->dev, "data: "); 317 dev_info(&urb->dev->dev, "data: ");
318 for (j = 0; j < urb->transfer_buffer_length; ++j) 318 for (j = 0; j < urb->transfer_buffer_length; ++j)
319 printk("%02x ", data[j]); 319 printk("%02x ", data[j]);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 0eee32a65e23..81fa8506825d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -279,9 +279,9 @@ static const u8 hs_rh_config_descriptor [] = {
279 * helper routine for returning string descriptors in UTF-16LE 279 * helper routine for returning string descriptors in UTF-16LE
280 * input can actually be ISO-8859-1; ASCII is its 7-bit subset 280 * input can actually be ISO-8859-1; ASCII is its 7-bit subset
281 */ 281 */
282static int ascii2utf (char *s, u8 *utf, int utfmax) 282static unsigned ascii2utf(char *s, u8 *utf, int utfmax)
283{ 283{
284 int retval; 284 unsigned retval;
285 285
286 for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) { 286 for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
287 *utf++ = *s++; 287 *utf++ = *s++;
@@ -304,19 +304,15 @@ static int ascii2utf (char *s, u8 *utf, int utfmax)
304 * Produces either a manufacturer, product or serial number string for the 304 * Produces either a manufacturer, product or serial number string for the
305 * virtual root hub device. 305 * virtual root hub device.
306 */ 306 */
307static int rh_string ( 307static unsigned rh_string(int id, struct usb_hcd *hcd, u8 *data, unsigned len)
308 int id, 308{
309 struct usb_hcd *hcd,
310 u8 *data,
311 int len
312) {
313 char buf [100]; 309 char buf [100];
314 310
315 // language ids 311 // language ids
316 if (id == 0) { 312 if (id == 0) {
317 buf[0] = 4; buf[1] = 3; /* 4 bytes string data */ 313 buf[0] = 4; buf[1] = 3; /* 4 bytes string data */
318 buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */ 314 buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */
319 len = min (len, 4); 315 len = min_t(unsigned, len, 4);
320 memcpy (data, buf, len); 316 memcpy (data, buf, len);
321 return len; 317 return len;
322 318
@@ -332,10 +328,7 @@ static int rh_string (
332 } else if (id == 3) { 328 } else if (id == 3) {
333 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, 329 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
334 init_utsname()->release, hcd->driver->description); 330 init_utsname()->release, hcd->driver->description);
335 331 }
336 // unsupported IDs --> "protocol stall"
337 } else
338 return -EPIPE;
339 332
340 switch (len) { /* All cases fall through */ 333 switch (len) { /* All cases fall through */
341 default: 334 default:
@@ -360,9 +353,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
360 u8 tbuf [sizeof (struct usb_hub_descriptor)] 353 u8 tbuf [sizeof (struct usb_hub_descriptor)]
361 __attribute__((aligned(4))); 354 __attribute__((aligned(4)));
362 const u8 *bufp = tbuf; 355 const u8 *bufp = tbuf;
363 int len = 0; 356 unsigned len = 0;
364 int status; 357 int status;
365 int n;
366 u8 patch_wakeup = 0; 358 u8 patch_wakeup = 0;
367 u8 patch_protocol = 0; 359 u8 patch_protocol = 0;
368 360
@@ -456,10 +448,11 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
456 patch_wakeup = 1; 448 patch_wakeup = 1;
457 break; 449 break;
458 case USB_DT_STRING << 8: 450 case USB_DT_STRING << 8:
459 n = rh_string (wValue & 0xff, hcd, ubuf, wLength); 451 if ((wValue & 0xff) < 4)
460 if (n < 0) 452 urb->actual_length = rh_string(wValue & 0xff,
453 hcd, ubuf, wLength);
454 else /* unsupported IDs --> "protocol stall" */
461 goto error; 455 goto error;
462 urb->actual_length = n;
463 break; 456 break;
464 default: 457 default:
465 goto error; 458 goto error;
@@ -629,7 +622,7 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
629{ 622{
630 int retval; 623 int retval;
631 unsigned long flags; 624 unsigned long flags;
632 int len = 1 + (urb->dev->maxchild / 8); 625 unsigned len = 1 + (urb->dev->maxchild / 8);
633 626
634 spin_lock_irqsave (&hcd_root_hub_lock, flags); 627 spin_lock_irqsave (&hcd_root_hub_lock, flags);
635 if (hcd->status_urb || urb->transfer_buffer_length < len) { 628 if (hcd->status_urb || urb->transfer_buffer_length < len) {
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 81eb3e6b6592..be86ae3f4088 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -392,7 +392,7 @@ static void hub_irq(struct urb *urb)
392{ 392{
393 struct usb_hub *hub = urb->context; 393 struct usb_hub *hub = urb->context;
394 int status = urb->status; 394 int status = urb->status;
395 int i; 395 unsigned i;
396 unsigned long bits; 396 unsigned long bits;
397 397
398 switch (status) { 398 switch (status) {
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 3922fa915ed2..293a30d78d24 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -59,7 +59,7 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
59 retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status); 59 retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status);
60 60
61 dev_dbg(&urb->dev->dev, 61 dev_dbg(&urb->dev->dev,
62 "%s timed out on ep%d%s len=%d/%d\n", 62 "%s timed out on ep%d%s len=%u/%u\n",
63 current->comm, 63 current->comm,
64 usb_endpoint_num(&urb->ep->desc), 64 usb_endpoint_num(&urb->ep->desc),
65 usb_urb_dir_in(urb) ? "in" : "out", 65 usb_urb_dir_in(urb) ? "in" : "out",
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 7025d801f23a..3376055f36e7 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -370,7 +370,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
370 } 370 }
371 371
372 /* the I/O buffer must be mapped/unmapped, except when length=0 */ 372 /* the I/O buffer must be mapped/unmapped, except when length=0 */
373 if (urb->transfer_buffer_length < 0) 373 if (urb->transfer_buffer_length > INT_MAX)
374 return -EMSGSIZE; 374 return -EMSGSIZE;
375 375
376#ifdef DEBUG 376#ifdef DEBUG