VirtualBox

Changeset 93989 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 28, 2022 3:28:20 PM (3 years ago)
Author:
vboxsync
Message:

Devices/USB: Fix memory leak introduced by r150140, and get rid of the VUSBDEV member of the roothub which is not used anyway, bugref:10196

Location:
trunk/src/VBox/Devices/USB
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/DrvVUSBRootHub.cpp

    r93979 r93989  
    245245 * @param   pThis               The VUSB roothub device instance.
    246246 * @param   uPort               The port to get the device for.
     247 * @param   pszWho              Caller of this method.
    247248 *
    248249 * @note The reference count of the VUSB device structure is retained to prevent it from going away.
    249250 */
    250 static PVUSBDEV vusbR3RhGetVUsbDevByPortRetain(PVUSBROOTHUB pThis, uint32_t uPort)
     251static PVUSBDEV vusbR3RhGetVUsbDevByPortRetain(PVUSBROOTHUB pThis, uint32_t uPort, const char *pszWho)
    251252{
    252253    PVUSBDEV pDev = NULL;
     
    258259    pDev = pThis->apDevByPort[uPort];
    259260    if (RT_LIKELY(pDev))
    260         vusbDevRetain(pDev);
     261        vusbDevRetain(pDev, pszWho);
    261262
    262263    RTCritSectLeave(&pThis->CritSectDevices);
     
    272273 * @param   pThis               The VUSB roothub device instance.
    273274 * @param   u8Address           The address to get the device for.
     275 * @param   pszWho              Caller of this method.
    274276 *
    275277 * @note The reference count of the VUSB device structure is retained to prevent it from going away.
    276278 */
    277 static PVUSBDEV vusbR3RhGetVUsbDevByAddrRetain(PVUSBROOTHUB pThis, uint8_t u8Address)
     279static PVUSBDEV vusbR3RhGetVUsbDevByAddrRetain(PVUSBROOTHUB pThis, uint8_t u8Address, const char *pszWho)
    278280{
    279281    PVUSBDEV pDev = NULL;
     
    285287    pDev = pThis->apDevByAddr[u8Address];
    286288    if (RT_LIKELY(pDev))
    287         vusbDevRetain(pDev);
     289        vusbDevRetain(pDev, pszWho);
    288290
    289291    RTCritSectLeave(&pThis->CritSectDevices);
     
    466468        pUsbIns->pvVUsbDev2 = NULL;
    467469    }
    468     vusbDevRelease(pDev);
     470    vusbDevRelease(pDev, "vusbPDMHubAttachDevice");
    469471    return rc;
    470472}
     
    487489    vusbDevSetStateCmp(pDev, VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_RESET);
    488490    vusbHubDetach(pThis, pDev);
    489     vusbDevRelease(pDev);
     491    vusbDevRelease(pDev, "vusbPDMHubDetachDevice");
    490492    return VINF_SUCCESS;
    491493}
     
    521523    Assert(pUrb->enmState != VUSBURBSTATE_FREE);
    522524
     525#ifdef LOG_ENABLED
     526    vusbUrbTrace(pUrb, "vusbRhFreeUrb", true);
     527#endif
     528
    523529    /*
    524530     * Free the URB description (logging builds only).
     
    536542
    537543        vusbUrbPoolFree(&pUrb->pVUsb->pDev->UrbPool, pUrb);
    538         vusbDevRelease(pDev);
     544        vusbDevRelease(pDev, "vusbRhFreeUrb");
    539545    }
    540546    else
    541         vusbUrbPoolFree(&pRh->Dev.UrbPool, pUrb);
     547        vusbUrbPoolFree(&pRh->UrbPool, pUrb);
    542548}
    543549
     
    550556{
    551557    RT_NOREF(pszTag);
    552     PVUSBURBPOOL pUrbPool = &pRh->Dev.UrbPool;
     558    PVUSBURBPOOL pUrbPool = &pRh->UrbPool;
    553559
    554560    if (RT_UNLIKELY(cbData > (32 * _1M)))
     
    560566    PVUSBDEV pDev;
    561567    if (uPort == VUSB_DEVICE_PORT_INVALID)
    562         pDev = vusbR3RhGetVUsbDevByAddrRetain(pRh, DstAddress);
     568        pDev = vusbR3RhGetVUsbDevByAddrRetain(pRh, DstAddress, "vusbRhNewUrb");
    563569    else
    564         pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort);
     570        pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort, "vusbRhNewUrb");
    565571
    566572    if (pDev)
     
    602608                     (pUrb->enmDir == VUSBDIRECTION_IN) ? '<' : ((pUrb->enmDir == VUSBDIRECTION_SETUP) ? 's' : '>'),
    603609                     pRh->iSerial, pszTag ? pszTag : "<none>");
     610
     611        vusbUrbTrace(pUrb, "vusbRhNewUrb", false);
    604612#endif
    605613    }
     
    817825    LogFlow(("vusR3bRhPowerOn: pRh=%p\n", pRh));
    818826
    819     Assert(     pRh->Dev.enmState != VUSB_DEVICE_STATE_DETACHED
    820            &&   pRh->Dev.enmState != VUSB_DEVICE_STATE_RESET);
    821 
    822     if (pRh->Dev.enmState == VUSB_DEVICE_STATE_ATTACHED)
    823         pRh->Dev.enmState = VUSB_DEVICE_STATE_POWERED;
     827    Assert(     pRh->enmState != VUSB_DEVICE_STATE_DETACHED
     828           &&   pRh->enmState != VUSB_DEVICE_STATE_RESET);
     829
     830    if (pRh->enmState == VUSB_DEVICE_STATE_ATTACHED)
     831        pRh->enmState = VUSB_DEVICE_STATE_POWERED;
    824832
    825833    return VINF_SUCCESS;
     
    833841    LogFlow(("vusbR3RhDevPowerOff: pThis=%p\n", pThis));
    834842
    835     Assert(     pThis->Dev.enmState != VUSB_DEVICE_STATE_DETACHED
    836            &&   pThis->Dev.enmState != VUSB_DEVICE_STATE_RESET);
     843    Assert(     pThis->enmState != VUSB_DEVICE_STATE_DETACHED
     844           &&   pThis->enmState != VUSB_DEVICE_STATE_RESET);
    837845
    838846    /*
     
    843851        VUSBIRhReapAsyncUrbs(&pThis->IRhConnector, uPort, 0);
    844852
    845     pThis->Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
     853    pThis->enmState = VUSB_DEVICE_STATE_ATTACHED;
    846854    return VINF_SUCCESS;
    847855}
     
    944952    else
    945953    {
    946         vusbDevRetain(&pRh->Dev);
    947         pUrb->pVUsb->pDev = &pRh->Dev;
    948954        Log(("vusb: pRh=%p: SUBMIT: Address %i not found!!!\n", pRh, pUrb->DstAddress));
    949955
     
    980986{
    981987    PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface); NOREF(pRh);
    982     PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort);
    983 
    984     if (  !pDev
    985         || RTListIsEmpty(&pDev->LstAsyncUrbs))
     988    PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort, "vusbRhReapAsyncUrbs");
     989
     990    if (!pDev)
    986991        return;
    987992
    988     STAM_PROFILE_START(&pRh->StatReapAsyncUrbs, a);
    989     int rc = vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhReapAsyncUrbsWorker, 2, pDev, cMillies);
    990     AssertRC(rc);
    991     STAM_PROFILE_STOP(&pRh->StatReapAsyncUrbs, a);
    992 
    993     vusbDevRelease(pDev);
     993    if (!RTListIsEmpty(&pDev->LstAsyncUrbs))
     994    {
     995        STAM_PROFILE_START(&pRh->StatReapAsyncUrbs, a);
     996        int rc = vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhReapAsyncUrbsWorker, 2, pDev, cMillies);
     997        AssertRC(rc);
     998        STAM_PROFILE_STOP(&pRh->StatReapAsyncUrbs, a);
     999    }
     1000
     1001    vusbDevRelease(pDev, "vusbRhReapAsyncUrbs");
    9941002}
    9951003
     
    10941102{
    10951103    PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1096     PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort);
     1104    PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort, "vusbRhAbortEp");
    10971105
    10981106    if (pDev->pHub != pRh)
     
    11001108
    11011109    vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhAbortEpWorker, 3, pDev, EndPt, enmDir);
    1102     vusbDevRelease(pDev);
     1110    vusbDevRelease(pDev, "vusbRhAbortEp");
    11031111
    11041112    /* The reaper thread will take care of completing the URB. */
     
    11871195    PVUSBROOTHUB    pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    11881196    AssertReturn(pRh, 0);
    1189     PVUSBDEV        pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort); AssertPtr(pDev);
     1197    PVUSBDEV        pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort, "vusbRhUpdateIsocFrameDelta"); AssertPtr(pDev);
    11901198    PVUSBPIPE       pPipe = &pDev->aPipes[EndPt];
    11911199    uint32_t        *puLastFrame;
     
    12001208        uFrameDelta += uMaxVal;
    12011209
    1202     vusbDevRelease(pDev);
     1210    vusbDevRelease(pDev, "vusbRhUpdateIsocFrameDelta");
    12031211    return (uint16_t)uFrameDelta;
    12041212}
     
    12101218{
    12111219    PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1212     PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
     1220    PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort, "vusbR3RhDevReset");
    12131221    AssertPtr(pDev);
    12141222
    12151223    int rc = VUSBIDevReset(&pDev->IDevice, fResetOnLinux, pfnDone, pvUser, pVM);
    1216     vusbDevRelease(pDev);
     1224    vusbDevRelease(pDev, "vusbR3RhDevReset");
    12171225    return rc;
    12181226}
     
    12231231{
    12241232    PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1225     PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
     1233    PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort, "vusbR3RhDevPowerOn");
    12261234    AssertPtr(pDev);
    12271235
    12281236    int rc = VUSBIDevPowerOn(&pDev->IDevice);
    1229     vusbDevRelease(pDev);
     1237    vusbDevRelease(pDev, "vusbR3RhDevPowerOn");
    12301238    return rc;
    12311239}
     
    12361244{
    12371245    PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1238     PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
     1246    PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort, "vusbR3RhDevPowerOff");
    12391247    AssertPtr(pDev);
    12401248
    12411249    int rc = VUSBIDevPowerOff(&pDev->IDevice);
    1242     vusbDevRelease(pDev);
     1250    vusbDevRelease(pDev, "vusbR3RhDevPowerOff");
    12431251    return rc;
    12441252}
     
    12491257{
    12501258    PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1251     PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
     1259    PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort, "vusbR3RhDevGetState");
    12521260    AssertPtr(pDev);
    12531261
    12541262    VUSBDEVICESTATE enmState = VUSBIDevGetState(&pDev->IDevice);
    1255     vusbDevRelease(pDev);
     1263    vusbDevRelease(pDev, "vusbR3RhDevGetState");
    12561264    return enmState;
    12571265}
     
    12621270{
    12631271    PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1264     PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
     1272    PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort, "vusbR3RhDevIsSavedStateSupported");
    12651273    AssertPtr(pDev);
    12661274
    12671275    bool fSavedStateSupported = VUSBIDevIsSavedStateSupported(&pDev->IDevice);
    1268     vusbDevRelease(pDev);
     1276    vusbDevRelease(pDev, "vusbR3RhDevIsSavedStateSupported");
    12691277    return fSavedStateSupported;
    12701278}
     
    12751283{
    12761284    PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
    1277     PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
     1285    PVUSBDEV     pDev  = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort, "vusbR3RhDevGetSpeed");
    12781286    AssertPtr(pDev);
    12791287
    12801288    VUSBSPEED enmSpeed = pDev->IDevice.pfnGetSpeed(&pDev->IDevice);
    1281     vusbDevRelease(pDev);
     1289    vusbDevRelease(pDev, "vusbR3RhDevGetSpeed");
    12821290    return enmSpeed;
    12831291}
     
    15091517    PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
    15101518
    1511     vusbUrbPoolDestroy(&pRh->Dev.UrbPool);
     1519    vusbUrbPoolDestroy(&pRh->UrbPool);
    15121520    if (pRh->pszName)
    15131521    {
     
    15731581    pDrvIns->IBase.pfnQueryInterface    = vusbRhQueryInterface;
    15741582    /* the usb device */
    1575     pThis->Dev.enmState                 = VUSB_DEVICE_STATE_ATTACHED;
    1576     pThis->Dev.cRefs                    = 1;
     1583    pThis->enmState                     = VUSB_DEVICE_STATE_ATTACHED;
    15771584    //pThis->hub.cPorts                - later
    15781585    pThis->cDevices                     = 0;
    1579     pThis->Dev.pHub                     = pThis;
    15801586    RTStrAPrintf(&pThis->pszName, "RootHub#%d", pDrvIns->iInstance);
    15811587    /* misc */
     
    16291635    Log(("vusbRhConstruct: fHcVersions=%u\n", pThis->fHcVersions));
    16301636
    1631     rc = vusbUrbPoolInit(&pThis->Dev.UrbPool);
     1637    rc = vusbUrbPoolInit(&pThis->UrbPool);
    16321638    if (RT_FAILURE(rc))
    16331639        return rc;
     
    17921798                           "/VUSB/%d/FramesProcessedClbk",     pDrvIns->iInstance);
    17931799#endif
    1794     PDMDrvHlpSTAMRegisterF(pDrvIns, (void *)&pThis->Dev.UrbPool.cUrbsInPool, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs in the pool.",
     1800    PDMDrvHlpSTAMRegisterF(pDrvIns, (void *)&pThis->UrbPool.cUrbsInPool, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs in the pool.",
    17951801                           "/VUSB/%d/cUrbsInPool",             pDrvIns->iInstance);
    17961802
  • trunk/src/VBox/Devices/USB/VUSBDevice.cpp

    r93979 r93989  
    13771377    pDev->u16Status = 0;
    13781378    vusbDevDoSelectConfig(pDev, &g_Config0);
    1379     if (!vusbDevIsRh(pDev))
    1380         vusbDevSetAddress(pDev, VUSB_DEFAULT_ADDRESS);
     1379    vusbDevSetAddress(pDev, VUSB_DEFAULT_ADDRESS);
    13811380    if (pfnDone)
    13821381        pfnDone(&pDev->IDevice, pDev->i16Port, rc, pvUser);
     
    15851584        LogRel(("VUSB: %s: power off ignored, the device is resetting!\n", pDev->pUsbIns->pszName));
    15861585        return VERR_VUSB_DEVICE_IS_RESETTING;
    1587     }
    1588 
    1589     /*
    1590      * If it's a root hub, we will have to cancel all URBs and reap them.
    1591      */
    1592     if (vusbDevIsRh(pDev))
    1593     {
    1594         PVUSBROOTHUB pRh = (PVUSBROOTHUB)pDev;
    1595         VUSBIRhCancelAllUrbs(&pRh->IRhConnector);
    1596         VUSBIRhReapAsyncUrbs(&pRh->IRhConnector, pDev->i16Port, 0);
    15971586    }
    15981587
  • trunk/src/VBox/Devices/USB/VUSBInternal.h

    r93979 r93989  
    291291int vusbDevInit(PVUSBDEV pDev, PPDMUSBINS pUsbIns, const char *pszCaptureFilename);
    292292void vusbDevDestroy(PVUSBDEV pDev);
    293 
    294 DECLINLINE(bool) vusbDevIsRh(PVUSBDEV pDev)
    295 {
    296     return (pDev->pHub == (PVUSBROOTHUB)pDev);
    297 }
    298 
    299293bool vusbDevDoSelectConfig(PVUSBDEV dev, PCVUSBDESCCONFIGEX pCfg);
    300294void vusbDevMapEndpoint(PVUSBDEV dev, PCVUSBDESCENDPOINTEX ep);
     
    355349typedef struct VUSBROOTHUB
    356350{
    357     /** VUSB device data for the roothub @todo Remove. */
    358     VUSBDEV                     Dev;
    359351    /** Pointer to the driver instance. */
    360352    PPDMDRVINS                  pDrvIns;
     
    373365    PVUSBROOTHUBLOAD            pLoad;
    374366
     367    /** Roothub device state. */
     368    VUSBDEVICESTATE             enmState;
    375369    /** Number of ports this roothub offers. */
    376370    uint16_t                    cPorts;
     
    379373    /** Name of the roothub. Used for logging. */
    380374    char                        *pszName;
     375    /** URB pool for URBs from the roothub. */
     376    VUSBURBPOOL                 UrbPool;
    381377
    382378#if HC_ARCH_BITS == 32
     
    676672 * @returns New reference count.
    677673 * @param   pThis          The VUSB device pointer.
    678  */
    679 DECLINLINE(uint32_t) vusbDevRetain(PVUSBDEV pThis)
     674 * @param   pszWho         Caller of the retaining.
     675 */
     676DECLINLINE(uint32_t) vusbDevRetain(PVUSBDEV pThis, const char *pszWho)
    680677{
    681678    AssertPtrReturn(pThis, UINT32_MAX);
    682679
    683680    uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
     681    LogFlowFunc(("pThis=%p{.cRefs=%u}[%s]\n", pThis, cRefs, pszWho)); RT_NOREF(pszWho);
    684682    AssertMsg(cRefs > 1 && cRefs < _1M, ("%#x %p\n", cRefs, pThis));
    685683    return cRefs;
     
    691689 * @returns New reference count.
    692690 * @retval 0 if no onw is holding a reference anymore causing the device to be destroyed.
    693  */
    694 DECLINLINE(uint32_t) vusbDevRelease(PVUSBDEV pThis)
     691 * @param   pThis          The VUSB device pointer.
     692 * @param   pszWho         Caller of the retaining.
     693 */
     694DECLINLINE(uint32_t) vusbDevRelease(PVUSBDEV pThis, const char *pszWho)
    695695{
    696696    AssertPtrReturn(pThis, UINT32_MAX);
    697697
    698698    uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
     699    LogFlowFunc(("pThis=%p{.cRefs=%u}[%s]\n", pThis, cRefs, pszWho)); RT_NOREF(pszWho);
    699700    AssertMsg(cRefs < _1M, ("%#x %p\n", cRefs, pThis));
    700701    if (cRefs == 0)
  • trunk/src/VBox/Devices/USB/VUSBUrbTrace.cpp

    r93115 r93989  
    147147{
    148148    PVUSBDEV        pDev   = pUrb->pVUsb ? pUrb->pVUsb->pDev : NULL; /* Can be NULL when called from usbProxyConstruct and friends. */
    149     PVUSBPIPE       pPipe  = &pDev->aPipes[pUrb->EndPt];
     149    PVUSBPIPE       pPipe  = pDev ? &pDev->aPipes[pUrb->EndPt] : NULL;
    150150    const uint8_t  *pbData = pUrb->abData;
    151151    uint32_t        cbData = pUrb->cbData;
Note: See TracChangeset for help on using the changeset viewer.

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