@@ -258,8 +258,7 @@ static inline void list_bulk_move_tail(struct list_head *head,
258
258
* @list: the entry to test
259
259
* @head: the head of the list
260
260
*/
261
- static inline int list_is_first (const struct list_head * list ,
262
- const struct list_head * head )
261
+ static inline int list_is_first (const struct list_head * list , const struct list_head * head )
263
262
{
264
263
return list -> prev == head ;
265
264
}
@@ -269,12 +268,21 @@ static inline int list_is_first(const struct list_head *list,
269
268
* @list: the entry to test
270
269
* @head: the head of the list
271
270
*/
272
- static inline int list_is_last (const struct list_head * list ,
273
- const struct list_head * head )
271
+ static inline int list_is_last (const struct list_head * list , const struct list_head * head )
274
272
{
275
273
return list -> next == head ;
276
274
}
277
275
276
+ /**
277
+ * list_is_head - tests whether @list is the list @head
278
+ * @list: the entry to test
279
+ * @head: the head of the list
280
+ */
281
+ static inline int list_is_head (const struct list_head * list , const struct list_head * head )
282
+ {
283
+ return list == head ;
284
+ }
285
+
278
286
/**
279
287
* list_empty - tests whether a list is empty
280
288
* @head: the list to test.
@@ -318,7 +326,7 @@ static inline void list_del_init_careful(struct list_head *entry)
318
326
static inline int list_empty_careful (const struct list_head * head )
319
327
{
320
328
struct list_head * next = smp_load_acquire (& head -> next );
321
- return (next == head ) && (next == head -> prev );
329
+ return list_is_head (next , head ) && (next == head -> prev );
322
330
}
323
331
324
332
/**
@@ -393,10 +401,9 @@ static inline void list_cut_position(struct list_head *list,
393
401
{
394
402
if (list_empty (head ))
395
403
return ;
396
- if (list_is_singular (head ) &&
397
- (head -> next != entry && head != entry ))
404
+ if (list_is_singular (head ) && !list_is_head (entry , head ) && (entry != head -> next ))
398
405
return ;
399
- if (entry == head )
406
+ if (list_is_head ( entry , head ) )
400
407
INIT_LIST_HEAD (list );
401
408
else
402
409
__list_cut_position (list , head , entry );
@@ -570,7 +577,7 @@ static inline void list_splice_tail_init(struct list_head *list,
570
577
* @head: the head for your list.
571
578
*/
572
579
#define list_for_each (pos , head ) \
573
- for (pos = (head)->next; pos != (head); pos = pos->next)
580
+ for (pos = (head)->next; !list_is_head( pos, (head) ); pos = pos->next)
574
581
575
582
/**
576
583
* list_for_each_continue - continue iteration over a list
@@ -580,15 +587,15 @@ static inline void list_splice_tail_init(struct list_head *list,
580
587
* Continue to iterate over a list, continuing after the current position.
581
588
*/
582
589
#define list_for_each_continue (pos , head ) \
583
- for (pos = pos->next; pos != (head); pos = pos->next)
590
+ for (pos = pos->next; !list_is_head( pos, (head) ); pos = pos->next)
584
591
585
592
/**
586
593
* list_for_each_prev - iterate over a list backwards
587
594
* @pos: the &struct list_head to use as a loop cursor.
588
595
* @head: the head for your list.
589
596
*/
590
597
#define list_for_each_prev (pos , head ) \
591
- for (pos = (head)->prev; pos != (head); pos = pos->prev)
598
+ for (pos = (head)->prev; !list_is_head( pos, (head) ); pos = pos->prev)
592
599
593
600
/**
594
601
* list_for_each_safe - iterate over a list safe against removal of list entry
@@ -597,8 +604,9 @@ static inline void list_splice_tail_init(struct list_head *list,
597
604
* @head: the head for your list.
598
605
*/
599
606
#define list_for_each_safe (pos , n , head ) \
600
- for (pos = (head)->next, n = pos->next; pos != (head); \
601
- pos = n, n = pos->next)
607
+ for (pos = (head)->next, n = pos->next; \
608
+ !list_is_head(pos, (head)); \
609
+ pos = n, n = pos->next)
602
610
603
611
/**
604
612
* list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
@@ -608,7 +616,7 @@ static inline void list_splice_tail_init(struct list_head *list,
608
616
*/
609
617
#define list_for_each_prev_safe (pos , n , head ) \
610
618
for (pos = (head)->prev, n = pos->prev; \
611
- pos != (head); \
619
+ !list_is_head( pos, (head) ); \
612
620
pos = n, n = pos->prev)
613
621
614
622
/**
0 commit comments