* [PATCH] openat2: use ARRAY_SIZE instead of ARRAY_LEN
@ 2021-11-19 2:30 cgel.zte
2021-11-19 23:42 ` Shuah Khan
0 siblings, 1 reply; 2+ messages in thread
From: cgel.zte @ 2021-11-19 2:30 UTC (permalink / raw)
To: shuah
Cc: christian.brauner, cyphar, chi.minghao, rgb, baolin.wang,
linux-kselftest, linux-kernel, Zeal Robot
From: chiminghao <chi.minghao@zte.com.cn>
ARRAY_SIZE defined in <linux/kernel.h> is safer than self-defined
macros to get size of an array such as ARRAY_LEN used here.
Reported-by: Zeal Robot <zealci@zte.com.cm>
Signed-off-by: chiminghao <chi.minghao@zte.com.cn>
---
tools/testing/selftests/openat2/openat2_test.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/openat2/openat2_test.c b/tools/testing/selftests/openat2/openat2_test.c
index 1bddbe934204..c467f85e854e 100644
--- a/tools/testing/selftests/openat2/openat2_test.c
+++ b/tools/testing/selftests/openat2/openat2_test.c
@@ -5,6 +5,7 @@
*/
#define _GNU_SOURCE
+#include <linux/kernel.h>
#include <fcntl.h>
#include <sched.h>
#include <sys/stat.h>
@@ -82,14 +83,14 @@ void test_openat2_struct(void)
.size = sizeof(struct open_how_ext), .err = -E2BIG },
};
- BUILD_BUG_ON(ARRAY_LEN(misalignments) != NUM_OPENAT2_STRUCT_VARIATIONS);
- BUILD_BUG_ON(ARRAY_LEN(tests) != NUM_OPENAT2_STRUCT_TESTS);
+ BUILD_BUG_ON(ARRAY_SIZE(misalignments) != NUM_OPENAT2_STRUCT_VARIATIONS);
+ BUILD_BUG_ON(ARRAY_SIZE(tests) != NUM_OPENAT2_STRUCT_TESTS);
- for (int i = 0; i < ARRAY_LEN(tests); i++) {
+ for (int i = 0; i < ARRAY_SIZE(tests); i++) {
struct struct_test *test = &tests[i];
struct open_how_ext how_ext = test->arg;
- for (int j = 0; j < ARRAY_LEN(misalignments); j++) {
+ for (int j = 0; j < ARRAY_SIZE(misalignments); j++) {
int fd, misalign = misalignments[j];
char *fdpath = NULL;
bool failed;
@@ -240,9 +241,9 @@ void test_openat2_flags(void)
.how.resolve = 0, .err = -EINVAL },
};
- BUILD_BUG_ON(ARRAY_LEN(tests) != NUM_OPENAT2_FLAG_TESTS);
+ BUILD_BUG_ON(ARRAY_SIZE(tests) != NUM_OPENAT2_FLAG_TESTS);
- for (int i = 0; i < ARRAY_LEN(tests); i++) {
+ for (int i = 0; i < ARRAY_SIZE(tests); i++) {
int fd, fdflags = -1;
char *path, *fdpath = NULL;
bool failed = false;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] openat2: use ARRAY_SIZE instead of ARRAY_LEN
2021-11-19 2:30 [PATCH] openat2: use ARRAY_SIZE instead of ARRAY_LEN cgel.zte
@ 2021-11-19 23:42 ` Shuah Khan
0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2021-11-19 23:42 UTC (permalink / raw)
To: cgel.zte, shuah
Cc: christian.brauner, cyphar, chi.minghao, rgb, baolin.wang,
linux-kselftest, linux-kernel, Zeal Robot, Shuah Khan
On 11/18/21 7:30 PM, cgel.zte@gmail.com wrote:
> From: chiminghao <chi.minghao@zte.com.cn>
Missing commit log. Please add one and include information on
how you found this problem and tool output.
>
> ARRAY_SIZE defined in <linux/kernel.h> is safer than self-defined
> macros to get size of an array such as ARRAY_LEN used here.
>
> Reported-by: Zeal Robot <zealci@zte.com.cm>
> Signed-off-by: chiminghao <chi.minghao@zte.com.cn>
> ---
> tools/testing/selftests/openat2/openat2_test.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/openat2/openat2_test.c b/tools/testing/selftests/openat2/openat2_test.c
> index 1bddbe934204..c467f85e854e 100644
> --- a/tools/testing/selftests/openat2/openat2_test.c
> +++ b/tools/testing/selftests/openat2/openat2_test.c
> @@ -5,6 +5,7 @@
> */
>
> #define _GNU_SOURCE
> +#include <linux/kernel.h>
> #include <fcntl.h>
> #include <sched.h>
> #include <sys/stat.h>
> @@ -82,14 +83,14 @@ void test_openat2_struct(void)
> .size = sizeof(struct open_how_ext), .err = -E2BIG },
> };
>
> - BUILD_BUG_ON(ARRAY_LEN(misalignments) != NUM_OPENAT2_STRUCT_VARIATIONS);
> - BUILD_BUG_ON(ARRAY_LEN(tests) != NUM_OPENAT2_STRUCT_TESTS);
> + BUILD_BUG_ON(ARRAY_SIZE(misalignments) != NUM_OPENAT2_STRUCT_VARIATIONS);
> + BUILD_BUG_ON(ARRAY_SIZE(tests) != NUM_OPENAT2_STRUCT_TESTS);
>
> - for (int i = 0; i < ARRAY_LEN(tests); i++) {
> + for (int i = 0; i < ARRAY_SIZE(tests); i++) {
> struct struct_test *test = &tests[i];
> struct open_how_ext how_ext = test->arg;
>
> - for (int j = 0; j < ARRAY_LEN(misalignments); j++) {
> + for (int j = 0; j < ARRAY_SIZE(misalignments); j++) {
> int fd, misalign = misalignments[j];
> char *fdpath = NULL;
> bool failed;
> @@ -240,9 +241,9 @@ void test_openat2_flags(void)
> .how.resolve = 0, .err = -EINVAL },
> };
>
> - BUILD_BUG_ON(ARRAY_LEN(tests) != NUM_OPENAT2_FLAG_TESTS);
> + BUILD_BUG_ON(ARRAY_SIZE(tests) != NUM_OPENAT2_FLAG_TESTS);
>
> - for (int i = 0; i < ARRAY_LEN(tests); i++) {
> + for (int i = 0; i < ARRAY_SIZE(tests); i++) {
> int fd, fdflags = -1;
> char *path, *fdpath = NULL;
> bool failed = false;
>
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-19 23:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19 2:30 [PATCH] openat2: use ARRAY_SIZE instead of ARRAY_LEN cgel.zte
2021-11-19 23:42 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).