Browse Source

[list] Tidy up naming convention for list_contains() and friends

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
38b205d0a4
3 changed files with 48 additions and 12 deletions
  1. 46
    10
      src/include/ipxe/list.h
  2. 1
    1
      src/net/fc.c
  3. 1
    1
      src/net/netdevice.c

+ 46
- 10
src/include/ipxe/list.h View File

@@ -170,6 +170,18 @@ static inline int list_empty ( const struct list_head *list ) {
170 170
 	  ( type * ) NULL :				\
171 171
 	  list_entry ( (list)->next, type, member ) )
172 172
 
173
+/**
174
+ * Iterate over a list
175
+ *
176
+ * @v pos		Iterator
177
+ * @v head		List head
178
+ */
179
+#define list_for_each( pos, head )					      \
180
+	for ( list_check ( (head) ),					      \
181
+	      pos = (head)->next;					      \
182
+	      pos != (head);						      \
183
+	      pos = (pos)->next )
184
+
173 185
 /**
174 186
  * Iterate over entries in a list
175 187
  *
@@ -212,6 +224,38 @@ static inline int list_empty ( const struct list_head *list ) {
212 224
 	      pos = tmp,						      \
213 225
 	      tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
214 226
 
227
+/**
228
+ * Test if list contains a specified entry
229
+ *
230
+ * @v entry		Entry
231
+ * @v head		List head
232
+ * @ret present		List contains specified entry
233
+ */
234
+static inline int list_contains ( struct list_head *entry,
235
+				  struct list_head *head ) {
236
+	struct list_head *tmp;
237
+
238
+	list_for_each ( tmp, head ) {
239
+		if ( tmp == entry )
240
+			return 1;
241
+	}
242
+	return 0;
243
+}
244
+#define list_contains( entry, head ) ( {		\
245
+	list_check ( (head) );				\
246
+	list_check ( (entry) );				\
247
+	list_contains ( (entry), (head) ); } )
248
+
249
+/**
250
+ * Test if list contains a specified entry
251
+ *
252
+ * @v entry		Entry
253
+ * @v head		List head
254
+ * @ret present		List contains specified entry
255
+ */
256
+#define list_contains_entry( entry, head, member )	\
257
+	list_contains ( &(entry)->member, (head) )
258
+
215 259
 /**
216 260
  * Check list contains a specified entry
217 261
  *
@@ -219,16 +263,8 @@ static inline int list_empty ( const struct list_head *list ) {
219 263
  * @v head		List head
220 264
  * @v member		Name of list field within iterator's type
221 265
  */
222
-#define list_check_contains( entry, head, member ) do {		\
223
-	if ( ASSERTING ) {					\
224
-		typeof ( entry ) tmp;				\
225
-		int found = 0;					\
226
-		list_for_each_entry ( tmp, head, member ) {	\
227
-			if ( tmp == entry )			\
228
-				found = 1;			\
229
-		}						\
230
-		assert ( found );				\
231
-	}							\
266
+#define list_check_contains_entry( entry, head, member ) do {		      \
267
+	assert ( list_contains_entry ( (entry), (head), member ) );	      \
232 268
 	} while ( 0 )
233 269
 
234 270
 #endif /* _IPXE_LIST_H */

+ 1
- 1
src/net/fc.c View File

@@ -1625,7 +1625,7 @@ void fc_ulp_detach ( struct fc_ulp_user *user ) {
1625 1625
 		return;
1626 1626
 
1627 1627
 	/* Sanity checks */
1628
-	list_check_contains ( user, &ulp->users, list );
1628
+	list_check_contains_entry ( user, &ulp->users, list );
1629 1629
 
1630 1630
 	/* Detach user and log out if no users remain */
1631 1631
 	list_del ( &user->list );

+ 1
- 1
src/net/netdevice.c View File

@@ -233,7 +233,7 @@ void netdev_tx_complete_err ( struct net_device *netdev,
233 233
 			      struct io_buffer *iobuf, int rc ) {
234 234
 
235 235
 	/* Catch data corruption as early as possible */
236
-	list_check_contains ( iobuf, &netdev->tx_queue, list );
236
+	list_check_contains_entry ( iobuf, &netdev->tx_queue, list );
237 237
 
238 238
 	/* Dequeue and free I/O buffer */
239 239
 	list_del ( &iobuf->list );

Loading…
Cancel
Save