[WDMAUD_KERNEL]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 11 Jun 2010 12:28:10 +0000 (12:28 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 11 Jun 2010 12:28:10 +0000 (12:28 +0000)
- Perform all allocations / frees in dedicated alloc / free function

svn path=/trunk/; revision=47754

reactos/drivers/wdm/audio/legacy/wdmaud/control.c
reactos/drivers/wdm/audio/legacy/wdmaud/deviface.c
reactos/drivers/wdm/audio/legacy/wdmaud/entry.c
reactos/drivers/wdm/audio/legacy/wdmaud/mmixer.c
reactos/drivers/wdm/audio/legacy/wdmaud/sup.c
reactos/drivers/wdm/audio/legacy/wdmaud/wdmaud.h

index 4fc1d67..3af87b8 100644 (file)
@@ -251,7 +251,7 @@ WdmAudGetDeviceInterface(
             RtlMoveMemory(DeviceInfo->u.Interface.DeviceInterfaceString, Device, Length);
         }
 
-        ExFreePool(Device);
+        FreeItem(Device);
         return SetIrpIoStatus(Irp, STATUS_SUCCESS, sizeof(WDMAUD_DEVICE_INFO));
     }
     else if (DeviceInfo->DeviceType == MIXER_DEVICE_TYPE)
index 8330917..d191a97 100644 (file)
@@ -65,7 +65,7 @@ WdmAudOpenSysAudioDeviceInterfaces(
     while(*SymbolicLinkList)
     {
         Length = wcslen(SymbolicLinkList) + 1;
-        Entry = (SYSAUDIO_ENTRY*)ExAllocatePool(NonPagedPool, sizeof(SYSAUDIO_ENTRY) + Length * sizeof(WCHAR));
+        Entry = (SYSAUDIO_ENTRY*)AllocateItem(NonPagedPool, sizeof(SYSAUDIO_ENTRY) + Length * sizeof(WCHAR));
         if (!Entry)
         {
             return STATUS_INSUFFICIENT_RESOURCES;
@@ -108,7 +108,7 @@ WdmAudOpenSysAudioDevices(
         if (NT_SUCCESS(Status))
         {
             WdmAudOpenSysAudioDeviceInterfaces(DeviceExtension, SymbolicLinkList);
-            ExFreePool(SymbolicLinkList);
+            FreeItem(SymbolicLinkList);
         }
 
 
@@ -123,7 +123,7 @@ WdmAudOpenSysAudioDevices(
     else
     {
             Length = wcslen(DeviceName.Buffer) + 1;
-            Entry = (SYSAUDIO_ENTRY*)ExAllocatePool(NonPagedPool, sizeof(SYSAUDIO_ENTRY) + Length * sizeof(WCHAR));
+            Entry = (SYSAUDIO_ENTRY*)AllocateItem(NonPagedPool, sizeof(SYSAUDIO_ENTRY) + Length * sizeof(WCHAR));
             if (!Entry)
             {
                 return STATUS_INSUFFICIENT_RESOURCES;
@@ -218,7 +218,7 @@ WdmAudOpenSysaudio(
     ASSERT(!IsListEmpty(&DeviceExtension->SysAudioDeviceList));
 
     /* allocate client context struct */
-    Client = ExAllocatePool(NonPagedPool, sizeof(WDMAUD_CLIENT));
+    Client = AllocateItem(NonPagedPool, sizeof(WDMAUD_CLIENT));
 
     /* check for allocation failure */
     if (!Client)
index 20421ea..5953e33 100644 (file)
@@ -240,10 +240,10 @@ WdmAudCleanup(
 
     /* free pin array */
     if (pClient->hPins)
-        ExFreePool(pClient->hPins);
+        FreeItem(pClient->hPins);
 
     /* free client context struct */
-    ExFreePool(pClient);
+    FreeItem(pClient);
 
     /* clear old client pointer */
     IoStack->FileObject->FsContext = NULL;
index cf58846..397bf99 100644 (file)
@@ -65,7 +65,7 @@ QueryKeyValue(
         return MM_STATUS_UNSUCCESSFUL;
 
     /* allocate a buffer for key data */
-    PartialInformation = ExAllocatePool(NonPagedPool, Length);
+    PartialInformation = AllocateItem(NonPagedPool, Length);
 
     if (!PartialInformation)
         return MM_STATUS_NO_MEMORY;
@@ -77,7 +77,7 @@ QueryKeyValue(
     /* check for success */
     if (!NT_SUCCESS(Status))
     {
-        ExFreePool(PartialInformation);
+        FreeItem(PartialInformation);
         return MM_STATUS_UNSUCCESSFUL;
     }
 
@@ -93,11 +93,11 @@ QueryKeyValue(
         *ResultLength = PartialInformation->DataLength;
     }
 
-    *ResultBuffer = ExAllocatePool(NonPagedPool, PartialInformation->DataLength);
+    *ResultBuffer = AllocateItem(NonPagedPool, PartialInformation->DataLength);
     if (!*ResultBuffer)
     {
         /* not enough memory */
-        ExFreePool(PartialInformation);
+        FreeItem(PartialInformation);
         return MM_STATUS_NO_MEMORY;
     }
 
@@ -105,7 +105,7 @@ QueryKeyValue(
     RtlMoveMemory(*ResultBuffer, PartialInformation->Data, PartialInformation->DataLength);
 
     /* free key info */
-    ExFreePool(PartialInformation);
+    FreeItem(PartialInformation);
 
     return MM_STATUS_SUCCESS;
 }
@@ -149,12 +149,7 @@ CloseKey(
 
 PVOID Alloc(ULONG NumBytes)
 {
-    PVOID Mem = ExAllocatePool(NonPagedPool, NumBytes);
-    if (!Mem)
-        return Mem;
-
-    RtlZeroMemory(Mem, NumBytes);
-    return Mem;
+    return AllocateItem(NonPagedPool, NumBytes);
 }
 
 MIXER_STATUS
@@ -169,7 +164,7 @@ Close(HANDLE hDevice)
 VOID
 Free(PVOID Block)
 {
-    ExFreePool(Block);
+    FreeItem(Block);
 }
 
 VOID
@@ -277,7 +272,7 @@ Enum(
     {
         /* failed to open key */
         DPRINT("IoOpenDeviceInterfaceRegistryKey failed with %lx\n", Status);
-        ExFreePool(*DeviceName);
+        FreeItem(*DeviceName);
         return MM_STATUS_UNSUCCESSFUL;
     }
 #endif
@@ -297,14 +292,14 @@ PVOID
 AllocEventData(
     IN ULONG ExtraSize)
 {
-    PKSEVENTDATA Data = (PKSEVENTDATA)ExAllocatePool(NonPagedPool, sizeof(KSEVENTDATA) + ExtraSize);
+    PKSEVENTDATA Data = (PKSEVENTDATA)AllocateItem(NonPagedPool, sizeof(KSEVENTDATA) + ExtraSize);
     if (!Data)
         return NULL;
 
-    Data->EventObject.Event = ExAllocatePool(NonPagedPool, sizeof(KEVENT));
+    Data->EventObject.Event = AllocateItem(NonPagedPool, sizeof(KEVENT));
     if (!Data->EventHandle.Event)
     {
-        ExFreePool(Data);
+        FreeItem(Data);
         return NULL;
     }
 
@@ -319,8 +314,8 @@ FreeEventData(IN PVOID EventData)
 {
     PKSEVENTDATA Data = (PKSEVENTDATA)EventData;
 
-    ExFreePool(Data->EventHandle.Event);
-    ExFreePool(Data);
+    FreeItem(Data->EventHandle.Event);
+    FreeItem(Data);
 }
 
 NTSTATUS
@@ -391,14 +386,14 @@ WdmAudControlOpenMixer(
     }
 
 
-    Handles = ExAllocatePool(NonPagedPool, sizeof(WDMAUD_HANDLE) * (ClientInfo->NumPins+1));
+    Handles = AllocateItem(NonPagedPool, sizeof(WDMAUD_HANDLE) * (ClientInfo->NumPins+1));
 
     if (Handles)
     {
         if (ClientInfo->NumPins)
         {
             RtlMoveMemory(Handles, ClientInfo->hPins, sizeof(WDMAUD_HANDLE) * ClientInfo->NumPins);
-            ExFreePool(ClientInfo->hPins);
+            FreeItem(ClientInfo->hPins);
         }
 
         ClientInfo->hPins = Handles;
index 5820abc..5083bcc 100644 (file)
@@ -8,6 +8,28 @@
  */
 #include "wdmaud.h"
 
+PVOID
+AllocateItem(
+    IN POOL_TYPE PoolType,
+    IN SIZE_T NumberOfBytes)
+{
+    PVOID Item = ExAllocatePool(PoolType, NumberOfBytes);
+    if (!Item)
+        return Item;
+
+    RtlZeroMemory(Item, NumberOfBytes);
+    return Item;
+}
+
+VOID
+FreeItem(
+    IN PVOID Item)
+{
+    ExFreePool(Item);
+}
+
+
+
 ULONG
 GetSysAudioDeviceCount(
     IN  PDEVICE_OBJECT DeviceObject)
@@ -92,7 +114,7 @@ InsertPinHandle(
         return STATUS_SUCCESS;
     }
 
-    Handles = ExAllocatePool(NonPagedPool, sizeof(WDMAUD_HANDLE) * (ClientInfo->NumPins+1));
+    Handles = AllocateItem(NonPagedPool, sizeof(WDMAUD_HANDLE) * (ClientInfo->NumPins+1));
 
     if (!Handles)
         return STATUS_INSUFFICIENT_RESOURCES;
@@ -100,7 +122,7 @@ InsertPinHandle(
     if (ClientInfo->NumPins)
     {
         RtlMoveMemory(Handles, ClientInfo->hPins, sizeof(WDMAUD_HANDLE) * ClientInfo->NumPins);
-        ExFreePool(ClientInfo->hPins);
+        FreeItem(ClientInfo->hPins);
     }
 
     ClientInfo->hPins = Handles;
@@ -130,7 +152,7 @@ ReadKeyValue(
         return NULL;
 
     /* allocate a buffer for key data */
-    PartialInformation = ExAllocatePool(NonPagedPool, Length);
+    PartialInformation = AllocateItem(NonPagedPool, Length);
 
     if (!PartialInformation)
         return NULL;
@@ -142,14 +164,14 @@ ReadKeyValue(
     /* check for success */
     if (!NT_SUCCESS(Status))
     {
-        ExFreePool(PartialInformation);
+        FreeItem(PartialInformation);
         return NULL;
     }
 
     if (PartialInformation->Type != REG_SZ)
     {
         /* invalid key type */
-        ExFreePool(PartialInformation);
+        FreeItem(PartialInformation);
         return NULL;
     }
 
@@ -189,12 +211,12 @@ CompareProductName(
 
     if (_wcsnicmp((LPWSTR)PartialInformation->Data, &PnpName[4], Length))
     {
-        ExFreePool(PartialInformation);
+        FreeItem(PartialInformation);
         return STATUS_NO_MATCH;
     }
 
     /* free buffer */
-    ExFreePool(PartialInformation);
+    FreeItem(PartialInformation);
 
     /* read DriverDescName value */
     PartialInformation = ReadKeyValue(hSubKey, &DriverDescName);
@@ -213,7 +235,7 @@ CompareProductName(
     ProductName[ProductNameSize-1] = L'\0';
 
     /* free buffer */
-    ExFreePool(PartialInformation);
+    FreeItem(PartialInformation);
 
     return STATUS_SUCCESS;
 }
@@ -265,7 +287,7 @@ FindProductName(
     }
 
     /* allocate key information struct */
-    KeyInformation = ExAllocatePool(NonPagedPool, Length);
+    KeyInformation = AllocateItem(NonPagedPool, Length);
     if (!KeyInformation)
     {
         /* no memory */
@@ -279,7 +301,7 @@ FindProductName(
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("ZwQueryKey failed with %x\n", Status);
-        ExFreePool(KeyInformation);
+        FreeItem(KeyInformation);
         ZwClose(hKey);
         return Status;
     }
@@ -314,7 +336,7 @@ FindProductName(
     }
 
     /* free buffer */
-    ExFreePool(KeyInformation);
+    FreeItem(KeyInformation);
 
     /* close key */
     ZwClose(hKey);
@@ -354,7 +376,7 @@ GetSysAudioDevicePnpName(
         return STATUS_UNSUCCESSFUL;
 
     /* allocate buffer for the device */
-    *Device = ExAllocatePool(NonPagedPool, BytesReturned);
+    *Device = AllocateItem(NonPagedPool, BytesReturned);
     if (!Device)
         return STATUS_INSUFFICIENT_RESOURCES;
 
@@ -364,7 +386,7 @@ GetSysAudioDevicePnpName(
     if (!NT_SUCCESS(Status))
     {
         /* failed */
-        ExFreePool(*Device);
+        FreeItem(*Device);
         return Status;
     }
 
index 459b6c7..0258c8e 100644 (file)
@@ -276,3 +276,14 @@ WdmAudGetPnpNameByIndexAndType(
 ULONG
 GetSysAudioDeviceCount(
     IN  PDEVICE_OBJECT DeviceObject);
+
+
+PVOID
+AllocateItem(
+    IN POOL_TYPE PoolType,
+    IN SIZE_T NumberOfBytes);
+
+VOID
+FreeItem(
+    IN PVOID Item);
+