Skip to content

Commit a4bbfb1

Browse files
committed
[USBPORT]
- Rewrite USBPORT_FreeCommonBuffer, USBPORT_AllocateCommonBuffer
1 parent aca820c commit a4bbfb1

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

drivers/usb/usbport/usbport.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,6 @@ USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice,
17861786
PUSBPORT_DEVICE_EXTENSION FdoExtension;
17871787
PDMA_ADAPTER DmaAdapter;
17881788
PDMA_OPERATIONS DmaOperations;
1789-
SIZE_T HeaderSize;
17901789
ULONG Length = 0;
17911790
ULONG LengthPadded;
17921791
PHYSICAL_ADDRESS LogicalAddress;
@@ -1806,9 +1805,17 @@ USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice,
18061805
DmaAdapter = FdoExtension->DmaAdapter;
18071806
DmaOperations = DmaAdapter->DmaOperations;
18081807

1809-
HeaderSize = sizeof(USBPORT_COMMON_BUFFER_HEADER);
1810-
Length = ROUND_TO_PAGES(BufferLength + HeaderSize);
1811-
LengthPadded = Length - (BufferLength + HeaderSize);
1808+
Length = ROUND_TO_PAGES(BufferLength);
1809+
LengthPadded = Length - BufferLength;
1810+
1811+
ASSERT(DmaAdapter);
1812+
ASSERT(Length);
1813+
ASSERT(DmaOperations);
1814+
ASSERT(DmaOperations->AllocateCommonBuffer);
1815+
1816+
HeaderBuffer = (PUSBPORT_COMMON_BUFFER_HEADER)ExAllocatePoolZero(NonPagedPool, sizeof(USBPORT_COMMON_BUFFER_HEADER), USB_PORT_TAG);
1817+
if (!HeaderBuffer)
1818+
return NULL;
18121819

18131820
BaseVA = (ULONG_PTR)DmaOperations->AllocateCommonBuffer(DmaAdapter,
18141821
Length,
@@ -1817,13 +1824,10 @@ USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice,
18171824

18181825
if (!BaseVA)
18191826
goto Exit;
1820-
18211827
StartBufferVA = BaseVA & ~(PAGE_SIZE - 1);
1828+
18221829
StartBufferPA = LogicalAddress.LowPart & ~(PAGE_SIZE - 1);
18231830

1824-
HeaderBuffer = (PUSBPORT_COMMON_BUFFER_HEADER)(StartBufferVA +
1825-
BufferLength +
1826-
LengthPadded);
18271831

18281832
HeaderBuffer->Length = Length;
18291833
HeaderBuffer->BaseVA = BaseVA;
@@ -1833,8 +1837,7 @@ USBPORT_AllocateCommonBuffer(IN PDEVICE_OBJECT FdoDevice,
18331837
HeaderBuffer->VirtualAddress = StartBufferVA;
18341838
HeaderBuffer->PhysicalAddress = StartBufferPA;
18351839

1836-
RtlZeroMemory((PVOID)StartBufferVA, BufferLength + LengthPadded);
1837-
1840+
RtlZeroMemory((PVOID)StartBufferVA, BufferLength);
18381841
Exit:
18391842
return HeaderBuffer;
18401843
}
@@ -1854,12 +1857,17 @@ USBPORT_FreeCommonBuffer(IN PDEVICE_OBJECT FdoDevice,
18541857

18551858
DmaAdapter = FdoExtension->DmaAdapter;
18561859
DmaOperations = DmaAdapter->DmaOperations;
1860+
ASSERT(DmaAdapter);
1861+
ASSERT(DmaOperations);
1862+
ASSERT(FdoExtension->DmaAdapter);
18571863

18581864
DmaOperations->FreeCommonBuffer(FdoExtension->DmaAdapter,
18591865
HeaderBuffer->Length,
18601866
HeaderBuffer->LogicalAddress,
1861-
(PVOID)HeaderBuffer->VirtualAddress,
1867+
(PVOID)HeaderBuffer->BaseVA,
18621868
TRUE);
1869+
1870+
ExFreePool(HeaderBuffer);
18631871
}
18641872

18651873
PUSBPORT_MINIPORT_INTERFACE

0 commit comments

Comments
 (0)