Skip to content

Commit 066b34a

Browse files
committed
tools: fix ARRAY_SIZE defines in tools and selftests hdrs
tools/include/linux/kernel.h and kselftest_harness.h are missing ifndef guard around ARRAY_SIZE define. Fix them to avoid duplicate define errors during compile when another file defines it. This problem was found when compiling selftests that include a header with ARRAY_SIZE define. ARRAY_SIZE is defined in several selftests. There are about 25+ duplicate defines in various selftests source and header files. Add ARRAY_SIZE to kselftest.h in preparation for removing duplicate ARRAY_SIZE defines from individual test files. Signed-off-by: Shuah Khan <[email protected]>
1 parent a738a4c commit 066b34a

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

tools/include/linux/kernel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
9292
int scnprintf(char * buf, size_t size, const char * fmt, ...);
9393
int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
9494

95+
#ifndef ARRAY_SIZE
9596
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
97+
#endif
9698

9799
#define current_gfp_context(k) 0
98100
#define synchronize_rcu()

tools/testing/selftests/kselftest.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
#include <stdarg.h>
4949
#include <stdio.h>
5050

51+
#ifndef ARRAY_SIZE
52+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
53+
#endif
54+
5155
/* define kselftest exit codes */
5256
#define KSFT_PASS 0
5357
#define KSFT_FAIL 1

tools/testing/selftests/kselftest_harness.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,9 @@
671671
#define EXPECT_STRNE(expected, seen) \
672672
__EXPECT_STR(expected, seen, !=, 0)
673673

674+
#ifndef ARRAY_SIZE
674675
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
676+
#endif
675677

676678
/* Support an optional handler after and ASSERT_* or EXPECT_*. The approach is
677679
* not thread-safe, but it should be fine in most sane test scenarios.

0 commit comments

Comments
 (0)