Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Kees Cook <keescook@chromium.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
1a89595c 3e455b7d

+24 -18
+24 -18
tools/testing/selftests/kselftest_harness.h
··· 631 631 } \ 632 632 } while (0); OPTIONAL_HANDLER(_assert) 633 633 634 + /* List helpers */ 635 + #define __LIST_APPEND(head, item) \ 636 + { \ 637 + /* Circular linked list where only prev is circular. */ \ 638 + if (head == NULL) { \ 639 + head = item; \ 640 + item->next = NULL; \ 641 + item->prev = item; \ 642 + return; \ 643 + } \ 644 + if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { \ 645 + item->next = NULL; \ 646 + item->prev = head->prev; \ 647 + item->prev->next = item; \ 648 + head->prev = item; \ 649 + } else { \ 650 + item->next = head; \ 651 + item->next->prev = item; \ 652 + item->prev = item; \ 653 + head = item; \ 654 + } \ 655 + } 656 + 634 657 /* Contains all the information for test execution and status checking. */ 635 658 struct __test_metadata { 636 659 const char *name; ··· 690 667 static inline void __register_test(struct __test_metadata *t) 691 668 { 692 669 __test_count++; 693 - /* Circular linked list where only prev is circular. */ 694 - if (__test_list == NULL) { 695 - __test_list = t; 696 - t->next = NULL; 697 - t->prev = t; 698 - return; 699 - } 700 - if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { 701 - t->next = NULL; 702 - t->prev = __test_list->prev; 703 - t->prev->next = t; 704 - __test_list->prev = t; 705 - } else { 706 - t->next = __test_list; 707 - t->next->prev = t; 708 - t->prev = t; 709 - __test_list = t; 710 - } 670 + __LIST_APPEND(__test_list, t); 711 671 } 712 672 713 673 static inline int __bail(int for_realz, bool no_print, __u8 step)