USB: debugging code shouldn't alter control flow
authorAlan Stern <stern@rowland.harvard.edu>
Thu, 2 Feb 2012 20:38:14 +0000 (15:38 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 3 Feb 2012 00:15:44 +0000 (16:15 -0800)
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 <stern@rowland.harvard.edu>
Reported-by: Keith Packard <keithp@keithp.com>
CC: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/urb.c

index 909625b91eb35a3a4096029d3fd46e0a6cb25bb4..f4f20c7b77657a2e88a298bd3ba605c1fa1db12c 100644 (file)
@@ -403,20 +403,17 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
         * cause problems in HCDs if they get it wrong.
         */
        {
-       unsigned int    orig_flags = urb->transfer_flags;
        unsigned int    allowed;
        static int pipetypes[4] = {
                PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
        };
 
        /* Check that the pipe's type matches the endpoint's type */
-       if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) {
-               dev_err(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
+       if (usb_pipetype(urb->pipe) != pipetypes[xfertype])
+               dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
                        usb_pipetype(urb->pipe), pipetypes[xfertype]);
-               return -EPIPE;          /* The most suitable error code :-) */
-       }
 
-       /* enforce simple/standard policy */
+       /* Check against a simple/standard policy */
        allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK |
                        URB_FREE_BUFFER);
        switch (xfertype) {
@@ -435,14 +432,12 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
                allowed |= URB_ISO_ASAP;
                break;
        }
-       urb->transfer_flags &= allowed;
+       allowed &= urb->transfer_flags;
 
-       /* fail if submitter gave bogus flags */
-       if (urb->transfer_flags != orig_flags) {
-               dev_err(&dev->dev, "BOGUS urb flags, %x --> %x\n",
-                       orig_flags, urb->transfer_flags);
-               return -EINVAL;
-       }
+       /* warn if submitter gave bogus flags */
+       if (allowed != urb->transfer_flags)
+               dev_WARN(&dev->dev, "BOGUS urb flags, %x --> %x\n",
+                       urb->transfer_flags, allowed);
        }
 #endif
        /*