Skip to content

Commit

Permalink
Make removing from Open arrays use a consistent loop structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Feb 15, 2017
1 parent a889ccb commit 974cf33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
36 changes: 16 additions & 20 deletions packetWin7/npf/npf/Openclos.c
Original file line number Diff line number Diff line change
Expand Up @@ -1072,22 +1072,24 @@ NPF_RemoveFromOpenArray(
TRACE_ENTER();

NdisAcquireSpinLock(&g_OpenArrayLock);
for (CurOpen = g_arrOpen; CurOpen != NULL; CurOpen = CurOpen->Next)
{
if (CurOpen == Open)
if (g_arrOpen == Open) {
g_arrOpen = Open->Next;
// CurOpen must be set or a later check will fail.
CurOpen = g_arrOpen;
}
else {
PrevOpen = g_arrOpen;
CurOpen = PrevOpen->Next;
while (CurOpen)
{
if (CurOpen == g_arrOpen)
{
g_arrOpen = CurOpen->Next;
}
else
if (CurOpen == Open)
{
PrevOpen->Next = CurOpen->Next;
break;
}

break;
PrevOpen = CurOpen;
CurOpen = CurOpen->Next;
}
PrevOpen = CurOpen;
}

// Remove the links between group head and group members.
Expand Down Expand Up @@ -1126,19 +1128,13 @@ NPF_RemoveFromGroupOpenArray(
}

NdisAcquireSpinLock(&g_OpenArrayLock);
GroupOpen = Open->GroupHead;
GroupPrev = Open->GroupHead;
GroupOpen = GroupPrev->GroupNext;
while (GroupOpen)
{
if (GroupOpen == Open)
{
if (GroupPrev)
{
GroupPrev->GroupNext = GroupOpen->GroupNext;
}
else
{
Open->GroupHead = GroupOpen->GroupNext;
}
GroupPrev->GroupNext = GroupOpen->GroupNext;
GroupOpen->GroupHead = NULL;

NdisReleaseSpinLock(&g_OpenArrayLock);
Expand Down
2 changes: 2 additions & 0 deletions packetWin7/npf/npf/Read.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,11 @@ NPF_SendEx(

TRACE_ENTER();

ASSERT(Open->GroupHead != NULL);
if (Open->GroupHead != NULL)
{
// Should not come here, because Open called by NDIS will always be a group head itself, so its GroupHead member is NULL.
IF_LOUD(DbgPrint("NPF_SendEx: Open->GroupHead != NULL\n");)
GroupOpen = Open->GroupHead->GroupNext;
}
else
Expand Down

0 comments on commit 974cf33

Please sign in to comment.