Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2538755pxk; Sun, 6 Sep 2020 04:10:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS37Cm2WzUh+yCw8o7dJ6KpoZOKktnw3QX5E3fdVsUxzjnQ7hprzMPKrUaoQw78Nz3yl9z X-Received: by 2002:aa7:c3d4:: with SMTP id l20mr17119324edr.263.1599390618704; Sun, 06 Sep 2020 04:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599390618; cv=none; d=google.com; s=arc-20160816; b=a6mAQbxZFSRT4nSE8DF300qSTRl9eHv5IvQ0D5mIU+tph35nlZy6nXsW/oFEj6jifK rbLLp8+Wz1zJOknKYYkEImhO/FE7Jm0tgMv/ExY3yJeo1IL/GyaraXeM6xykqccloIEj /HGCntcXRMPTuD8jFV6sIXpkJILz7BPUirMqVxHTAaglXv2l4D+izgXzlf54bHkMTEIP abOPPsluZwKdN+OM00igV0pkPLGxrGOfgm8eWG/tus65MB3wdot5ZOY9WKJAUzwEABpb BwszqZlSpp634Dv1IhIgGry1zbg3JIUOk0sgjqOeELjIcVz1CCE3idOkMBbBVt1sIgDF U9FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to:dkim-signature; bh=sXURuKdB3VULZ4Bj9H0oogd+JM16i76T2nWZbzsfcyM=; b=aL/JIFGqyaQ1ToaRIv+eKnFOyaHe4ELkQFn8EDPbH4LoNCJp5xqQXpDC/tBSc+iVqr 7bHO3b0o3McCowTMpgIPLlwEwTd0dVUlOFdXbQ0FTKIQORnHvJvo6S8z0r5R3nHO0t3u aDFT+dBweNJr+l+8eYO7DVvfjPZIOGLHo5LYLlM77OWugZm93aHOEa2h+zN8g7lN7R0/ BScEY6sOe+57373blmylciqr66/PcGuiOys3VUehfsxnLVPYXXnkwHzL7+JN2/fJXeXj w1WFGF9HI+QaMVjQMKBt96RaQHt9JA6ZlGJvPvuxA7uebNHhxMmJQyJYcKT35hzf4mej 8hIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=B9RLSl+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b21si8924724ejz.77.2020.09.06.04.09.28; Sun, 06 Sep 2020 04:10:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=B9RLSl+M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728662AbgIFLHw (ORCPT + 99 others); Sun, 6 Sep 2020 07:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbgIFLG2 (ORCPT ); Sun, 6 Sep 2020 07:06:28 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FA05C061573 for ; Sun, 6 Sep 2020 04:05:52 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id z4so11719679wrr.4 for ; Sun, 06 Sep 2020 04:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=sXURuKdB3VULZ4Bj9H0oogd+JM16i76T2nWZbzsfcyM=; b=B9RLSl+McTo6/Xhc2S5K4nklx1ICnuNamOIQYGtfT58otK3WlVXrxiWWvAkXah/U5e YFY/5cxsOFbGEsdnJFR388U2CUdYwrTbllyL7gmKkJp22KnypR8wVtiZvsxZ5S3Pj/s8 7k0nmw43qWIs8z4NT7/xXCQYhTwJB8JCXDpq9+PqGiIdcm9RZE8JOZjAyxPJ+iSNNk+e L5FObwS0RQRvTVMiWy5tf2gnUHe7G96mpONQgvlpzHF4Ni8YcP6dSytKzW83mMDOVyS5 pR4OEmgW3GzunIfMw3BEdP9ofy+VXgX4fALcoKT179okvJEtxEQ7tomsE9HH8qQFMaGG wvrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=sXURuKdB3VULZ4Bj9H0oogd+JM16i76T2nWZbzsfcyM=; b=VhZYnI1j7B0S3Hc/qLFwzuFVbYsynEpPPruJrrgmrVE1Hffij7Vmv87jKnHMjTI5+G DCsMqSf1NR5fx+F9EbVubN/Ol/b63fOZ6WCwzXUFp+69Tw28VFZsn12YrlDa0nESn7yi u2Gw0OvLtqgJ36vrcnnMcXf+kwTTMx9RIrjmgZsi0J91P/j7DM3mg6/o+7SiVrWn3Hr6 WgK9fuH5URzNMP4Q3r1S3rOAw5oR+v2k//vdc/8lzTrTKuAPVmhRA3S2sONTMFV0JpEn /7lwZiQlfsvYxjOzeQuUR+rNxuwwgyziisMwWQQ4ezzEFlylV5JPUoT6BR79ATrF1F8O mieQ== X-Gm-Message-State: AOAM530XM8Ts1q4I3GyGCClLiQW7w40Wob2Pruvp6PG27bcksJ2P7GMm Vq0mDWd28SpgG5A+57L8ETq5kBNX8Ig= X-Received: by 2002:a5d:6852:: with SMTP id o18mr16132271wrw.113.1599390339023; Sun, 06 Sep 2020 04:05:39 -0700 (PDT) Received: from [192.168.0.160] ([93.115.133.118]) by smtp.gmail.com with ESMTPSA id z13sm22582758wro.97.2020.09.06.04.05.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Sep 2020 04:05:38 -0700 (PDT) To: linux-kernel@vger.kernel.org Cc: colomar.6.4.3@gmail.com From: Alejandro Colomar Subject: Multiple definitions of ARRAY_SIZE(arr) Message-ID: Date: Sun, 6 Sep 2020 13:05:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ? If so, I would be happy to patch them. Moreover, only the 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