Avoid allocating second MDL
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
ca120aa1c0
commit
be8d2cb071
14
wintun.c
14
wintun.c
@ -704,15 +704,8 @@ static NTSTATUS TunDispatchWrite(_Inout_ TUN_CTX *ctx, _Inout_ IRP *Irp)
|
|||||||
goto cleanup_nbl_queues;
|
goto cleanup_nbl_queues;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDL *mdl = NdisAllocateMdl(ctx->MiniportAdapterHandle, p->Data, p->Size);
|
NET_BUFFER_LIST *nbl = NdisAllocateNetBufferAndNetBufferList(ctx->NBLPool, 0, 0, Irp->MdlAddress, (ULONG)(p->Data - buffer), p->Size);
|
||||||
if (!mdl) {
|
|
||||||
status = STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
goto cleanup_nbl_queues;
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_BUFFER_LIST *nbl = NdisAllocateNetBufferAndNetBufferList(ctx->NBLPool, 0, 0, mdl, 0, p->Size);
|
|
||||||
if (!nbl) {
|
if (!nbl) {
|
||||||
NdisFreeMdl(mdl);
|
|
||||||
status = STATUS_INSUFFICIENT_RESOURCES;
|
status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
goto cleanup_nbl_queues;
|
goto cleanup_nbl_queues;
|
||||||
}
|
}
|
||||||
@ -763,7 +756,6 @@ cleanup_nbl_queues:
|
|||||||
for (NET_BUFFER_LIST *nbl = nbl_queue[idx].head, *nbl_next; nbl; nbl = nbl_next) {
|
for (NET_BUFFER_LIST *nbl = nbl_queue[idx].head, *nbl_next; nbl; nbl = nbl_next) {
|
||||||
nbl_next = NET_BUFFER_LIST_NEXT_NBL(nbl);
|
nbl_next = NET_BUFFER_LIST_NEXT_NBL(nbl);
|
||||||
NET_BUFFER_LIST_NEXT_NBL(nbl) = NULL;
|
NET_BUFFER_LIST_NEXT_NBL(nbl) = NULL;
|
||||||
NdisFreeMdl(NET_BUFFER_FIRST_MDL(NET_BUFFER_LIST_FIRST_NB(nbl)));
|
|
||||||
NdisFreeNetBufferList(nbl);
|
NdisFreeNetBufferList(nbl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -786,15 +778,13 @@ static void TunReturnNetBufferLists(NDIS_HANDLE MiniportAdapterContext, PNET_BUF
|
|||||||
NET_BUFFER_LIST_NEXT_NBL(nbl) = NULL;
|
NET_BUFFER_LIST_NEXT_NBL(nbl) = NULL;
|
||||||
|
|
||||||
IRP *irp = NET_BUFFER_LIST_IRP(nbl);
|
IRP *irp = NET_BUFFER_LIST_IRP(nbl);
|
||||||
MDL *mdl = NET_BUFFER_FIRST_MDL(NET_BUFFER_LIST_FIRST_NB(nbl));
|
|
||||||
if (NT_SUCCESS(NET_BUFFER_LIST_STATUS(nbl))) {
|
if (NT_SUCCESS(NET_BUFFER_LIST_STATUS(nbl))) {
|
||||||
ULONG p_size = MmGetMdlByteCount(mdl);
|
ULONG p_size = NET_BUFFER_LIST_FIRST_NB(nbl)->DataLength;
|
||||||
stat_size += p_size;
|
stat_size += p_size;
|
||||||
stat_p_ok++;
|
stat_p_ok++;
|
||||||
} else
|
} else
|
||||||
stat_p_err++;
|
stat_p_err++;
|
||||||
|
|
||||||
NdisFreeMdl(mdl);
|
|
||||||
NdisFreeNetBufferList(nbl);
|
NdisFreeNetBufferList(nbl);
|
||||||
TunCompletePause(ctx, TRUE);
|
TunCompletePause(ctx, TRUE);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user