diff mbox

[01/34] ptrlist: simplify DO_FOR_EACH/DO_END_FOR_EACH

Message ID 20170707134002.49500-2-luc.vanoostenryck@gmail.com (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Luc Van Oostenryck July 7, 2017, 1:39 p.m. UTC
---
 ptrlist.h | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

Comments

Christopher Li July 8, 2017, 3:31 p.m. UTC | #1
On Fri, Jul 7, 2017 at 6:39 AM, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> -       if (__head) {                                                                   \
> -               do { int __nr;                                                          \
> -                       for (__nr = 0; __nr < __list->nr; __nr++) {                     \
> -                               do {                                                    \
> -                                       ptr = PTR_ENTRY(__list,__nr);                   \
> -                                       do {
> +       if (!__head) break;                                                             \
> +       do { int __nr;                                                                  \
> +               for (__nr = 0; __nr < __list->nr; __nr++) {                             \
> +                       ptr = PTR_ENTRY(__list,__nr);                                   \
>
>  #define DO_END_FOR_EACH(ptr, __head, __list, __nr)                                     \
> -                                       } while (0);                                    \
> -                               } while (0);                                            \
> -                       }                                                               \
> -               } while ((__list = __list->next) != __head);                            \
> -       }                                                                               \
> +               }                                                                       \
> +       } while ((__list = __list->next) != __head);                                    \
>  } while (0)

I think the extra "do {} while (0)" is there to prevent the FOR_EACH
paring with END_FOR_EACH_REVERSE() and vise versa.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/ptrlist.h b/ptrlist.h
index d09be2f51..9ffbc6e18 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -156,19 +156,14 @@  static inline void *last_ptr_list(struct ptr_list *list)
 	struct ptr_list *__head = (struct ptr_list *) (head);				\
 	struct ptr_list *__list = __head;						\
 	CHECK_TYPE(head,ptr);								\
-	if (__head) {									\
-		do { int __nr;								\
-			for (__nr = 0; __nr < __list->nr; __nr++) {			\
-				do {							\
-					ptr = PTR_ENTRY(__list,__nr);			\
-					do {
+	if (!__head) break;								\
+	do { int __nr;									\
+		for (__nr = 0; __nr < __list->nr; __nr++) {				\
+			ptr = PTR_ENTRY(__list,__nr);					\
 
 #define DO_END_FOR_EACH(ptr, __head, __list, __nr)					\
-					} while (0);					\
-				} while (0);						\
-			}								\
-		} while ((__list = __list->next) != __head);				\
-	}										\
+		}									\
+	} while ((__list = __list->next) != __head);					\
 } while (0)
 
 #define DO_FOR_EACH_REVERSE(head, ptr, __head, __list, __nr, PTR_ENTRY) do {		\