VirtualBox

忽略:
時間撮記:
2014-1-24 下午09:16:37 (11 年 以前)
作者:
vboxsync
訊息:

USB/Proxy: Start a source code cleanup, remove unused struct members and make the generic proxy code do the backend specific memory allocation (fixes a small memory leak in the VRDP backend when closing a proxy device)

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Devices/USB/linux/USBProxyDevice-linux.cpp

    r49814 r50228  
    160160    /** The device node/sysfs path of the device.
    161161     * Used to figure out the configuration after a reset. */
    162     char                szPath[1];
     162    char                *pszPath;
    163163} USBPROXYDEVLNX, *PUSBPROXYDEVLNX;
    164164
     
    194194{
    195195    int rc;
    196     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     196    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    197197    do
    198198    {
     
    225225static void usbProxLinuxUrbUnplugged(PUSBPROXYDEV pProxyDev)
    226226{
    227     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     227    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    228228
    229229    /*
     
    307307static PUSBPROXYURBLNX usbProxyLinuxUrbAlloc(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pSplitHead)
    308308{
    309     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     309    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    310310    PUSBPROXYURBLNX pUrbLnx;
    311311
     
    360360static void usbProxyLinuxUrbFree(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx)
    361361{
    362     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     362    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    363363
    364364    RTCritSectEnter(&pDevLnx->CritSect);
     
    398398static void usbProxyLinuxUrbFreeSplitList(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx)
    399399{
    400     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     400    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    401401
    402402    RTCritSectEnter(&pDevLnx->CritSect);
     
    585585static int usbProxyLinuxFindActiveConfig(PUSBPROXYDEV pProxyDev, const char *pszPath, int *piFirstCfg)
    586586{
    587     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     587    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    588588    if (pDevLnx->fUsingSysfs)
    589589        return usbProxyLinuxFindActiveConfigSysfs(pProxyDev, pszPath, piFirstCfg);
     
    600600RTDECL(int) USBProxyDeviceLinuxGetFD(PUSBPROXYDEV pProxyDev)
    601601{
    602     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     602    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    603603    AssertReturn(pDevLnx->hFile != NIL_RTFILE, -1);
    604604    return RTFileToNative(pDevLnx->hFile);
     
    618618 * @param   pvBackend       Backend specific pointer, unused for the linux backend.
    619619 */
    620 static int usbProxyLinuxOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
     620static DECLCALLBACK(int) usbProxyLinuxOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
    621621{
    622622    LogFlow(("usbProxyLinuxOpen: pProxyDev=%p pszAddress=%s\n", pProxyDev, pszAddress));
     
    637637        {
    638638            LogRel(("usbProxyLinuxOpen: Invalid device address: '%s'\n", pszAddress));
    639             pProxyDev->Backend.pv = NULL;
    640639            return VERR_INVALID_PARAMETER;
    641640        }
     
    662661    if (RT_SUCCESS(rc))
    663662    {
    664             /*
    665              * Allocate and initialize the linux backend data.
    666              */
    667             PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)RTMemAllocZVar(sizeof(*pDevLnx) + cchPath);
    668             if (pDevLnx)
     663        /*
     664         * Initialize the linux backend data.
     665         */
     666        PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
     667        pDevLnx->pszPath = RTStrDupN(pszPath, cchPath);
     668        if (pDevLnx->pszPath)
     669        {
     670            rc = RTPipeCreate(&pDevLnx->hPipeWakeupR, &pDevLnx->hPipeWakeupW, 0);
     671            if (RT_SUCCESS(rc))
    669672            {
    670 
    671                 rc = RTPipeCreate(&pDevLnx->hPipeWakeupR, &pDevLnx->hPipeWakeupW, 0);
     673                pDevLnx->fUsingSysfs = fUsingSysfs;
     674                pDevLnx->hFile = hFile;
     675                rc = RTCritSectInit(&pDevLnx->CritSect);
    672676                if (RT_SUCCESS(rc))
    673677                {
    674                     pDevLnx->fUsingSysfs = fUsingSysfs;
    675                     memcpy(&pDevLnx->szPath[0], pszPath, cchPath);
    676                     pDevLnx->szPath[cchPath] = '\0';
    677                     pDevLnx->hFile = hFile;
    678                     rc = RTCritSectInit(&pDevLnx->CritSect);
    679                     if (RT_SUCCESS(rc))
    680                     {
    681                         pProxyDev->Backend.pv = pDevLnx;
    682 
    683                         LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n",
    684                                  pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg));
    685 
    686                         return VINF_SUCCESS;
    687                     }
    688                     RTPipeClose(pDevLnx->hPipeWakeupR);
    689                     RTPipeClose(pDevLnx->hPipeWakeupW);
     678                    LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n",
     679                             pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg));
     680
     681                    return VINF_SUCCESS;
    690682                }
    691 
    692                 RTMemFree(pDevLnx);
     683                RTPipeClose(pDevLnx->hPipeWakeupR);
     684                RTPipeClose(pDevLnx->hPipeWakeupW);
    693685            }
    694             else
    695                 rc = VERR_NO_MEMORY;
     686        }
     687        else
     688            rc = VERR_NO_MEMORY;
    696689
    697690        RTFileClose(hFile);
     
    702695    Log(("usbProxyLinuxOpen(%p, %s) failed, rc=%s!\n", pProxyDev, pszAddress,
    703696         RTErrGetShort(rc)));
    704     pProxyDev->Backend.pv = NULL;
    705697
    706698    NOREF(pvBackend);
     
    716708 * @param   pProxyDev       The proxy device.
    717709 */
    718 static int usbProxyLinuxInit(PUSBPROXYDEV pProxyDev)
    719 {
    720     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     710static DECLCALLBACK(int) usbProxyLinuxInit(PUSBPROXYDEV pProxyDev)
     711{
     712    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    721713
    722714    /*
     
    737729    pProxyDev->cIgnoreSetConfigs = 1;
    738730    int iFirstCfg;
    739     pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->szPath, &iFirstCfg);
     731    pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, &iFirstCfg);
    740732    if (pProxyDev->iActiveCfg == -1)
    741733    {
    742734        usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETCONFIGURATION, &iFirstCfg, false, UINT32_MAX);
    743         pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->szPath, NULL);
     735        pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, NULL);
    744736        Log(("usbProxyLinuxInit: No active config! Tried to set %d: iActiveCfg=%d\n", iFirstCfg, pProxyDev->iActiveCfg));
    745737    }
     
    753745 * Closes the proxy device.
    754746 */
    755 static void usbProxyLinuxClose(PUSBPROXYDEV pProxyDev)
     747static DECLCALLBACK(void) usbProxyLinuxClose(PUSBPROXYDEV pProxyDev)
    756748{
    757749    LogFlow(("usbProxyLinuxClose: pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
    758     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
    759     Assert(pDevLnx);
    760     if (!pDevLnx)
    761         return;
     750    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
     751    AssertPtrReturnVoid(pDevLnx);
    762752
    763753    /*
     
    831821    RTPipeClose(pDevLnx->hPipeWakeupW);
    832822
    833     RTMemFree(pDevLnx);
    834     pProxyDev->Backend.pv = NULL;
     823    RTStrFree(pDevLnx->pszPath);
     824
    835825    LogFlow(("usbProxyLinuxClose: returns\n"));
    836826}
     
    10291019 * @param   pDev    The device to reset.
    10301020 */
    1031 static int usbProxyLinuxReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
     1021static DECLCALLBACK(int) usbProxyLinuxReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
    10321022{
    10331023#ifdef NO_PORT_RESET
    1034     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     1024    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    10351025
    10361026    /*
     
    10581048
    10591049        /* find the active config - damn annoying. */
    1060         pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->szPath, NULL);
     1050        pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, NULL);
    10611051        LogFlow(("usbProxyLinuxReset: returns successfully iActiveCfg=%d\n", pProxyDev->iActiveCfg));
    10621052    }
     
    11281118 * @param   iCfg            The configuration to set.
    11291119 */
    1130 static int usbProxyLinuxSetConfig(PUSBPROXYDEV pProxyDev, int iCfg)
     1120static DECLCALLBACK(int) usbProxyLinuxSetConfig(PUSBPROXYDEV pProxyDev, int iCfg)
    11311121{
    11321122    LogFlow(("usbProxyLinuxSetConfig: pProxyDev=%s cfg=%#x\n",
     
    11461136 * @returns success indicator.
    11471137 */
    1148 static int usbProxyLinuxClaimInterface(PUSBPROXYDEV pProxyDev, int iIf)
     1138static DECLCALLBACK(int) usbProxyLinuxClaimInterface(PUSBPROXYDEV pProxyDev, int iIf)
    11491139{
    11501140    LogFlow(("usbProxyLinuxClaimInterface: pProxyDev=%s ifnum=%#x\n", usbProxyGetName(pProxyDev), iIf));
     
    12911281static bool usbProxyLinuxSubmitURB(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pCur, PVUSBURB pUrb, bool *pfUnplugged)
    12921282{
    1293     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     1283    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    12941284    unsigned        cTries = 0;
    12951285
     
    14631453 * @copydoc USBPROXYBACK::pfnUrbQueue
    14641454 */
    1465 static int usbProxyLinuxUrbQueue(PVUSBURB pUrb)
     1455static DECLCALLBACK(int) usbProxyLinuxUrbQueue(PVUSBURB pUrb)
    14661456{
    14671457    unsigned        cTries;
     
    14711461    PUSBPROXYDEV    pProxyDev = usbProxyFromVusbDev(pUrb->pDev);
    14721462#endif
    1473     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     1463    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    14741464    LogFlow(("usbProxyLinuxUrbQueue: pProxyDev=%s pUrb=%p EndPt=%d cbData=%d\n",
    14751465             usbProxyGetName(pProxyDev), pUrb, pUrb->EndPt, pUrb->cbData));
     
    17231713 * @param   cMillies    Number of milliseconds to wait. Use 0 to not wait at all.
    17241714 */
    1725 static PVUSBURB usbProxyLinuxUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
     1715static DECLCALLBACK(PVUSBURB) usbProxyLinuxUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
    17261716{
    17271717    PUSBPROXYURBLNX pUrbLnx = NULL;
    1728     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     1718    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    17291719
    17301720    /*
     
    19611951 * The URB requires reaping, so we don't change its state.
    19621952 */
    1963 static void usbProxyLinuxUrbCancel(PVUSBURB pUrb)
     1953static DECLCALLBACK(void) usbProxyLinuxUrbCancel(PVUSBURB pUrb)
    19641954{
    19651955#ifndef RDESKTOP
     
    20011991static DECLCALLBACK(int) usbProxyLinuxWakeup(PUSBPROXYDEV pProxyDev)
    20021992{
    2003     PUSBPROXYDEVLNX pDevLnx = (PUSBPROXYDEVLNX)pProxyDev->Backend.pv;
     1993    PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
    20041994    size_t cbIgnored;
    20051995
     
    20142004const USBPROXYBACK g_USBProxyDeviceHost =
    20152005{
     2006    /* pszName */
    20162007    "host",
     2008    /* cbBackend */
     2009    sizeof(USBPROXYDEVLNX),
    20172010    usbProxyLinuxOpen,
    20182011    usbProxyLinuxInit,
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette