]> git.proxmox.com Git - mirror_qemu.git/commitdiff
usb: rearrange usb_ep_get()
authorLiam Merwick <liam.merwick@oracle.com>
Wed, 6 Feb 2019 13:36:48 +0000 (13:36 +0000)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 20 Feb 2019 08:41:23 +0000 (09:41 +0100)
There is no need to calculate the 'eps' variable in usb_ep_get()
if 'ep' is the control endpoint.  Instead the calculation should
be done after validating the input before returning an entry
indexed by the endpoint 'ep'.

Signed-off-by: Liam Merwick <liam.merwick@oracle.com>
Reviewed-by: Darren Kenny <Darren.Kenny@oracle.com>
Reviewed-by: Mark Kanda <Mark.Kanda@oracle.com>
Reviewed-by: Ameya More <ameya.more@oracle.com>
Message-id: 1549460216-25808-2-git-send-email-liam.merwick@oracle.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb/core.c

index 241ae66b15059b2963acc1debbe0e50e674497b6..bfb7ae67bbf0204b7b6fe74faa226ef89c83c318 100644 (file)
@@ -720,12 +720,12 @@ struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep)
     if (dev == NULL) {
         return NULL;
     }
-    eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out;
     if (ep == 0) {
         return &dev->ep_ctl;
     }
     assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT);
     assert(ep > 0 && ep <= USB_MAX_ENDPOINTS);
+    eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out;
     return eps + ep - 1;
 }