[openib-general] [PATCH] SDP: use linux/list.h for advt table

Tom Duffy tduffy at sun.com
Mon Jul 25 09:58:34 PDT 2005


This patch changes sdp_advt.[ch] to use linux lists.  I didn't change
the API, but it may be a good idea now that the lists are done a bit
differently.

Signed-off-by: Tom Duffy <tduffy at sun.com>

 sdp_advt.c |   51 +++++++++++++--------------------------------------
 sdp_advt.h |    7 ++++---
 2 files changed, 17 insertions(+), 41 deletions(-)

Index: linux-2.6.13-rc3-openib/drivers/infiniband/ulp/sdp/sdp_advt.c
===================================================================
--- linux-2.6.13-rc3-openib/drivers/infiniband/ulp/sdp/sdp_advt.c	(revision 2900)
+++ linux-2.6.13-rc3-openib/drivers/infiniband/ulp/sdp/sdp_advt.c	(working copy)
@@ -33,6 +33,8 @@
  * $Id$
  */
 
+#include <linux/list.h>
+
 #include "sdp_main.h"
 
 static kmem_cache_t *sdp_advt_cache = NULL;
@@ -68,7 +70,6 @@ struct sdpc_advt *sdp_advt_create(void)
  */
 void sdp_advt_destroy(struct sdpc_advt *advt)
 {
-	BUG_ON(advt->next || advt->prev);
 	/*
 	 * return the object to its cache
 	 */
@@ -81,29 +82,16 @@ void sdp_advt_destroy(struct sdpc_advt *
 struct sdpc_advt *sdp_advt_q_get(struct sdpc_advt_q *table)
 {
 	struct sdpc_advt *advt;
-	struct sdpc_advt *next;
-	struct sdpc_advt *prev;
 
-	advt = table->head;
-	if (!advt)
+	if (list_empty(&table->head))
 		return NULL;
 
-	if (advt->next == advt && advt->prev == advt)
-		table->head = NULL;
-	else {
-		next = advt->next;
-		prev = advt->prev;
-		next->prev = prev;
-		prev->next = next;
+	advt = list_entry(table->head.next, struct sdpc_advt, list);
 
-		table->head = next;
-	}
+	list_del(&advt->list);
 
 	table->size--;
 
-	advt->next = NULL;
-	advt->prev = NULL;
-
 	return advt;
 }
 
@@ -112,7 +100,10 @@ struct sdpc_advt *sdp_advt_q_get(struct 
  */
 struct sdpc_advt *sdp_advt_q_look(struct sdpc_advt_q *table)
 {
-	return table->head;
+	if (list_empty(&table->head))
+		return NULL;
+	
+	return list_entry(table->head.next, struct sdpc_advt, list);
 }
 
 /*
@@ -120,25 +111,9 @@ struct sdpc_advt *sdp_advt_q_look(struct
  */
 void sdp_advt_q_put(struct sdpc_advt_q *table, struct sdpc_advt *advt)
 {
-	struct sdpc_advt *next;
-	struct sdpc_advt *prev;
-
 	BUG_ON(advt->table);
 
-	if (!table->head) {
-		advt->next = advt;
-		advt->prev = advt;
-		table->head = advt;
-	}
-	else {
-		next = table->head;
-		prev = next->prev;
-
-		prev->next = advt;
-		advt->prev = prev;
-		advt->next = next;
-		next->prev = advt;
-	}
+	list_add_tail(&advt->list, &table->head);
 
 	table->size++;
 }
@@ -148,7 +123,7 @@ void sdp_advt_q_put(struct sdpc_advt_q *
  */
 void sdp_advt_q_init(struct sdpc_advt_q *table)
 {
-	table->head = NULL;
+	INIT_LIST_HEAD(&table->head);
 	table->size = 0;
 }
 
@@ -157,11 +132,11 @@ void sdp_advt_q_init(struct sdpc_advt_q 
  */
 void sdp_advt_q_clear(struct sdpc_advt_q *table)
 {
-	struct sdpc_advt *advt;
+	struct sdpc_advt *advt, *tmp;
 	/*
 	 * drain the table of any objects
 	 */
-	while ((advt = sdp_advt_q_get(table)))
+	list_for_each_entry_safe(advt, tmp, &table->head, list)
 		sdp_advt_destroy(advt);
 }
 
Index: linux-2.6.13-rc3-openib/drivers/infiniband/ulp/sdp/sdp_advt.h
===================================================================
--- linux-2.6.13-rc3-openib/drivers/infiniband/ulp/sdp/sdp_advt.h	(revision 2900)
+++ linux-2.6.13-rc3-openib/drivers/infiniband/ulp/sdp/sdp_advt.h	(working copy)
@@ -36,6 +36,8 @@
 #ifndef _SDP_ADVT_H
 #define _SDP_ADVT_H
 
+#include <linux/list.h>
+
 #include "sdp_queue.h"
 
 /*
@@ -47,8 +49,7 @@
  * SDP read/write advertisments
  */
 struct sdpc_advt {
-	struct sdpc_advt   *next;  /* next structure in table */
-	struct sdpc_advt   *prev;  /* previous structure in table */
+	struct list_head list;
 	u32                 type; /* element type. (for generic queue) */
 	struct sdpc_advt_q *table; /* table to which this object belongs */
 	void (*release)(struct sdpc_advt *advt); /* release the object */
@@ -67,7 +68,7 @@ struct sdpc_advt {
  * table for holding SDP advertisments.
  */
 struct sdpc_advt_q {
-	struct sdpc_advt *head; /* double linked list of advertisments */
+	struct list_head head; /* double linked list of advertisments */
 	s32 size;               /* current number of advertisments in table */
 };
 




More information about the general mailing list