Commit 1a89595c authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

kselftest: factor out list manipulation to a helper

Kees suggest to factor out the list append code to a macro,
since following commits need it, which leads to code duplication.
Suggested-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3e455b7d
...@@ -631,6 +631,29 @@ ...@@ -631,6 +631,29 @@
} \ } \
} while (0); OPTIONAL_HANDLER(_assert) } while (0); OPTIONAL_HANDLER(_assert)
/* List helpers */
#define __LIST_APPEND(head, item) \
{ \
/* Circular linked list where only prev is circular. */ \
if (head == NULL) { \
head = item; \
item->next = NULL; \
item->prev = item; \
return; \
} \
if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { \
item->next = NULL; \
item->prev = head->prev; \
item->prev->next = item; \
head->prev = item; \
} else { \
item->next = head; \
item->next->prev = item; \
item->prev = item; \
head = item; \
} \
}
/* Contains all the information for test execution and status checking. */ /* Contains all the information for test execution and status checking. */
struct __test_metadata { struct __test_metadata {
const char *name; const char *name;
...@@ -667,24 +690,7 @@ static int __constructor_order; ...@@ -667,24 +690,7 @@ static int __constructor_order;
static inline void __register_test(struct __test_metadata *t) static inline void __register_test(struct __test_metadata *t)
{ {
__test_count++; __test_count++;
/* Circular linked list where only prev is circular. */ __LIST_APPEND(__test_list, t);
if (__test_list == NULL) {
__test_list = t;
t->next = NULL;
t->prev = t;
return;
}
if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) {
t->next = NULL;
t->prev = __test_list->prev;
t->prev->next = t;
__test_list->prev = t;
} else {
t->next = __test_list;
t->next->prev = t;
t->prev = t;
__test_list = t;
}
} }
static inline int __bail(int for_realz, bool no_print, __u8 step) static inline int __bail(int for_realz, bool no_print, __u8 step)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment