All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers: staging: bcm: sort: kill handrolled bubblesort
@ 2011-07-03  4:38 Chris Forbes
  2011-07-03 19:14 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Chris Forbes @ 2011-07-03  4:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: devel, linux-kernel, Chris Forbes

Replaced the handrolled bubblesort with the kernel's sort() function.
Makes things considerably smaller & clearer.

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
---
 drivers/staging/bcm/sort.c |   77 +++++++++++++++++++-------------------------
 1 files changed, 33 insertions(+), 44 deletions(-)

diff --git a/drivers/staging/bcm/sort.c b/drivers/staging/bcm/sort.c
index fc5d07a..63c966a 100644
--- a/drivers/staging/bcm/sort.c
+++ b/drivers/staging/bcm/sort.c
@@ -1,4 +1,5 @@
 #include "headers.h"
+#include <linux/sort.h>
 
 /*
  * File Name: sort.c
@@ -10,54 +11,42 @@
  * Copyright (c) 2007 Beceem Communications Pvt. Ltd
  */
 
+static int compare_packet_info(void const *a, void const *b)
+{
+	PacketInfo const *pa = a;
+	PacketInfo const *pb = b;
+
+	if (!pa->bValid || !pb->bValid)
+		return 0;
+
+	return pa->u8TrafficPriority - pb->u8TrafficPriority;
+}
+
 VOID SortPackInfo(PMINI_ADAPTER Adapter)
 {
-	UINT nIndex1;
-	UINT nIndex2;
-
-	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "<=======");
-
-	for(nIndex1 = 0; nIndex1 < NO_OF_QUEUES -2 ; nIndex1++)
-	{
-		for(nIndex2 = nIndex1 + 1 ; nIndex2 < NO_OF_QUEUES -1  ; nIndex2++)
-		{
-			if(Adapter->PackInfo[nIndex1].bValid && Adapter->PackInfo[nIndex2].bValid)
-			{
-				if(Adapter->PackInfo[nIndex2].u8TrafficPriority <
-						Adapter->PackInfo[nIndex1].u8TrafficPriority)
-				{
-					PacketInfo stTemppackInfo = Adapter->PackInfo[nIndex2];
-					Adapter->PackInfo[nIndex2] = Adapter->PackInfo[nIndex1];
-					Adapter->PackInfo[nIndex1] = stTemppackInfo;
-
-				}
-			}
-		}
-	}
+	BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
+			DBG_LVL_ALL, "<=======");
+
+	sort(Adapter->PackInfo, NO_OF_QUEUES, sizeof(PacketInfo),
+		compare_packet_info, NULL);
+}
+
+static int compare_classifiers(void const *a, void const *b)
+{
+	S_CLASSIFIER_RULE const *pa = a;
+	S_CLASSIFIER_RULE const *pb = b;
+
+	if (!pa->bUsed || !pb->bUsed)
+		return 0;
+
+	return pa->u8ClassifierRulePriority - pb->u8ClassifierRulePriority;
 }
 
 VOID SortClassifiers(PMINI_ADAPTER Adapter)
 {
-	UINT nIndex1;
-	UINT nIndex2;
-
-	BCM_DEBUG_PRINT( Adapter,DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "<=======");
-
-	for(nIndex1 = 0; nIndex1 < MAX_CLASSIFIERS -1 ; nIndex1++)
-	{
-		for(nIndex2 = nIndex1 + 1 ; nIndex2 < MAX_CLASSIFIERS  ; nIndex2++)
-		{
-			if(Adapter->astClassifierTable[nIndex1].bUsed && Adapter->astClassifierTable[nIndex2].bUsed)
-			{
-				if(Adapter->astClassifierTable[nIndex2].u8ClassifierRulePriority <
-					Adapter->astClassifierTable[nIndex1].u8ClassifierRulePriority)
-				{
-					S_CLASSIFIER_RULE stTempClassifierRule = Adapter->astClassifierTable[nIndex2];
-					Adapter->astClassifierTable[nIndex2] = Adapter->astClassifierTable[nIndex1];
-					Adapter->astClassifierTable[nIndex1] = stTempClassifierRule;
-
-				}
-			}
-		}
-	}
+	BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
+			DBG_LVL_ALL, "<=======");
+
+	sort(Adapter->astClassifierTable, MAX_CLASSIFIERS,
+		sizeof(S_CLASSIFIER_RULE), compare_classifiers, NULL);
 }
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers: staging: bcm: sort: kill handrolled bubblesort
  2011-07-03  4:38 [PATCH] drivers: staging: bcm: sort: kill handrolled bubblesort Chris Forbes
@ 2011-07-03 19:14 ` Dan Carpenter
  2011-07-03 20:06   ` Chris Forbes
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2011-07-03 19:14 UTC (permalink / raw)
  To: Chris Forbes; +Cc: Greg Kroah-Hartman, devel, linux-kernel

On Sun, Jul 03, 2011 at 04:38:20PM +1200, Chris Forbes wrote:
> Replaced the handrolled bubblesort with the kernel's sort() function.
> Makes things considerably smaller & clearer.
> 

Did you test this?  It's Ok to not test it if you can't but the
changelog should probably say one way or the other.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers: staging: bcm: sort: kill handrolled bubblesort
  2011-07-03 19:14 ` Dan Carpenter
@ 2011-07-03 20:06   ` Chris Forbes
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Forbes @ 2011-07-03 20:06 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Greg Kroah-Hartman, devel, linux-kernel

No, it has not been tested. I have checked that it builds cleanly and
passes checkpatch though.

-- Chris

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-07-03 20:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-03  4:38 [PATCH] drivers: staging: bcm: sort: kill handrolled bubblesort Chris Forbes
2011-07-03 19:14 ` Dan Carpenter
2011-07-03 20:06   ` Chris Forbes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.