Author: janderwald
Date: Thu Aug 6 23:45:10 2009
New Revision: 42439
URL:
http://svn.reactos.org/svn/reactos?rev=42439&view=rev
Log:
- Add a few parameters check
- Calculate resource list size with FIELD_OFFSET macro
- Fix a big bug in IResourceList_fnAddEntryFromParent which didnt copy the untranslated
resource list entry
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
23:45:10 2009
@@ -22,6 +22,7 @@
POOL_TYPE PoolType;
PCM_RESOURCE_LIST TranslatedResourceList;
PCM_RESOURCE_LIST UntranslatedResourceList;
+ ULONG NumberOfEntries;
} IResourceListImpl;
/*
@@ -100,7 +101,7 @@
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
- return This->TranslatedResourceList->List[0].PartialResourceList.Count;
+ return This->NumberOfEntries;
}
ULONG
@@ -114,6 +115,12 @@
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
+
+ if (!This->TranslatedResourceList)
+ {
+ /* no resource list */
+ return 0;
+ }
/* I guess the translated and untranslated lists will be same length? */
for (Index = 0; Index <
This->TranslatedResourceList->List[0].PartialResourceList.Count; Index ++ )
@@ -143,6 +150,12 @@
PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
+
+ if (!This->TranslatedResourceList)
+ {
+ /* no resource list */
+ return NULL;
+ }
for (DescIndex = 0; DescIndex <
This->TranslatedResourceList->List[0].PartialResourceList.Count; DescIndex ++ )
{
@@ -175,6 +188,12 @@
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
+ if (!This->UntranslatedResourceList)
+ {
+ /* no resource list */
+ return NULL;
+ }
+
for (DescIndex = 0; DescIndex <
This->UntranslatedResourceList->List[0].PartialResourceList.Count; DescIndex ++ )
{
PartialDescriptor =
&This->UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
@@ -200,17 +219,29 @@
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated)
{
PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
- ULONG NewTranslatedSize, NewUntranslatedSize;
- IResourceListImpl * This = (IResourceListImpl*)iface;
-
- ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
-
- NewTranslatedSize = sizeof(CM_RESOURCE_LIST) +
This->TranslatedResourceList[0].List->PartialResourceList.Count *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
+ ULONG NewTranslatedSize, NewUntranslatedSize, TranslatedSize, UntranslatedSize,
ResourceCount;
+ IResourceListImpl * This = (IResourceListImpl*)iface;
+
+ ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
+
+ /* calculate translated resource list size */
+ ResourceCount =
This->TranslatedResourceList->List[0].PartialResourceList.Count;
+ NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount+1]);
+ TranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
+
+
NewTranslatedResources = AllocateItem(This->PoolType, NewTranslatedSize,
TAG_PORTCLASS);
if (!NewTranslatedResources)
return STATUS_INSUFFICIENT_RESOURCES;
- NewUntranslatedSize = sizeof(CM_RESOURCE_LIST) +
This->UntranslatedResourceList[0].List->PartialResourceList.Count *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
+
+ /* calculate untranslated resouce list size */
+ ResourceCount =
This->UntranslatedResourceList->List[0].PartialResourceList.Count;
+ NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount+1]);
+ UntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
+
+
+ /* allocate untranslated resource list size */
NewUntranslatedResources = AllocateItem(This->PoolType, NewUntranslatedSize,
TAG_PORTCLASS);
if (!NewUntranslatedResources)
{
@@ -218,34 +249,28 @@
return STATUS_INSUFFICIENT_RESOURCES;
}
- RtlCopyMemory(NewTranslatedResources, This->TranslatedResourceList,
sizeof(CM_RESOURCE_LIST));
- if (This->TranslatedResourceList[0].List->PartialResourceList.Count > 1)
- {
-
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[0],
-
&This->TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[0],
- sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) *
This->TranslatedResourceList->List[0].PartialResourceList.Count);
- }
-
-
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[This->TranslatedResourceList[0].List->PartialResourceList.Count],
Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
-
- RtlCopyMemory(NewUntranslatedResources, This->UntranslatedResourceList,
sizeof(CM_RESOURCE_LIST));
- if (This->UntranslatedResourceList[0].List->PartialResourceList.Count > 1)
- {
-
RtlCopyMemory(&NewUntranslatedResources->List[0].PartialResourceList.PartialDescriptors[0],
-
&This->UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[0],
- sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) *
This->UntranslatedResourceList->List[0].PartialResourceList.Count);
- }
-
-
RtlCopyMemory(&NewUntranslatedResources->List[0].PartialResourceList.PartialDescriptors[This->UntranslatedResourceList[0].List->PartialResourceList.Count],
Untranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
-
+ /* now copy translated resource list */
+ RtlMoveMemory(NewTranslatedResources, This->TranslatedResourceList,
TranslatedSize);
+ RtlMoveMemory((PUCHAR)NewTranslatedResources + TranslatedSize, Translated,
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
+
+ /* now copy untranslated resource list */
+ RtlMoveMemory(NewUntranslatedResources, This->UntranslatedResourceList,
UntranslatedSize);
+ RtlMoveMemory((PUCHAR)NewUntranslatedResources + UntranslatedSize, Untranslated,
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
+
+ /* free old lists */
FreeItem(This->TranslatedResourceList, TAG_PORTCLASS);
FreeItem(This->UntranslatedResourceList, TAG_PORTCLASS);
+ /* store new lists */
This->UntranslatedResourceList = NewUntranslatedResources;
This->TranslatedResourceList = NewTranslatedResources;
+ /* increment descriptor count */
NewUntranslatedResources->List[0].PartialResourceList.Count++;
NewTranslatedResources->List[0].PartialResourceList.Count++;
+
+ /* add entry count */
+ This->NumberOfEntries++;
return STATUS_SUCCESS;
}
@@ -258,37 +283,21 @@
IN CM_RESOURCE_TYPE Type,
IN ULONG Index)
{
- PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated;
- PCM_RESOURCE_LIST NewTranslatedResources;
- ULONG NewTranslatedSize;
- IResourceListImpl * This = (IResourceListImpl*)iface;
+ PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated, Untranslated;
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
Translated = Parent->lpVtbl->FindTranslatedEntry(Parent, Type, Index);
- if (!Translated)
- return STATUS_INVALID_PARAMETER;
-
- NewTranslatedSize = sizeof(CM_RESOURCE_LIST) +
This->TranslatedResourceList[0].List->PartialResourceList.Count *
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
- NewTranslatedResources = AllocateItem(This->PoolType, NewTranslatedSize,
TAG_PORTCLASS);
- if (!NewTranslatedResources)
- return STATUS_INSUFFICIENT_RESOURCES;
-
- RtlCopyMemory(NewTranslatedResources, This->TranslatedResourceList,
sizeof(CM_RESOURCE_LIST));
- if (This->TranslatedResourceList[0].List->PartialResourceList.Count > 1)
- {
-
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[0],
-
&This->TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[0],
- sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) *
This->TranslatedResourceList->List[0].PartialResourceList.Count);
- }
-
-
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[This->TranslatedResourceList[0].List->PartialResourceList.Count],
Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
-
- FreeItem(This->TranslatedResourceList, TAG_PORTCLASS);
- This->TranslatedResourceList = NewTranslatedResources;
- NewTranslatedResources->List[0].PartialResourceList.Count++;
-
- return STATUS_SUCCESS;
+ Untranslated = Parent->lpVtbl->FindUntranslatedEntry(Parent, Type, Index);
+
+ if (Translated && Untranslated)
+ {
+ /* add entry from parent */
+ return iface->lpVtbl->AddEntry(iface, Translated, Untranslated);
+ }
+
+ /* entry not found */
+ return STATUS_INVALID_PARAMETER;
}
PCM_RESOURCE_LIST
@@ -399,6 +408,9 @@
ResourceCount = TranslatedResourceList->List[0].PartialResourceList.Count;
NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
+ /* store resource count */
+ NewList->NumberOfEntries = ResourceCount;
+
/* calculate untranslated resouce list size */
ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST,
List[0].PartialResourceList.PartialDescriptors[ResourceCount]);