usb: add usb_update_pipe()

Preparation for better xhci support: allows to notify host controllers
instead of going through a free+alloc cycle.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
diff --git a/src/hw/usb.c b/src/hw/usb.c
index 59d2a93..b4d0ab8 100644
--- a/src/hw/usb.c
+++ b/src/hw/usb.c
@@ -44,6 +44,18 @@
     }
 }
 
+// Update an pipe (used for control only)
+struct usb_pipe *
+usb_update_pipe(struct usbdevice_s *usbdev, struct usb_pipe *pipe
+                , struct usb_endpoint_descriptor *epdesc)
+{
+    switch (usbdev->hub->cntl->type) {
+    default:
+        free_pipe(pipe);
+        return usb_alloc_pipe(usbdev, epdesc);
+    }
+}
+
 // Send a message on a control pipe using the default control descriptor.
 static int
 send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize
@@ -262,15 +274,16 @@
     req.wIndex = 0;
     req.wLength = 0;
     int ret = send_default_control(usbdev->defpipe, &req, NULL);
-    free_pipe(usbdev->defpipe);
-    if (ret)
+    if (ret) {
+        free_pipe(usbdev->defpipe);
         return -1;
+    }
 
     msleep(USB_TIME_SETADDR_RECOVERY);
 
     cntl->maxaddr++;
     usbdev->devaddr = cntl->maxaddr;
-    usbdev->defpipe = usb_alloc_pipe(usbdev, &epdesc);
+    usbdev->defpipe = usb_update_pipe(usbdev, usbdev->defpipe, &epdesc);
     if (!usbdev->defpipe)
         return -1;
     return 0;
@@ -294,12 +307,11 @@
             , dinfo.bDeviceProtocol, dinfo.bMaxPacketSize0);
     if (dinfo.bMaxPacketSize0 < 8 || dinfo.bMaxPacketSize0 > 64)
         return 0;
-    free_pipe(usbdev->defpipe);
     struct usb_endpoint_descriptor epdesc = {
         .wMaxPacketSize = dinfo.bMaxPacketSize0,
         .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
     };
-    usbdev->defpipe = usb_alloc_pipe(usbdev, &epdesc);
+    usbdev->defpipe = usb_update_pipe(usbdev, usbdev->defpipe, &epdesc);
     if (!usbdev->defpipe)
         return -1;