- Timestamp:
- Apr 5, 2020 9:23:26 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp
r83568 r83569 975 975 976 976 /* req datain bytes already in guest phys mem. via virtioScsiIoReqCopyFromBuf() */ 977 /** @todo r=bird: There is too much allocating here and we'll leak stuff if 978 * we're low on memory and one of the RTMemAllocZ calls fail! */ 979 980 PRTSGBUF pReqSegBuf = (PRTSGBUF)RTMemAllocZ(sizeof(RTSGBUF)); 981 AssertReturn(pReqSegBuf, VERR_NO_MEMORY); 982 983 PRTSGSEG paReqSegs = (PRTSGSEG)RTMemAllocZ(sizeof(RTSGSEG) * 2); 984 AssertReturn(paReqSegs, VERR_NO_MEMORY); 985 986 int cSegs = 0; 987 paReqSegs[cSegs].pvSeg = &respHdr; 988 paReqSegs[cSegs++].cbSeg = sizeof(respHdr); 989 990 paReqSegs[cSegs].pvSeg = pReq->pbSense; 991 paReqSegs[cSegs++].cbSeg = pReq->cbSenseAlloc; /* VirtIO 1.0 spec 5.6.4/5.6.6.1 */ 992 993 /* Copy segment data to malloc'd memory to avoid stack out-of-scope errors sanitizer doesn't detect */ 994 /** @todo r=bird: The above comment makes zero sense as the memory is freed 995 * before we return, so there cannot be any trouble with out-of-scope 996 * stuff here. */ 997 for (int i = 0; i < cSegs; i++) 998 { 999 void *pv = paReqSegs[i].pvSeg; 1000 paReqSegs[i].pvSeg = RTMemDup(pv, paReqSegs[i].cbSeg); 1001 AssertReturn(paReqSegs[i].pvSeg, VERR_NO_MEMORY); 1002 } 1003 1004 RTSgBufInit(pReqSegBuf, paReqSegs, cSegs); 1005 1006 size_t cbReqSgBuf = RTSgBufCalcTotalLength(pReqSegBuf); 977 RTSGSEG aReqSegs[2]; 978 979 paReqSegs[0].pvSeg = &respHdr; 980 paReqSegs[0].cbSeg = sizeof(respHdr); 981 982 paReqSegs[1].pvSeg = pReq->pbSense; 983 paReqSegs[1].cbSeg = pReq->cbSenseAlloc; /* VirtIO 1.0 spec 5.6.4/5.6.6.1 */ 984 985 RTSGBUF ReqSgBuf 986 RTSgBufInit(&ReqSgBuf, aReqSegs, RT_ELEMENTS(aRegSegs)); 987 988 size_t cbReqSgBuf = RTSgBufCalcTotalLength(&ReqSgBuf); 989 /** @todo r=bird: Returning here looks a little bogus... */ 1007 990 AssertMsgReturn(cbReqSgBuf <= pReq->pDescChain->cbPhysReturn, 1008 ("Guest expected less req data (space needed: % d, avail: %d)\n",1009 1010 VERR_BUFFER_OVERFLOW);1011 1012 virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, pReq->qIdx, pReqSegBuf, pReq->pDescChain, true /* fFence TBD */);991 ("Guest expected less req data (space needed: %zu, avail: %u)\n", 992 cbReqSgBuf, pReq->pDescChain->cbPhysReturn), 993 VERR_BUFFER_OVERFLOW); 994 995 virtioCoreR3QueuePut(pDevIns, &pThis->Virtio, pReq->qIdx, &ReqSgBuf, pReq->pDescChain, true /* fFence TBD */); 1013 996 virtioCoreQueueSync(pDevIns, &pThis->Virtio, pReq->qIdx); 1014 1015 for (int i = 0; i < cSegs; i++)1016 RTMemFree(paReqSegs[i].pvSeg);1017 1018 RTMemFree(paReqSegs);1019 RTMemFree(pReqSegBuf);1020 997 1021 998 Log2(("-----------------------------------------------------------------------------------------\n")); … … 1027 1004 PDMDevHlpAsyncNotificationCompleted(pDevIns); 1028 1005 1029 return VINF_SUCCESS;1006 return rc; 1030 1007 } 1031 1008
Note:
See TracChangeset
for help on using the changeset viewer.