From: Alejandro Colomar <colomar.6.4.3@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: colomar.6.4.3@gmail.com
Subject: Multiple definitions of ARRAY_SIZE(arr)
Date: Sun, 6 Sep 2020 13:05:37 +0200 [thread overview]
Message-ID: <d55df87a-c867-ae40-c27c-0894ffbba429@gmail.com> (raw)
Hi all,
I was reading through kernel code, and found that there are many
definitions of `ARRAY_SIZE(arr)` all around the kernel.
Is there a reason for all of those to exist, or should they all just
include <linux/kernel.h>? If so, I would be happy to patch them.
Moreover, only the <linux/kernel.h> one is safe because of
`__must_be_array(arr)`.
Here's what I found:
$ grep -rn "define ARRAY_SIZE("
fs/orangefs/orangefs-debug.h:21:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof((arr)[0]))
fs/unicode/mkutf8data.c:63:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
scripts/genksyms/genksyms.c:406:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof((arr)[0]))
scripts/dtc/util.h:26:#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
scripts/mod/file2alias.c:713:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
scripts/kconfig/preprocess.c:15:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof((arr)[0]))
scripts/kallsyms.c:28:#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
include/linux/kernel.h:47:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof((arr)[0]) + __must_be_array(arr))
tools/gpio/gpio-utils.h:17:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof((arr)[0]))
tools/iio/iio_utils.h:18:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof(arr[0]))
tools/virtio/linux/kernel.h:50:#define ARRAY_SIZE(x)
(sizeof(x)/sizeof(x[0]))
tools/lib/traceevent/plugins/plugin_xen.c:103:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/include/linux/kernel.h:107:#define ARRAY_SIZE(arr) (sizeof(arr) /
sizeof((arr)[0]) + __must_be_array(arr))
tools/power/cpupower/utils/cpupower.c:23:#define ARRAY_SIZE(x)
(sizeof(x)/sizeof(x[0]))
tools/usb/usbip/libsrc/usbip_device_driver.c:30:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/spi/spidev_test.c:26:#define ARRAY_SIZE(a) (sizeof(a) /
sizeof((a)[0]))
tools/testing/selftests/seccomp/seccomp_benchmark.c:17:#define
ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
tools/testing/selftests/sparc64/drivers/adi-test.c:28:# define
ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
tools/testing/selftests/net/reuseport_bpf.c:28:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/net/tcp_fastopen_backup_key.c:38:#define
ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/net/socket.c:34:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/net/rxtimestamp.c:21:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/kselftest_harness.h:590:#define ARRAY_SIZE(a)
(sizeof(a) / sizeof(a[0]))
tools/testing/selftests/timens/procfs.c:27:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/timens/timens.c:25:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/cgroup/cgroup_util.h:7:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/rseq/basic_percpu_ops_test.c:14:#define
ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/rseq/rseq.c:32:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/ir/ir_loopback.c:29:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/vm/va_128TBswitch.c:12:#define ARRAY_SIZE(arr)
(sizeof(arr) / sizeof((arr)[0]))
tools/testing/selftests/x86/protection_keys.c:54:#define ARRAY_SIZE(x)
(sizeof(x) / sizeof(*(x)))
tools/testing/selftests/bpf/progs/test_sysctl_loop1.c:13:#define
ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
tools/testing/selftests/bpf/progs/test_sysctl_loop2.c:13:#define
ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
tools/testing/selftests/bpf/progs/test_sysctl_prog.c:19:#define
ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
tools/testing/selftests/bpf/bpf_util.h:31:# define ARRAY_SIZE(x)
(sizeof(x) / sizeof((x)[0]))
tools/vm/page-types.c:209:#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
samples/seccomp/user-trap.c:24:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof(*(x)))
samples/mic/mpssd/mpssd.c:40:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
samples/bpf/cookie_uid_helper_example.c:34:#define ARRAY_SIZE(x)
(sizeof(x) / sizeof(*(x)))
arch/powerpc/boot/types.h:7:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
arch/mips/boot/tools/relocs.h:32:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
arch/um/include/shared/user.h:17:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
arch/x86/tools/insn_sanity.c:19:#define ARRAY_SIZE(a)
(sizeof(a)/sizeof(a[0]))
arch/x86/tools/relocs.h:22:#define ARRAY_SIZE(x) (sizeof(x) /
sizeof((x)[0]))
arch/x86/boot/boot.h:31:#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
Documentation/process/coding-style.rst:985: #define ARRAY_SIZE(x)
(sizeof(x) / sizeof((x)[0]))
Documentation/translations/zh_CN/process/coding-style.rst:823: #define
ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Documentation/translations/it_IT/process/coding-style.rst:1001: #define
ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Alex
next reply other threads:[~2020-09-06 11:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-06 11:05 Alejandro Colomar [this message]
2020-09-06 11:40 ` Multiple definitions of ARRAY_SIZE(arr) Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d55df87a-c867-ae40-c27c-0894ffbba429@gmail.com \
--to=colomar.6.4.3@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox