Skip to content

Commit 0cb54a3

Browse files
AlanSterngregkh
authored andcommitted
USB: debugging code shouldn't alter control flow
People have complained that debugging code shouldn't alter the flow of control; it should restrict itself to printing out warnings and error messages. Bowing to popular opinion, this patch (as1518) changes the debugging checks in usb_submit_urb() to follow this guideline. Signed-off-by: Alan Stern <[email protected]> Reported-by: Keith Packard <[email protected]> CC: Pavel Machek <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c39c654 commit 0cb54a3

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

drivers/usb/core/urb.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,17 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
403403
* cause problems in HCDs if they get it wrong.
404404
*/
405405
{
406-
unsigned int orig_flags = urb->transfer_flags;
407406
unsigned int allowed;
408407
static int pipetypes[4] = {
409408
PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
410409
};
411410

412411
/* Check that the pipe's type matches the endpoint's type */
413-
if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) {
414-
dev_err(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
412+
if (usb_pipetype(urb->pipe) != pipetypes[xfertype])
413+
dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
415414
usb_pipetype(urb->pipe), pipetypes[xfertype]);
416-
return -EPIPE; /* The most suitable error code :-) */
417-
}
418415

419-
/* enforce simple/standard policy */
416+
/* Check against a simple/standard policy */
420417
allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK |
421418
URB_FREE_BUFFER);
422419
switch (xfertype) {
@@ -435,14 +432,12 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
435432
allowed |= URB_ISO_ASAP;
436433
break;
437434
}
438-
urb->transfer_flags &= allowed;
435+
allowed &= urb->transfer_flags;
439436

440-
/* fail if submitter gave bogus flags */
441-
if (urb->transfer_flags != orig_flags) {
442-
dev_err(&dev->dev, "BOGUS urb flags, %x --> %x\n",
443-
orig_flags, urb->transfer_flags);
444-
return -EINVAL;
445-
}
437+
/* warn if submitter gave bogus flags */
438+
if (allowed != urb->transfer_flags)
439+
dev_WARN(&dev->dev, "BOGUS urb flags, %x --> %x\n",
440+
urb->transfer_flags, allowed);
446441
}
447442
#endif
448443
/*

0 commit comments

Comments
 (0)