Index: trunk/src/VBox/ValidationKit/utils/usb/UsbTest.cpp
===================================================================
--- trunk/src/VBox/ValidationKit/utils/usb/UsbTest.cpp	(revision 60518)
+++ trunk/src/VBox/ValidationKit/utils/usb/UsbTest.cpp	(revision 60522)
@@ -30,5 +30,7 @@
 *   Header Files                                                                                                                 *
 *********************************************************************************************************************************/
+#include <iprt/dir.h>
 #include <iprt/err.h>
+#include <iprt/file.h>
 #include <iprt/getopt.h>
 #include <iprt/path.h>
@@ -38,5 +40,4 @@
 #include <iprt/string.h>
 #include <iprt/test.h>
-#include <iprt/file.h>
 
 #include <unistd.h>
@@ -273,54 +274,69 @@
      * Assumption is that the path looks like /dev/bus/usb/%3d/%3d.
      */
-    uint8_t uBus = 1;
-    bool fBusExists = false;
-    char aszDevPath[64];
-
-    RT_ZERO(aszDevPath);
-
-    do
+    char *pszDevPath = NULL;
+
+    PRTDIR pDirUsb = NULL;
+    int rc = RTDirOpen(&pDirUsb, "/dev/bus/usb");
+    if (RT_SUCCESS(rc))
     {
-        RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d", uBus);
-
-        fBusExists = RTPathExists(aszDevPath);
-
-        if (fBusExists)
+        do
         {
-            /* Check every device. */
-            bool fDevExists = false;
-            uint8_t uDev = 1;
-
-            do
+            RTDIRENTRY DirUsbBus;
+            rc = RTDirRead(pDirUsb, &DirUsbBus, NULL);
+            if (RT_SUCCESS(rc))
             {
-                RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d/%03d", uBus, uDev);
-
-                fDevExists = RTPathExists(aszDevPath);
-
-                if (fDevExists)
+                char aszPath[RTPATH_MAX + 1];
+                RTStrPrintf(&aszPath[0], RT_ELEMENTS(aszPath), "/dev/bus/usb/%s", DirUsbBus.szName);
+
+                PRTDIR pDirUsbBus = NULL;
+                rc = RTDirOpen(&pDirUsbBus, &aszPath[0]);
+                if (RT_SUCCESS(rc))
                 {
-                    RTFILE hFileDev;
-                    int rc = RTFileOpen(&hFileDev, aszDevPath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
-                    if (RT_SUCCESS(rc))
+                    do
                     {
-                        USBDEVDESC DevDesc;
-
-                        rc = RTFileRead(hFileDev, &DevDesc, sizeof(DevDesc), NULL);
-                        RTFileClose(hFileDev);
-
-                        if (   RT_SUCCESS(rc)
-                            && DevDesc.idVendor == 0x0525
-                            && DevDesc.idProduct == 0xa4a0)
-                            return RTStrDup(aszDevPath);
-                    }
+                        RTDIRENTRY DirUsbDev;
+                        rc = RTDirRead(pDirUsbBus, &DirUsbDev, NULL);
+                        if (RT_SUCCESS(rc))
+                        {
+                            char aszPathDev[RTPATH_MAX + 1];
+                            RTStrPrintf(&aszPathDev[0], RT_ELEMENTS(aszPathDev), "/dev/bus/usb/%s/%s",
+                                        DirUsbBus.szName, DirUsbDev.szName);
+
+                            RTFILE hFileDev;
+                            rc = RTFileOpen(&hFileDev, aszPathDev, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
+                            if (RT_SUCCESS(rc))
+                            {
+                                USBDEVDESC DevDesc;
+
+                                rc = RTFileRead(hFileDev, &DevDesc, sizeof(DevDesc), NULL);
+                                RTFileClose(hFileDev);
+
+                                if (   RT_SUCCESS(rc)
+                                    && DevDesc.idVendor == 0x0525
+                                    && DevDesc.idProduct == 0xa4a0)
+                                    pszDevPath = RTStrDup(aszPathDev);
+                            }
+
+                            rc = VINF_SUCCESS;
+                        }
+                        else if (rc != VERR_NO_MORE_FILES)
+                            rc = VINF_SUCCESS;
+
+                    } while (   RT_SUCCESS(rc)
+                             && !pszDevPath);
+
+                    rc = VINF_SUCCESS;
+                    RTDirClose(pDirUsbBus);
                 }
-
-                uDev++;
-            } while (fDevExists);
-        }
-
-        uBus++;
-    } while (fBusExists);
-
-    return NULL;
+            }
+            else if (rc != VERR_NO_MORE_FILES)
+                rc = VINF_SUCCESS;
+        } while (   RT_SUCCESS(rc)
+                 && !pszDevPath);
+
+        RTDirClose(pDirUsb);
+    }
+
+    return pszDevPath;
 }
 
Index: trunk/src/VBox/ValidationKit/utils/usb/UsbTestService.cpp
===================================================================
--- trunk/src/VBox/ValidationKit/utils/usb/UsbTestService.cpp	(revision 60518)
+++ trunk/src/VBox/ValidationKit/utils/usb/UsbTestService.cpp	(revision 60522)
@@ -832,5 +832,5 @@
         rc = utsDoGadgetCreate(pClient, pPktHdr);
     else if (utsIsSameOpcode(pPktHdr, UTSPKT_OPCODE_GADGET_DESTROY))
-        rc = utsDoGadgetCreate(pClient, pPktHdr);
+        rc = utsDoGadgetDestroy(pClient, pPktHdr);
     else if (utsIsSameOpcode(pPktHdr, UTSPKT_OPCODE_GADGET_CONNECT))
         rc = utsDoGadgetConnect(pClient, pPktHdr);
Index: trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceGadgetClassTest.cpp
===================================================================
--- trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceGadgetClassTest.cpp	(revision 60518)
+++ trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceGadgetClassTest.cpp	(revision 60522)
@@ -32,4 +32,5 @@
 #include <iprt/string.h>
 #include <iprt/symlink.h>
+#include <iprt/thread.h>
 #include <iprt/types.h>
 
@@ -359,4 +360,6 @@
                     if (RT_SUCCESS(rc))
                         rc = RTLinuxSysFsWriteStrFile(pClass->pszUdc, 0, NULL, "%s/UDC", pClass->pszGadgetPath);
+                    if (RT_SUCCESS(rc))
+                        RTThreadSleep(500); /* Fudge: Sleep a bit to give the device a chance to appear on the host so binding succeeds. */
                 }
             }
@@ -406,5 +409,9 @@
 static DECLCALLBACK(int) utsGadgetClassTestConnect(PUTSGADGETCLASSINT pClass)
 {
-    return RTLinuxSysFsWriteStrFile("connect", 0, NULL, "/sys/class/udc/%s/soft_connect", pClass->pszUdc);
+    int rc = RTLinuxSysFsWriteStrFile("connect", 0, NULL, "/sys/class/udc/%s/soft_connect", pClass->pszUdc);
+    if (RT_SUCCESS(rc))
+        RTThreadSleep(500); /* Fudge: Sleep a bit to give the device a chance to appear on the host so binding succeeds. */
+
+    return rc;
 }
 
Index: trunk/src/VBox/ValidationKit/utils/usb/UsbTestServicePlatform-linux.cpp
===================================================================
--- trunk/src/VBox/ValidationKit/utils/usb/UsbTestServicePlatform-linux.cpp	(revision 60518)
+++ trunk/src/VBox/ValidationKit/utils/usb/UsbTestServicePlatform-linux.cpp	(revision 60522)
@@ -178,4 +178,5 @@
                                         g_paDummyHcd[idxHcdCur].uBusId      = uBusId;
                                         g_paDummyHcd[idxHcdCur].fAvailable  = true;
+                                        idxHcdCur++;
                                     }
                                 }
@@ -300,5 +301,5 @@
         pszIdx++;
         uint32_t idxHcd = 0;
-        rc = RTStrToUInt32Ex(pszUdc, NULL, 10, &idxHcd);
+        rc = RTStrToUInt32Ex(pszIdx, NULL, 10, &idxHcd);
         if (RT_SUCCESS(rc))
         {
