Changeset 34260 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB/win/USBLib-win.cpp
- Timestamp:
- Nov 22, 2010 6:12:25 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 68008
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/USBLib-win.cpp
r34259 r34260 2696 2696 2697 2697 /** 2698 * Return all attached USB devices .that are captured by the filter2698 * Return all attached USB devices that are captured by the filter 2699 2699 * 2700 2700 * @returns VBox status code … … 2706 2706 USBSUP_GETNUMDEV numdev; 2707 2707 PUSBDEVICE pDevice = NULL; 2708 PUSBDEVICE pCaptured = NULL;2709 PUSBDEVICE pList = NULL;2710 2708 Log(("usbLibGetDevices: enter\n")); 2711 2709 … … 2798 2796 Assert(numdev.cUSBDevices == *pcDevices); 2799 2797 2800 if ( numdev.cUSBDevices == 0 || *pcDevices == 0)2798 if ((int32_t)numdev.cUSBDevices <= 0 || *pcDevices == 0) 2801 2799 { 2802 2800 /* Only return the host devices */ … … 2810 2808 2811 2809 /* Get the required info for each captured device */ 2812 pCaptured = NULL; 2813 for (int i = 0; i < (int32_t)numdev.cUSBDevices; i++) 2810 PUSBDEVICE *ppCaptured = (PUSBDEVICE*)RTMemAllocZ(sizeof(PUSBDEVICE * numDev.cUSBDevices)); 2811 if (!ppCaptured) 2812 goto failure; 2813 2814 uint32_t cCaptured = 0; 2815 for (uint32_t i = 0; i < numdev.cUSBDevices; i++) 2814 2816 { 2815 2817 USBSUP_GETDEV dev = {0}; … … 2833 2835 { 2834 2836 pDevice = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE)); 2835 if ( pDevice == NULL)2837 if (!pDevice) 2836 2838 goto failure; 2837 2839 … … 2847 2849 Log(("usbLibGetDevices: Detected device vid=%x did=%x rev=%x hispd=%d hash=%s hash=%RX64\n", dev.vid, dev.did, dev.rev, dev.fHiSpeed, dev.serial_hash, pDevice->u64SerialHash)); 2848 2850 2849 /* Insert into the list */ 2850 pDevice->pNext = pCaptured; 2851 if (pCaptured) 2852 pCaptured->pPrev = pDevice; 2853 2854 pCaptured = pDevice; 2855 2851 ppCaptured[i] = pDevice; 2852 cCaptured++; 2856 2853 } 2857 2854 … … 2862 2859 } 2863 2860 2864 if (! pCaptured)2861 if (!cCaptured) 2865 2862 { 2866 2863 /* Only return the host devices */ … … 2871 2868 } 2872 2869 2873 /* 3: Add all host devices to array of captured devices; obviously making sure there are no duplicates */2874 Assert(pHostDevices && pCaptured);2875 pList = pCaptured;2870 /* 3: Go through the list of captured devices, lookup the corresponding device 2871 * in the list of host devices and update the information there. */ 2872 Assert(pHostDevices); 2876 2873 for (uint32_t i = 0; i < numdev.cUSBDevices; i++) 2877 2874 { 2878 uint32_t j; 2875 char *pszDeviceRegPath = usblibQueryDeviceRegPath(i); 2876 Assert(pszDeviceRegPath); 2879 2877 2880 2878 pDevice = pHostDevices; 2881 Assert(pDevice); 2882 2883 for (j = 0; j < cHostDevices; j++) 2884 { 2885 char *pszDeviceRegPath = usblibQueryDeviceRegPath(i); 2886 2887 Assert(pszDeviceRegPath); 2879 for (uint32_t j = 0; j < cHostDevices; j++) 2880 { 2888 2881 if (pszDeviceRegPath) 2889 2882 { … … 2910 2903 2911 2904 pDevice->enmState = USBDEVICESTATE_HELD_BY_PROXY; 2912 pDevice->enmSpeed = pList->enmSpeed; // @todo: Is that right? 2905 if (ppCaptured[i]) 2906 pDevice->enmSpeed = ppCaptured[i]->enmSpeed; // @todo: Is that right? 2913 2907 RTStrFree(pDevice->pszAltAddress); 2914 2908 pDevice->pszAltAddress = (char *)pDevice->pszAddress; 2915 2909 pDevice->pszAddress = RTStrDup(usblibQueryDeviceName(i)); 2916 2910 } 2917 pList = pList->pNext;2918 2911 } 2919 2912 *pcDevices = cHostDevices; 2920 2913 2921 2914 /* Free captured devices list */ 2922 pDevice = pCaptured; 2923 while (pDevice) 2924 { 2925 PUSBDEVICE pOldDev = pDevice; 2926 2927 if (pDevice->pszAddress) 2915 for (uint32_t i = 0; i < numdev.cUSBDevices; i++) 2916 { 2917 pDevice = ppCaptured[i]; 2918 if (pDevice) 2919 { 2928 2920 RTMemFree((void *)pDevice->pszAddress); 2929 if (pDevice->pszAltAddress)2930 2921 RTStrFree(pDevice->pszAltAddress); 2931 if (pDevice->pszHubName)2932 2922 RTStrFree(pDevice->pszHubName); 2933 if (pDevice->pszManufacturer)2934 2923 RTMemFree((void *)pDevice->pszManufacturer); 2935 if (pDevice->pszProduct)2936 2924 RTMemFree((void *)pDevice->pszProduct); 2937 if (pDevice->pszSerialNumber)2938 2925 RTMemFree((void *)pDevice->pszSerialNumber); 2939 2940 pDevice = pDevice->pNext; 2941 2942 RTMemFree(pOldDev); 2943 } 2926 RTMemFree(pDevice); 2927 } 2928 } 2929 RTMemFree(ppCaptured); 2944 2930 2945 2931 Log(("usbLibGetDevices: returns %d devices\n", *pcDevices)); … … 2991 2977 2992 2978 failure: 2979 /* free host devices */ 2993 2980 pDevice = pHostDevices; 2994 2981 pHostDevices = NULL; 2995 2982 while (pDevice) 2996 2983 { 2997 PUSBDEVICE pOldDev = pDevice; 2998 2999 if (pDevice->pszAddress) 2984 PUSBDEVICE pNext = pDevice->pNext; 2985 2986 RTMemFree((void *)pDevice->pszAddress); 2987 RTMemFree((void *)pDevice->pszManufacturer); 2988 RTMemFree((void *)pDevice->pszProduct); 2989 RTMemFree((void *)pDevice->pszSerialNumber); 2990 RTMemFree(pDevice); 2991 2992 pDevice = Next; 2993 } 2994 2995 /* free captured devices */ 2996 for (uint32_t i = 0; i < numdev.cUSBDevices; i++) 2997 { 2998 pDevice = ppCaptured[i]; 2999 if (pDevice) 3000 { 3000 3001 RTMemFree((void *)pDevice->pszAddress); 3001 if (pDevice->pszManufacturer)3002 3002 RTMemFree((void *)pDevice->pszManufacturer); 3003 if (pDevice->pszProduct)3004 3003 RTMemFree((void *)pDevice->pszProduct); 3005 if (pDevice->pszSerialNumber)3006 3004 RTMemFree((void *)pDevice->pszSerialNumber); 3007 3008 pDevice = pDevice->pNext; 3009 3010 RTMemFree(pOldDev); 3011 3012 if (pDevice == NULL && pCaptured) 3013 { 3014 pDevice = pCaptured; 3015 pCaptured = NULL; 3016 } 3017 } 3005 RTMemFree(pDevice); 3006 } 3007 } 3008 RTMemFree(ppCaptured); 3018 3009 3019 3010 *ppDevices = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.