Author: janderwald
Date: Thu Aug 6 22:44:53 2009
New Revision: 42438
URL:
http://svn.reactos.org/svn/reactos?rev=42438&view=rev
Log:
- Check if translated / untranslated resource list is empty
- If both are empty, create an empty resource list
- May fix a crash with Yamaha XG Pci
Modified:
trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.c
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/resource.c [iso-8859-1] Thu Aug 6
22:44:53 2009
@@ -351,13 +351,31 @@
IN PCM_RESOURCE_LIST UntranslatedResourceList)
{
PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
- ULONG NewTranslatedSize, NewUntranslatedSize;
+ ULONG NewTranslatedSize, NewUntranslatedSize, ResourceCount;
IResourceListImpl* NewList;
- /* TODO: Validate parameters */
-
+ if (!TranslatedResourceList)
+ {
+ /* if the untranslated resource list is also not provided, it becomes an empty
resource list */
+ if (UntranslatedResourceList)
+ {
+ /* invalid parameter mix */
+ return STATUS_INVALID_PARAMETER;
+ }
+ }
+ else
+ {
+ /* if the translated resource list is also not provided, it becomes an empty
resource list */
+ if (!UntranslatedResourceList)
+ {
+ /* invalid parameter mix */
+ return STATUS_INVALID_PARAMETER;
+ }
+ }
+
+ /* allocate resource list ctx */
NewList = AllocateItem(PoolType, sizeof(IResourceListImpl), TAG_PORTCLASS);
-
+ /* check for success */
if (!NewList)
{
DPRINT("AllocateItem failed\n");
@@ -365,39 +383,50 @@
}
/* Initialize */
-
- NewTranslatedSize = sizeof(CM_RESOURCE_LIST);
- if (TranslatedResourceList[0].List->PartialResourceList.Count > 1)
- NewTranslatedSize +=
(TranslatedResourceList[0].List->PartialResourceList.Count-1) *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
-
- NewTranslatedResources = AllocateItem(PoolType, NewTranslatedSize, TAG_PORTCLASS);
- if (!NewTranslatedResources)
- {
- FreeItem(NewList, TAG_PORTCLASS);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- NewUntranslatedSize = sizeof(CM_RESOURCE_LIST);
- if (UntranslatedResourceList[0].List->PartialResourceList.Count > 1)
- NewUntranslatedSize +=
(UntranslatedResourceList[0].List->PartialResourceList.Count-1) *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
-
- NewUntranslatedResources = AllocateItem(PoolType, NewUntranslatedSize,
TAG_PORTCLASS);
- if (!NewUntranslatedResources)
- {
- FreeItem(NewList, TAG_PORTCLASS);
- FreeItem(NewTranslatedResources, TAG_PORTCLASS);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- RtlCopyMemory(NewTranslatedResources, TranslatedResourceList, NewTranslatedSize);
- RtlCopyMemory(NewUntranslatedResources, UntranslatedResourceList,
NewUntranslatedSize);
-
NewList->lpVtbl = (IResourceListVtbl*)&vt_ResourceListVtbl;
NewList->ref = 1;
NewList->OuterUnknown = OuterUnknown;
+ NewList->PoolType = PoolType;
+
+ if (!TranslatedResourceList || !UntranslatedResourceList)
+ {
+ /* empty resource list */
+ *OutResourceList = (IResourceList*)&NewList->lpVtbl;
+ return STATUS_SUCCESS;
+ }
+
+ /* calculate translated resource list size */
+ ResourceCount = TranslatedResourceList->List[0].PartialResourceList.Count;
+ NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
+
+ /* calculate untranslated resouce list size */
+ ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
+ NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
+
+ /* allocate translated resource list */
+ NewTranslatedResources = AllocateItem(PoolType, NewTranslatedSize, TAG_PORTCLASS);
+ if (!NewTranslatedResources)
+ {
+ FreeItem(NewList, TAG_PORTCLASS);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* allocate untranslated resource list */
+ NewUntranslatedResources = AllocateItem(PoolType, NewUntranslatedSize,
TAG_PORTCLASS);
+ if (!NewUntranslatedResources)
+ {
+ FreeItem(NewList, TAG_PORTCLASS);
+ FreeItem(NewTranslatedResources, TAG_PORTCLASS);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* copy resource lists */
+ RtlCopyMemory(NewTranslatedResources, TranslatedResourceList, NewTranslatedSize);
+ RtlCopyMemory(NewUntranslatedResources, UntranslatedResourceList,
NewUntranslatedSize);
+
+ /* store resource lists */
NewList->TranslatedResourceList= NewTranslatedResources;
NewList->UntranslatedResourceList = NewUntranslatedResources;
- NewList->PoolType = PoolType;
/* Increment our usage count and set the pointer to this object */
*OutResourceList = (IResourceList*)&NewList->lpVtbl;
@@ -405,7 +434,9 @@
return STATUS_SUCCESS;
}
-PORTCLASSAPI NTSTATUS NTAPI
+PORTCLASSAPI
+NTSTATUS
+NTAPI
PcNewResourceSublist(
OUT PRESOURCELIST* OutResourceList,
IN PUNKNOWN OuterUnknown OPTIONAL,