]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[list] Tidy up naming convention for list_contains() and friends
authorMichael Brown <mcb30@ipxe.org>
Fri, 14 Oct 2011 12:35:05 +0000 (13:35 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 14 Oct 2011 13:33:31 +0000 (14:33 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/list.h
src/net/fc.c
src/net/netdevice.c

index 4905aaa3a7bfa04249db021d604867675f8c9a6e..8dc74139dfdc322d19546596b2c73bfcffb55796 100644 (file)
@@ -170,6 +170,18 @@ static inline int list_empty ( const struct list_head *list ) {
          ( type * ) NULL :                             \
          list_entry ( (list)->next, type, member ) )
 
+/**
+ * Iterate over a list
+ *
+ * @v pos              Iterator
+ * @v head             List head
+ */
+#define list_for_each( pos, head )                                           \
+       for ( list_check ( (head) ),                                          \
+             pos = (head)->next;                                             \
+             pos != (head);                                                  \
+             pos = (pos)->next )
+
 /**
  * Iterate over entries in a list
  *
@@ -212,6 +224,38 @@ static inline int list_empty ( const struct list_head *list ) {
              pos = tmp,                                                      \
              tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) )
 
+/**
+ * Test if list contains a specified entry
+ *
+ * @v entry            Entry
+ * @v head             List head
+ * @ret present                List contains specified entry
+ */
+static inline int list_contains ( struct list_head *entry,
+                                 struct list_head *head ) {
+       struct list_head *tmp;
+
+       list_for_each ( tmp, head ) {
+               if ( tmp == entry )
+                       return 1;
+       }
+       return 0;
+}
+#define list_contains( entry, head ) ( {               \
+       list_check ( (head) );                          \
+       list_check ( (entry) );                         \
+       list_contains ( (entry), (head) ); } )
+
+/**
+ * Test if list contains a specified entry
+ *
+ * @v entry            Entry
+ * @v head             List head
+ * @ret present                List contains specified entry
+ */
+#define list_contains_entry( entry, head, member )     \
+       list_contains ( &(entry)->member, (head) )
+
 /**
  * Check list contains a specified entry
  *
@@ -219,16 +263,8 @@ static inline int list_empty ( const struct list_head *list ) {
  * @v head             List head
  * @v member           Name of list field within iterator's type
  */
-#define list_check_contains( entry, head, member ) do {                \
-       if ( ASSERTING ) {                                      \
-               typeof ( entry ) tmp;                           \
-               int found = 0;                                  \
-               list_for_each_entry ( tmp, head, member ) {     \
-                       if ( tmp == entry )                     \
-                               found = 1;                      \
-               }                                               \
-               assert ( found );                               \
-       }                                                       \
+#define list_check_contains_entry( entry, head, member ) do {                \
+       assert ( list_contains_entry ( (entry), (head), member ) );           \
        } while ( 0 )
 
 #endif /* _IPXE_LIST_H */
index 977ad07c7d5a9b8ef57e2baff65caab265d6d214..f76cfe928912d8f390ee9300bce55bc2ae3c8326 100644 (file)
@@ -1625,7 +1625,7 @@ void fc_ulp_detach ( struct fc_ulp_user *user ) {
                return;
 
        /* Sanity checks */
-       list_check_contains ( user, &ulp->users, list );
+       list_check_contains_entry ( user, &ulp->users, list );
 
        /* Detach user and log out if no users remain */
        list_del ( &user->list );
index f5ec4191fb584f46a80ad4ce363e34e4d81ecf2b..d1ae8af30b1f49f922a7819742c628eb9057bbe3 100644 (file)
@@ -233,7 +233,7 @@ void netdev_tx_complete_err ( struct net_device *netdev,
                              struct io_buffer *iobuf, int rc ) {
 
        /* Catch data corruption as early as possible */
-       list_check_contains ( iobuf, &netdev->tx_queue, list );
+       list_check_contains_entry ( iobuf, &netdev->tx_queue, list );
 
        /* Dequeue and free I/O buffer */
        list_del ( &iobuf->list );