[PATCH] L5Common: Fix SendIndicationToSubscribers for 64-bit systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For ListItems in the subscribersList, the 'pData' field is used to hold the
value of the subscriber ID, instead of storing a pointer. Iterator_GetNext()
can not read subscriber IDs directly into an L5_TARGET_ID since this may not
be as large as the size of 'pData'. With this change, the subscriber ID is
first read into a pointer, whose value is later copied into a L5_TARGET_ID.

Additionally, this change eliminates the step of copying the subscriber IDs
to a temporary list before processing them, as this should not be necessary.

Signed-off-by: David Ward <david.ward at ll.mit.edu>
---
 .../Common/L5Common/IndicatorsSubscribers.c        |   48 +++++--------------
 1 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/InfraStack/OSAgnostic/Common/L5Common/IndicatorsSubscribers.c b/InfraStack/OSAgnostic/Common/L5Common/IndicatorsSubscribers.c
index f920509..af23871 100644
--- a/InfraStack/OSAgnostic/Common/L5Common/IndicatorsSubscribers.c
+++ b/InfraStack/OSAgnostic/Common/L5Common/IndicatorsSubscribers.c
@@ -134,14 +134,17 @@ EXPORT IndicatorSubscribers *GetIndicatorSubscribers(List *pList, UINT32 indicat
 // Add a subscriber to the IndicatorSubscribers list
 EXPORT void Indications_AddSubscriber(IndicatorSubscribers *indSubscribers, UINT32 subscriberID)
 {
-	//I`m using the pointer to data (in the list) as my indication id. So i don`t need to allocate/free it.
-	List_AddItem(&(indSubscribers->subscribersList), (void*)((ULONG_PTR)subscriberID));
+	// Instead of storing a pointer in the 'pData' field of the ListItem, the indicator ID is stored there;
+	// so malloc() is not necessary. Note that the size of a pointer may be larger than the size of a UINT32.
+	List_AddItem(&(indSubscribers->subscribersList), (void*)(subscriberID));
 }
 
 // Remove a subscriber from the IndicatorSubscribers list
 EXPORT BOOL Indications_RemoveSubscriber(IndicatorSubscribers *indSubscribers, UINT32 subscriberID)
 {
-	if (List_RemoveItem(&(indSubscribers->subscribersList), (void*)((ULONG_PTR)subscriberID)))
+	// Instead of storing a pointer in the 'pData' field of the ListItem, the indicator ID is stored there;
+	// so free() is not necessary. Note that the size of a pointer may be larger than the size of a UINT32.
+	if (List_RemoveItem(&(indSubscribers->subscribersList), (void*)(subscriberID)))
 	{
 		return TRUE;
 	}
@@ -155,10 +158,12 @@ EXPORT void SendIndicationToSubscribers( UINT32 internalRequestID, void *_buffer
 	SendIndData *buffer = _buffer;
 	ListItem* handle;
 	L5_TARGET_ID targetID;
-	L5_TARGET_ID data;
+	// Instead of storing a pointer in the 'pData' field of the ListItem, the indicator ID is stored there.
+	// Since the size of a pointer may be larger than the size of an L5_TARGET_ID, a pointer needs to be used
+	// with Iterator_GetNext() to store the indicator ID, before copying the value to an L5_TARGET_ID.
+	void *data;
 	L5_RESULT res;
 	IndicatorSubscribers *indSubscribers;
-	List tempList;
 	
 	UNREFERENCED_PARAMETER(bufferLength);
 	
@@ -171,31 +176,12 @@ EXPORT void SendIndicationToSubscribers( UINT32 internalRequestID, void *_buffer
 									internalRequestID ,indSubscribers, buffer->pSubscribersList, buffer->indication_id);
 	if ((NULL != indSubscribers) && (0 != List_Length(&(indSubscribers->subscribersList))))
 	{		
-		// Build temp list
-		List_Init(&tempList, FALSE);
 		handle = CreateIterator(&(indSubscribers->subscribersList));
-//		handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)&targetID);
 		handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)(&data));
-		targetID = data;
 		while (handle != NULL)
 		{
-			List_AddItem(&tempList, (void *)targetID);
-			handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)(&data));
-    		targetID = data; ////
-
-	//		handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)&targetID);
-		}
-
-		FreeIterator(&(indSubscribers->subscribersList));
-
-		//iterate the temp list and send the targets indication:
-		handle = CreateIterator(&tempList);
-		handle = Iterator_GetNext(&tempList, handle, (void**)(&data));
-    	targetID = data;
+			targetID = (L5_TARGET_ID) data;
 
-	//	handle = Iterator_GetNext(&tempList, handle, (void**)&targetID);
-		while (handle != NULL)
-		{
 			//in case we are working with remote DnD, we want to send the trace and monitor indications 
 			//only to the DnD agent
 			if(((L3_L4_OPCODE_REPORT_MONITOR_EVACUATE != wimaxll_le16_to_cpu(*((UINT16 *)buffer->indication_buffer))) &&
@@ -217,23 +203,15 @@ EXPORT void SendIndicationToSubscribers( UINT32 internalRequestID, void *_buffer
 				}
 
 			}
-			
-	//		handle = Iterator_GetNext(&tempList, handle, (void**)&targetID);
-
-			handle = Iterator_GetNext(&tempList, handle, (void**)(&data));
-    		targetID = data;
 
+			handle = Iterator_GetNext(&(indSubscribers->subscribersList), handle, (void**)(&data));
 
 			// TODO - XXX - check L5_COMMON_UTILS_IsTargetNotExist
 			// TODO - XXX - check res
 			// TODO - XXX - check responseID
 		}
 
-		FreeIterator(&tempList);
-
-		//free the temp list items:
-		List_Clear(&tempList);
-		List_Finalize(&tempList);
+		FreeIterator(&(indSubscribers->subscribersList));
 	}
 	else
 	{
-- 
1.7.1



[Index of Archives]     [Linux Kernel]     [Linux Wireless]     [Linux Bluetooth]     [Linux Netdev]     [Linux Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux