This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3a0fdb019d279fb657774177f7e806d9e37ef6c8
Author: chao an <anc...@xiaomi.com>
AuthorDate: Thu Feb 2 20:31:22 2023 +0800

    nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
    
    Signed-off-by: chao an <anc...@xiaomi.com>
---
 arch/arm/include/cxd56xx/crashdump.h               |  4 ++--
 arch/arm/src/cxd56xx/cxd56_pinconfig.h             |  3 ++-
 arch/arm/src/rtl8720c/chip.h                       |  6 +++---
 arch/arm/src/stm32h7/stm32_fmc.c                   |  6 +++---
 arch/arm64/src/a64/a64_boot.c                      |  2 +-
 arch/arm64/src/common/arm64_arch.h                 |  4 ----
 arch/arm64/src/common/arm64_mmu.c                  |  2 +-
 arch/arm64/src/qemu/qemu_boot.c                    |  2 +-
 arch/sim/src/sim/posix/sim_hostusrsock.c           |  7 +------
 binfmt/libelf/libelf_coredump.c                    |  4 ++--
 boards/arm/cxd56xx/common/src/cxd56_crashdump.c    |  8 ++++----
 .../gd32f4/gd32f450zk-eval/src/gd32f4xx_autoleds.c | 10 +++-------
 .../gd32f4/gd32f450zk-eval/src/gd32f4xx_userleds.c | 14 +++++---------
 boards/arm/samv7/same70-qmtech/src/sam_bringup.c   |  5 ++---
 boards/arm/samv7/same70-xplained/src/sam_bringup.c |  5 ++---
 boards/arm/samv7/samv71-xult/src/sam_bringup.c     |  5 ++---
 .../arm/stm32/nucleo-f207zg/src/stm32_autoleds.c   | 10 +++-------
 .../arm/stm32/nucleo-f207zg/src/stm32_userleds.c   | 14 +++++---------
 .../arm/stm32/nucleo-f303ze/src/stm32_autoleds.c   | 10 +++-------
 .../arm/stm32/nucleo-f303ze/src/stm32_userleds.c   | 14 +++++---------
 .../arm/stm32/nucleo-f429zi/src/stm32_autoleds.c   | 10 +++-------
 boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c  | 14 +++++++-------
 boards/arm/stm32/nucleo-f429zi/src/stm32_spi.c     | 16 ++++++++--------
 .../arm/stm32/nucleo-f429zi/src/stm32_userleds.c   | 14 +++++---------
 boards/arm/stm32f7/nucleo-144/src/stm32_autoleds.c | 10 +++-------
 boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c   | 14 +++++++-------
 boards/arm/stm32f7/nucleo-144/src/stm32_spi.c      | 16 ++++++++--------
 boards/arm/stm32f7/nucleo-144/src/stm32_userleds.c | 14 +++++---------
 .../stm32f777zit6-meadow/src/stm32_autoleds.c      | 10 +++-------
 .../arm/stm32h7/nucleo-h743zi/src/stm32_autoleds.c | 10 +++-------
 .../arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c  |  5 ++---
 .../arm/stm32h7/nucleo-h743zi/src/stm32_userleds.c | 14 +++++---------
 .../stm32h7/nucleo-h743zi2/src/stm32_autoleds.c    | 10 +++-------
 .../stm32h7/nucleo-h743zi2/src/stm32_userleds.c    | 14 +++++---------
 .../stm32h7/stm32h747i-disco/src/stm32_autoleds.c  | 10 +++-------
 .../stm32h7/stm32h747i-disco/src/stm32_userleds.c  | 14 +++++---------
 .../arm/stm32l4/nucleo-l496zg/src/stm32_autoleds.c | 10 +++-------
 boards/arm/stm32l4/nucleo-l496zg/src/stm32_spi.c   | 16 ++++++++--------
 .../arm/stm32l4/nucleo-l496zg/src/stm32_userleds.c | 14 +++++---------
 .../arm/stm32l5/nucleo-l552ze/src/stm32_autoleds.c | 10 +++-------
 .../arm/stm32l5/nucleo-l552ze/src/stm32_userleds.c | 14 +++++---------
 .../arm/stm32l5/stm32l562e-dk/src/stm32_autoleds.c | 10 +++-------
 .../arm/stm32l5/stm32l562e-dk/src/stm32_userleds.c | 14 +++++---------
 .../arm64/a64/pinephone/src/pinephone_autoleds.c   | 10 +++-------
 .../arm64/a64/pinephone/src/pinephone_userleds.c   | 14 +++++---------
 .../renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c   | 14 +++++++-------
 .../renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c   | 14 +++++++-------
 .../esp32c3/common/src/esp32c3_board_spiflash.c    |  6 +++---
 .../xtensa/esp32/common/src/esp32_board_spiflash.c |  6 +++---
 .../xtensa/esp32/esp32-lyrat/src/esp32_buttons.c   | 10 ++++------
 crypto/testmngr.c                                  | 18 ++++++++----------
 drivers/audio/cs4344.c                             |  2 +-
 drivers/audio/cs4344.h                             |  6 ++----
 drivers/audio/es8388.c                             | 12 +++---------
 drivers/clk/clk_rpmsg.c                            |  8 +++-----
 drivers/ioexpander/ioe_rpmsg.c                     |  8 +++-----
 drivers/misc/rpmsgblk.c                            |  2 +-
 drivers/misc/rpmsgblk.h                            |  6 ++----
 drivers/misc/rpmsgblk_server.c                     |  2 +-
 drivers/misc/rpmsgdev.c                            |  2 +-
 drivers/misc/rpmsgdev.h                            |  6 ++----
 drivers/misc/rpmsgdev_server.c                     |  2 +-
 drivers/mtd/rpmsgmtd.c                             |  2 +-
 drivers/mtd/rpmsgmtd.h                             |  5 +----
 drivers/mtd/rpmsgmtd_server.c                      |  2 +-
 drivers/power/pm/pm_procfs.c                       | 14 ++++++--------
 drivers/power/supply/regulator_rpmsg.c             |  8 +++-----
 drivers/sensors/wtgahrs2.c                         |  6 +++---
 drivers/usrsock/usrsock_dev.c                      |  8 ++++----
 fs/rpmsgfs/rpmsgfs.h                               |  5 +----
 fs/rpmsgfs/rpmsgfs_client.c                        |  2 +-
 fs/rpmsgfs/rpmsgfs_server.c                        |  2 +-
 include/nuttx/net/usrsock.h                        |  5 +----
 include/nuttx/wireless/bluetooth/bt_gatt.h         |  2 +-
 libs/libc/termios/lib_cfspeed.c                    |  7 +++----
 libs/libc/time/lib_asctimer.c                      | 14 ++++----------
 net/netfilter/ipt_sockopt.c                        |  8 +++-----
 net/procfs/net_procfs.c                            | 22 +++++++++-------------
 net/usrsock/usrsock_accept.c                       |  4 ++--
 net/usrsock/usrsock_bind.c                         |  2 +-
 net/usrsock/usrsock_close.c                        |  2 +-
 net/usrsock/usrsock_connect.c                      |  2 +-
 net/usrsock/usrsock_getpeername.c                  |  4 ++--
 net/usrsock/usrsock_getsockname.c                  |  4 ++--
 net/usrsock/usrsock_getsockopt.c                   |  4 ++--
 net/usrsock/usrsock_ioctl.c                        |  4 ++--
 net/usrsock/usrsock_listen.c                       |  2 +-
 net/usrsock/usrsock_recvmsg.c                      |  4 ++--
 net/usrsock/usrsock_sendmsg.c                      |  2 +-
 net/usrsock/usrsock_setsockopt.c                   |  2 +-
 net/usrsock/usrsock_shutdown.c                     |  2 +-
 net/usrsock/usrsock_socket.c                       |  2 +-
 net/utils/net_snoop.c                              | 10 ++++------
 wireless/bluetooth/bt_hcicore.c                    |  8 ++++----
 wireless/bluetooth/bt_smp.c                        |  6 +++---
 95 files changed, 291 insertions(+), 451 deletions(-)

diff --git a/arch/arm/include/cxd56xx/crashdump.h 
b/arch/arm/include/cxd56xx/crashdump.h
index e6b7dd142a..e7b3b5d8fa 100644
--- a/arch/arm/include/cxd56xx/crashdump.h
+++ b/arch/arm/include/cxd56xx/crashdump.h
@@ -29,6 +29,8 @@
 
 #include <stdint.h>
 
+#include <sys/param.h>
+
 #include <nuttx/irq.h>
 
 /****************************************************************************
@@ -54,8 +56,6 @@
 #define CONFIG_USTACK_SIZE (CRASHLOG_LEFTOVER / NUMBER_STACKS / \
                             sizeof(stack_word_t))
 
-#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
-
 /* For Assert keep this much of the file name */
 
 #define MAX_FILE_PATH_LENGTH 40
diff --git a/arch/arm/src/cxd56xx/cxd56_pinconfig.h 
b/arch/arm/src/cxd56xx/cxd56_pinconfig.h
index f5c6e7d43d..17b7e9ca7d 100644
--- a/arch/arm/src/cxd56xx/cxd56_pinconfig.h
+++ b/arch/arm/src/cxd56xx/cxd56_pinconfig.h
@@ -28,6 +28,7 @@
 #include <nuttx/config.h>
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <stdint.h>
 #include <stdbool.h>
 
@@ -119,7 +120,7 @@
 
 #define CXD56_PIN_CONFIGS(pin) do { \
   uint32_t p[] = pin; \
-  cxd56_pin_configs((p), sizeof(p) / sizeof((p)[0])); \
+  cxd56_pin_configs((p), nitems(p)); \
 } while (0)
 
 /****************************************************************************
diff --git a/arch/arm/src/rtl8720c/chip.h b/arch/arm/src/rtl8720c/chip.h
index b8032c5043..afa805b443 100644
--- a/arch/arm/src/rtl8720c/chip.h
+++ b/arch/arm/src/rtl8720c/chip.h
@@ -29,15 +29,15 @@
 #  include <stdint.h>
 #  include <sys/types.h>
 #endif
+
+#include <sys/param.h>
+
 #include <arch/chip/chip.h>
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)               (sizeof(x) / sizeof((x)[0]))
-#endif
 /* If the common ARMv7-M vector handling logic is used,
  * then it expects the following
  * definition in this file that provides the number of
diff --git a/arch/arm/src/stm32h7/stm32_fmc.c b/arch/arm/src/stm32h7/stm32_fmc.c
index 934d8679a7..1d4198e6dc 100644
--- a/arch/arm/src/stm32h7/stm32_fmc.c
+++ b/arch/arm/src/stm32h7/stm32_fmc.c
@@ -31,11 +31,11 @@
 #include <assert.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/arch.h>
 #include <arch/board/board.h>
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 /****************************************************************************
  * To use FMC, you must first enable it in configuration:
  *
@@ -265,7 +265,7 @@ void stm32_fmc_init(void)
 
   /* Set up FMC GPIOs */
 
-  for (regval = 0; regval < ARRAY_SIZE(fmc_gpios); regval++)
+  for (regval = 0; regval < nitems(fmc_gpios); regval++)
     stm32_configgpio(fmc_gpios[regval]);
 
   /* Set up FMC registers */
diff --git a/arch/arm64/src/a64/a64_boot.c b/arch/arm64/src/a64/a64_boot.c
index 3a52012eea..ffb66fdf7a 100644
--- a/arch/arm64/src/a64/a64_boot.c
+++ b/arch/arm64/src/a64/a64_boot.c
@@ -62,7 +62,7 @@ static const struct arm_mmu_region mmu_regions[] =
 
 const struct arm_mmu_config mmu_config =
 {
-  .num_regions = ARRAY_SIZE(mmu_regions),
+  .num_regions = nitems(mmu_regions),
   .mmu_regions = mmu_regions,
 };
 
diff --git a/arch/arm64/src/common/arm64_arch.h 
b/arch/arm64/src/common/arm64_arch.h
index f6875ee94e..61a61e6e78 100644
--- a/arch/arm64/src/common/arm64_arch.h
+++ b/arch/arm64/src/common/arm64_arch.h
@@ -145,10 +145,6 @@
 
 #define STRINGIFY(x)    #x
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define GET_EL(mode)  (((mode) >> MODE_EL_SHIFT) & MODE_EL_MASK)
 
 /* MPIDR_EL1, Multiprocessor Affinity Register */
diff --git a/arch/arm64/src/common/arm64_mmu.c 
b/arch/arm64/src/common/arm64_mmu.c
index 3a351f1ff6..025183a8ef 100644
--- a/arch/arm64/src/common/arm64_mmu.c
+++ b/arch/arm64/src/common/arm64_mmu.c
@@ -186,7 +186,7 @@ static const struct arm_mmu_region mmu_nxrt_regions[] =
 
 static const struct arm_mmu_config mmu_nxrt_config =
 {
-  .num_regions = ARRAY_SIZE(mmu_nxrt_regions),
+  .num_regions = nitems(mmu_nxrt_regions),
   .mmu_regions = mmu_nxrt_regions,
 };
 
diff --git a/arch/arm64/src/qemu/qemu_boot.c b/arch/arm64/src/qemu/qemu_boot.c
index aa7d8010ef..b8f7caec4e 100644
--- a/arch/arm64/src/qemu/qemu_boot.c
+++ b/arch/arm64/src/qemu/qemu_boot.c
@@ -62,7 +62,7 @@ static const struct arm_mmu_region mmu_regions[] =
 
 const struct arm_mmu_config mmu_config =
 {
-  .num_regions = ARRAY_SIZE(mmu_regions),
+  .num_regions = nitems(mmu_regions),
   .mmu_regions = mmu_regions,
 };
 
diff --git a/arch/sim/src/sim/posix/sim_hostusrsock.c 
b/arch/sim/src/sim/posix/sim_hostusrsock.c
index 3899990442..b809d45088 100644
--- a/arch/sim/src/sim/posix/sim_hostusrsock.c
+++ b/arch/sim/src/sim/posix/sim_hostusrsock.c
@@ -26,6 +26,7 @@
 #include <sys/uio.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
+#include <sys/param.h>
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -39,12 +40,6 @@
 
 #include "sim_hostusrsock.h"
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
diff --git a/binfmt/libelf/libelf_coredump.c b/binfmt/libelf/libelf_coredump.c
index 2bee8a23fd..13462a720d 100644
--- a/binfmt/libelf/libelf_coredump.c
+++ b/binfmt/libelf/libelf_coredump.c
@@ -25,6 +25,7 @@
 #include <nuttx/config.h>
 
 #include <sys/stat.h>
+#include <sys/param.h>
 
 #include <stdio.h>
 #include <stdint.h>
@@ -44,7 +45,6 @@
 
 #define ELF_PAGESIZE    4096
 
-#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 #define ROUNDUP(x, y)   ((x + (y - 1)) / (y)) * (y)
 
 /****************************************************************************
@@ -244,7 +244,7 @@ static void elf_emit_note_info(FAR struct elf_dumpinfo_s 
*cinfo)
 
       status.pr_pid = tcb->pid;
 
-      for (j = 0; j < ARRAY_SIZE(status.pr_regs); j++)
+      for (j = 0; j < nitems(status.pr_regs); j++)
         {
           status.pr_regs[j] = *(uintptr_t *)((uint8_t *)tcb +
                                              g_tcbinfo.reg_off.p[j]);
diff --git a/boards/arm/cxd56xx/common/src/cxd56_crashdump.c 
b/boards/arm/cxd56xx/common/src/cxd56_crashdump.c
index 893137919e..30cb86e9d0 100644
--- a/boards/arm/cxd56xx/common/src/cxd56_crashdump.c
+++ b/boards/arm/cxd56xx/common/src/cxd56_crashdump.c
@@ -200,8 +200,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
   if ((pdump->info.flags & INTSTACK_PRESENT) != 0)
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
-      copy_reverse(pdump->istack, &ps[ARRAYSIZE(pdump->istack) / 2],
-                   ARRAYSIZE(pdump->istack));
+      copy_reverse(pdump->istack, &ps[nitems(pdump->istack) / 2],
+                   nitems(pdump->istack));
     }
 
   /* Is it Invalid? */
@@ -221,8 +221,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
   if ((pdump->info.flags & USERSTACK_PRESENT) != 0)
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
-      copy_reverse(pdump->ustack, &ps[ARRAYSIZE(pdump->ustack) / 2],
-                   ARRAYSIZE(pdump->ustack));
+      copy_reverse(pdump->ustack, &ps[nitems(pdump->ustack) / 2],
+                   nitems(pdump->ustack));
     }
 
   /* Is it Invalid? */
diff --git a/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_autoleds.c 
b/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_autoleds.c
index da2869fd8a..2fb8dc9af9 100644
--- a/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_autoleds.c
+++ b/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -34,12 +36,6 @@
 #include "gd32f450z_eval.h"
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -87,7 +83,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LED GPIO for output. */
 
-  for (i = 0; i < ARRAYSIZE(g_led_map); i++)
+  for (i = 0; i < nitems(g_led_map); i++)
     {
       gd32_gpio_config(g_led_map[i]);
     }
diff --git a/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_userleds.c 
b/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_userleds.c
index c93549bcd7..9ff8af2cda 100644
--- a/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_userleds.c
+++ b/boards/arm/gd32f4/gd32f450zk-eval/src/gd32f4xx_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -100,7 +96,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure the LED GPIO for output. */
 
-  for (i = 0; i < ARRAYSIZE(g_led_map); i++)
+  for (i = 0; i < nitems(g_led_map); i++)
     {
       gd32_gpio_config(g_led_map[i]);
     }
@@ -120,7 +116,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_led_map))
+  if ((unsigned)led < nitems(g_led_map))
     {
       gd32_gpio_write(g_led_map[led], ledon);
     }
@@ -144,7 +140,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_led_map); i++)
+  for (i = 0; i < nitems(g_led_map); i++)
     {
       gd32_gpio_write(g_led_map[i], (ledset & g_led_setmap[i]) != 0);
     }
diff --git a/boards/arm/samv7/same70-qmtech/src/sam_bringup.c 
b/boards/arm/samv7/same70-qmtech/src/sam_bringup.c
index 02a73d82a1..3039d11486 100644
--- a/boards/arm/samv7/same70-qmtech/src/sam_bringup.c
+++ b/boards/arm/samv7/same70-qmtech/src/sam_bringup.c
@@ -25,6 +25,7 @@
 #include <nuttx/config.h>
 
 #include <sys/mount.h>
+#include <sys/param.h>
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -72,8 +73,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
-
 #define NSECTORS(n) \
   (((n)+CONFIG_SAME70QMTECH_ROMFS_ROMDISK_SECTSIZE-1) / \
    CONFIG_SAME70QMTECH_ROMFS_ROMDISK_SECTSIZE)
@@ -103,7 +102,7 @@ static struct mtd_partition_s g_mtd_partition_table[] =
 };
 
 static const size_t g_mtd_partition_table_size =
-    ARRAY_SIZE(g_mtd_partition_table);
+    nitems(g_mtd_partition_table);
 #else
 #  define g_mtd_partition_table         NULL
 #  define g_mtd_partition_table_size    0
diff --git a/boards/arm/samv7/same70-xplained/src/sam_bringup.c 
b/boards/arm/samv7/same70-xplained/src/sam_bringup.c
index 84911fcebf..688ae3064d 100644
--- a/boards/arm/samv7/same70-xplained/src/sam_bringup.c
+++ b/boards/arm/samv7/same70-xplained/src/sam_bringup.c
@@ -25,6 +25,7 @@
 #include <nuttx/config.h>
 
 #include <sys/mount.h>
+#include <sys/param.h>
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -65,8 +66,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
-
 #define NSECTORS(n) \
   (((n)+CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_SECTSIZE-1) / \
    CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_SECTSIZE)
@@ -96,7 +95,7 @@ static struct mtd_partition_s g_mtd_partition_table[] =
 };
 
 static const size_t g_mtd_partition_table_size =
-    ARRAY_SIZE(g_mtd_partition_table);
+    nitems(g_mtd_partition_table);
 #else
 #  define g_mtd_partition_table         NULL
 #  define g_mtd_partition_table_size    0
diff --git a/boards/arm/samv7/samv71-xult/src/sam_bringup.c 
b/boards/arm/samv7/samv71-xult/src/sam_bringup.c
index c0cd15c988..38d816ed2a 100644
--- a/boards/arm/samv7/samv71-xult/src/sam_bringup.c
+++ b/boards/arm/samv7/samv71-xult/src/sam_bringup.c
@@ -25,6 +25,7 @@
 #include <nuttx/config.h>
 
 #include <sys/mount.h>
+#include <sys/param.h>
 
 #include <stdbool.h>
 #include <stdio.h>
@@ -90,8 +91,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
-
 #define NSECTORS(n) \
   (((n)+CONFIG_SAMV71XULT_ROMFS_ROMDISK_SECTSIZE-1) / \
    CONFIG_SAMV71XULT_ROMFS_ROMDISK_SECTSIZE)
@@ -121,7 +120,7 @@ static struct mtd_partition_s g_mtd_partition_table[] =
 };
 
 static const size_t g_mtd_partition_table_size =
-    ARRAY_SIZE(g_mtd_partition_table);
+    nitems(g_mtd_partition_table);
 #else
 #  define g_mtd_partition_table         NULL
 #  define g_mtd_partition_table_size    0
diff --git a/boards/arm/stm32/nucleo-f207zg/src/stm32_autoleds.c 
b/boards/arm/stm32/nucleo-f207zg/src/stm32_autoleds.c
index 0850c52fdd..fd0a8f24c0 100644
--- a/boards/arm/stm32/nucleo-f207zg/src/stm32_autoleds.c
+++ b/boards/arm/stm32/nucleo-f207zg/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32/nucleo-f207zg/src/stm32_userleds.c 
b/boards/arm/stm32/nucleo-f207zg/src/stm32_userleds.c
index c1ed6774f6..e6d4ea0fef 100644
--- a/boards/arm/stm32/nucleo-f207zg/src/stm32_userleds.c
+++ b/boards/arm/stm32/nucleo-f207zg/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32/nucleo-f303ze/src/stm32_autoleds.c 
b/boards/arm/stm32/nucleo-f303ze/src/stm32_autoleds.c
index c225497bb7..d3cae757bc 100644
--- a/boards/arm/stm32/nucleo-f303ze/src/stm32_autoleds.c
+++ b/boards/arm/stm32/nucleo-f303ze/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32/nucleo-f303ze/src/stm32_userleds.c 
b/boards/arm/stm32/nucleo-f303ze/src/stm32_userleds.c
index f300b06c5e..c2d10a64e4 100644
--- a/boards/arm/stm32/nucleo-f303ze/src/stm32_userleds.c
+++ b/boards/arm/stm32/nucleo-f303ze/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_autoleds.c 
b/boards/arm/stm32/nucleo-f429zi/src/stm32_autoleds.c
index e9a9e4bdd9..1d42a140ec 100644
--- a/boards/arm/stm32/nucleo-f429zi/src/stm32_autoleds.c
+++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -34,12 +36,6 @@
 #include "nucleo-144.h"
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -80,7 +76,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c 
b/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c
index e3cc48813e..df58583d76 100644
--- a/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c
+++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c
@@ -36,6 +36,8 @@
 #include <debug.h>
 #include <syslog.h>
 
+#include <sys/param.h>
+
 #include <nuttx/fs/fs.h>
 
 #include "arm_internal.h"
@@ -102,15 +104,13 @@
   0 \
 }
 
-#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
-
 /* For Assert keep this much of the file name */
 
 #define MAX_FILE_PATH_LENGTH 40
 
 #define HEADER_TIME_FMT      "%Y-%m-%d-%H:%M:%S"
 #define HEADER_TIME_FMT_NUM  (2+ 0+ 0+ 0+ 0+ 0)
-#define HEADER_TIME_FMT_LEN  (((ARRAYSIZE(HEADER_TIME_FMT)-1) + \
+#define HEADER_TIME_FMT_LEN  (((nitems(HEADER_TIME_FMT)-1) + \
                                 HEADER_TIME_FMT_NUM))
 
 /****************************************************************************
@@ -465,8 +465,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
   if ((pdump->info.flags & INTSTACK_PRESENT) != 0)
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
-      copy_reverse(pdump->istack, &ps[ARRAYSIZE(pdump->istack) / 2],
-                   ARRAYSIZE(pdump->istack));
+      copy_reverse(pdump->istack, &ps[nitems(pdump->istack) / 2],
+                   nitems(pdump->istack));
     }
 
   /* Is it Invalid? */
@@ -487,8 +487,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
   if ((pdump->info.flags & USERSTACK_PRESENT) != 0)
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
-      copy_reverse(pdump->ustack, &ps[ARRAYSIZE(pdump->ustack) / 2],
-                   ARRAYSIZE(pdump->ustack));
+      copy_reverse(pdump->ustack, &ps[nitems(pdump->ustack) / 2],
+                   nitems(pdump->ustack));
     }
 
   /* Is it Invalid? */
diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_spi.c 
b/boards/arm/stm32/nucleo-f429zi/src/stm32_spi.c
index a727551b53..c8532a3f45 100644
--- a/boards/arm/stm32/nucleo-f429zi/src/stm32_spi.c
+++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_spi.c
@@ -29,6 +29,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/spi/spi.h>
 #include <arch/board/board.h>
 
@@ -45,8 +47,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 #if defined(CONFIG_NUCLEO_SPI1_TEST)
 #  if defined(CONFIG_NUCLEO_SPI1_TEST_MODE0)
 #    define CONFIG_NUCLEO_SPI1_TEST_MODE SPIDEV_MODE0
@@ -200,7 +200,7 @@ void weak_function stm32_spidev_initialize(void)
   /* Configure SPI CS GPIO for output */
 
 #if defined(CONFIG_STM32F4_SPI1)
-  for (int i = 0; i < ARRAYSIZE(g_spi1gpio); i++)
+  for (int i = 0; i < nitems(g_spi1gpio); i++)
     {
       if (g_spi1gpio[i] != 0)
         {
@@ -210,7 +210,7 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32F4_SPI2)
-  for (int i = 0; i < ARRAYSIZE(g_spi2gpio); i++)
+  for (int i = 0; i < nitems(g_spi2gpio); i++)
     {
       if (g_spi2gpio[i] != 0)
         {
@@ -220,7 +220,7 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32F4_SPI3)
-  for (int i = 0; i < ARRAYSIZE(g_spi3gpio); i++)
+  for (int i = 0; i < nitems(g_spi3gpio); i++)
     {
       if (g_spi3gpio[i] != 0)
         {
@@ -451,7 +451,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi1, CONFIG_NUCLEO_SPI1_TEST_FREQ);
   SPI_SETBITS(spi1, CONFIG_NUCLEO_SPI1_TEST_BITS);
   SPI_SETMODE(spi1, CONFIG_NUCLEO_SPI1_TEST_MODE);
-  SPI_EXCHANGE(spi1, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi1, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
 #if defined(CONFIG_NUCLEO_SPI2_TEST)
@@ -468,7 +468,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi2, CONFIG_NUCLEO_SPI2_TEST_FREQ);
   SPI_SETBITS(spi2, CONFIG_NUCLEO_SPI2_TEST_BITS);
   SPI_SETMODE(spi2, CONFIG_NUCLEO_SPI2_TEST_MODE);
-  SPI_EXCHANGE(spi2, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi2, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
 #if defined(CONFIG_NUCLEO_SPI3_TEST)
@@ -485,7 +485,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi3, CONFIG_NUCLEO_SPI3_TEST_FREQ);
   SPI_SETBITS(spi3, CONFIG_NUCLEO_SPI3_TEST_BITS);
   SPI_SETMODE(spi3, CONFIG_NUCLEO_SPI3_TEST_MODE);
-  SPI_EXCHANGE(spi3, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi3, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
   return OK;
diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_userleds.c 
b/boards/arm/stm32/nucleo-f429zi/src/stm32_userleds.c
index 30286b157b..cce7d1a5c2 100644
--- a/boards/arm/stm32/nucleo-f429zi/src/stm32_userleds.c
+++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -121,7 +117,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_autoleds.c 
b/boards/arm/stm32f7/nucleo-144/src/stm32_autoleds.c
index 5516183759..f854ba1ba8 100644
--- a/boards/arm/stm32f7/nucleo-144/src/stm32_autoleds.c
+++ b/boards/arm/stm32f7/nucleo-144/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -34,12 +36,6 @@
 #include "nucleo-144.h"
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -80,7 +76,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c 
b/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c
index 5793e720f7..e73fcab10a 100644
--- a/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c
+++ b/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c
@@ -36,6 +36,8 @@
 #include <debug.h>
 #include <syslog.h>
 
+#include <sys/param.h>
+
 #include <nuttx/fs/fs.h>
 
 #include "arm_internal.h"
@@ -102,15 +104,13 @@
   0 \
 }
 
-#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
-
 /* For Assert keep this much of the file name */
 
 #define MAX_FILE_PATH_LENGTH 40
 
 #define HEADER_TIME_FMT      "%Y-%m-%d-%H:%M:%S"
 #define HEADER_TIME_FMT_NUM  (2+ 0+ 0+ 0+ 0+ 0)
-#define HEADER_TIME_FMT_LEN  (((ARRAYSIZE(HEADER_TIME_FMT)-1) + \
+#define HEADER_TIME_FMT_LEN  (((nitems(HEADER_TIME_FMT)-1) + \
                                 HEADER_TIME_FMT_NUM))
 
 /****************************************************************************
@@ -465,8 +465,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
   if ((pdump->info.flags & INTSTACK_PRESENT) != 0)
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
-      copy_reverse(pdump->istack, &ps[ARRAYSIZE(pdump->istack) / 2],
-                   ARRAYSIZE(pdump->istack));
+      copy_reverse(pdump->istack, &ps[nitems(pdump->istack) / 2],
+                   nitems(pdump->istack));
     }
 
   /* Is it Invalid? */
@@ -487,8 +487,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
   if ((pdump->info.flags & USERSTACK_PRESENT) != 0)
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
-      copy_reverse(pdump->ustack, &ps[ARRAYSIZE(pdump->ustack) / 2],
-                   ARRAYSIZE(pdump->ustack));
+      copy_reverse(pdump->ustack, &ps[nitems(pdump->ustack) / 2],
+                   nitems(pdump->ustack));
     }
 
   /* Is it Invalid? */
diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_spi.c 
b/boards/arm/stm32f7/nucleo-144/src/stm32_spi.c
index dce4c65ee0..1fbf6aeb40 100644
--- a/boards/arm/stm32f7/nucleo-144/src/stm32_spi.c
+++ b/boards/arm/stm32f7/nucleo-144/src/stm32_spi.c
@@ -29,6 +29,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/spi/spi.h>
 #include <arch/board/board.h>
 
@@ -45,8 +47,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 #if defined(CONFIG_NUCLEO_SPI1_TEST)
 #  if defined(CONFIG_NUCLEO_SPI1_TEST_MODE0)
 #    define CONFIG_NUCLEO_SPI1_TEST_MODE SPIDEV_MODE0
@@ -200,7 +200,7 @@ void weak_function stm32_spidev_initialize(void)
   /* Configure SPI CS GPIO for output */
 
 #if defined(CONFIG_STM32F7_SPI1)
-  for (int i = 0; i < ARRAYSIZE(g_spi1gpio); i++)
+  for (int i = 0; i < nitems(g_spi1gpio); i++)
     {
       if (g_spi1gpio[i] != 0)
         {
@@ -210,7 +210,7 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32F7_SPI2)
-  for (int i = 0; i < ARRAYSIZE(g_spi2gpio); i++)
+  for (int i = 0; i < nitems(g_spi2gpio); i++)
     {
       if (g_spi2gpio[i] != 0)
         {
@@ -220,7 +220,7 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32F7_SPI3)
-  for (int i = 0; i < ARRAYSIZE(g_spi3gpio); i++)
+  for (int i = 0; i < nitems(g_spi3gpio); i++)
     {
       if (g_spi3gpio[i] != 0)
         {
@@ -451,7 +451,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi1, CONFIG_NUCLEO_SPI1_TEST_FREQ);
   SPI_SETBITS(spi1, CONFIG_NUCLEO_SPI1_TEST_BITS);
   SPI_SETMODE(spi1, CONFIG_NUCLEO_SPI1_TEST_MODE);
-  SPI_EXCHANGE(spi1, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi1, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
 #if defined(CONFIG_NUCLEO_SPI2_TEST)
@@ -468,7 +468,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi2, CONFIG_NUCLEO_SPI2_TEST_FREQ);
   SPI_SETBITS(spi2, CONFIG_NUCLEO_SPI2_TEST_BITS);
   SPI_SETMODE(spi2, CONFIG_NUCLEO_SPI2_TEST_MODE);
-  SPI_EXCHANGE(spi2, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi2, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
 #if defined(CONFIG_NUCLEO_SPI3_TEST)
@@ -485,7 +485,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi3, CONFIG_NUCLEO_SPI3_TEST_FREQ);
   SPI_SETBITS(spi3, CONFIG_NUCLEO_SPI3_TEST_BITS);
   SPI_SETMODE(spi3, CONFIG_NUCLEO_SPI3_TEST_MODE);
-  SPI_EXCHANGE(spi3, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi3, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
   return OK;
diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_userleds.c 
b/boards/arm/stm32f7/nucleo-144/src/stm32_userleds.c
index 32722d84d6..249d835300 100644
--- a/boards/arm/stm32f7/nucleo-144/src/stm32_userleds.c
+++ b/boards/arm/stm32f7/nucleo-144/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32f7/stm32f777zit6-meadow/src/stm32_autoleds.c 
b/boards/arm/stm32f7/stm32f777zit6-meadow/src/stm32_autoleds.c
index abcf74c08c..3c7afcc510 100644
--- a/boards/arm/stm32f7/stm32f777zit6-meadow/src/stm32_autoleds.c
+++ b/boards/arm/stm32f7/stm32f777zit6-meadow/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
       phy_set_led(i, false);
diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_autoleds.c 
b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_autoleds.c
index ccbabd7ef6..7102558d05 100644
--- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_autoleds.c
+++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c 
b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c
index 3c3fc4788b..893da57f29 100644
--- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c
+++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c
@@ -25,6 +25,7 @@
 #include <nuttx/config.h>
 
 #include <sys/mount.h>
+#include <sys/param.h>
 
 #include <stdbool.h>
 #include <stdlib.h>
@@ -52,8 +53,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAYSIZE(x)                (sizeof((x)) / sizeof((x)[0]))
-
 #define PARTITION_LABEL_LEN         16
 
 /* Configuration ************************************************************/
@@ -183,7 +182,7 @@ static int init_ota_partitions(void)
   int ret = 0;
   char path[PARTITION_LABEL_LEN + 1];
 
-  for (i = 0; i < ARRAYSIZE(g_ota_partition_table); ++i)
+  for (i = 0; i < nitems(g_ota_partition_table); ++i)
     {
       const struct ota_partition_s *part = &g_ota_partition_table[i];
       mtd = progmem_alloc_mtdpart(part->offset, part->size);
diff --git a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_userleds.c 
b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_userleds.c
index bd93ed8370..3d22d5b197 100644
--- a/boards/arm/stm32h7/nucleo-h743zi/src/stm32_userleds.c
+++ b/boards/arm/stm32h7/nucleo-h743zi/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_autoleds.c 
b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_autoleds.c
index db26e84ef5..d2a930b627 100644
--- a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_autoleds.c
+++ b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -81,7 +77,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_userleds.c 
b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_userleds.c
index 5e35c63df1..ab0d59154a 100644
--- a/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_userleds.c
+++ b/boards/arm/stm32h7/nucleo-h743zi2/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_autoleds.c 
b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_autoleds.c
index cbaf6c01bb..52e4646adb 100644
--- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_autoleds.c
+++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -82,7 +78,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_userleds.c 
b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_userleds.c
index 6f77d9c279..b094e340ed 100644
--- a/boards/arm/stm32h7/stm32h747i-disco/src/stm32_userleds.c
+++ b/boards/arm/stm32h7/stm32h747i-disco/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -78,7 +74,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_configgpio(g_ledcfg[i]);
     }
@@ -100,7 +96,7 @@ void board_userled(int led, bool ledon)
 {
   /* Active Low */
 
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32_gpiowrite(g_ledcfg[led], !ledon);
     }
@@ -123,7 +119,7 @@ void board_userled_all(uint32_t ledset)
 
   int i;
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) == 0);
     }
diff --git a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_autoleds.c 
b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_autoleds.c
index b589d21ee3..4e4deba2c7 100644
--- a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_autoleds.c
+++ b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_autoleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -34,12 +36,6 @@
 #include "nucleo-144.h"
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -80,7 +76,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1 GPIO for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32l4_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_spi.c 
b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_spi.c
index f56e110e36..0b7e1cdc4d 100644
--- a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_spi.c
+++ b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_spi.c
@@ -29,6 +29,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/spi/spi.h>
 #include <arch/board/board.h>
 
@@ -45,8 +47,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 #if defined(CONFIG_NUCLEO_SPI1_TEST)
 #  if defined(CONFIG_NUCLEO_SPI1_TEST_MODE0)
 #    define CONFIG_NUCLEO_SPI1_TEST_MODE SPIDEV_MODE0
@@ -200,7 +200,7 @@ void weak_function stm32_spidev_initialize(void)
   /* Configure SPI CS GPIO for output */
 
 #if defined(CONFIG_STM32L4_SPI1)
-  for (int i = 0; i < ARRAYSIZE(g_spi1gpio); i++)
+  for (int i = 0; i < nitems(g_spi1gpio); i++)
     {
       if (g_spi1gpio[i] != 0)
         {
@@ -210,7 +210,7 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32L4_SPI2)
-  for (int i = 0; i < ARRAYSIZE(g_spi2gpio); i++)
+  for (int i = 0; i < nitems(g_spi2gpio); i++)
     {
       if (g_spi2gpio[i] != 0)
         {
@@ -220,7 +220,7 @@ void weak_function stm32_spidev_initialize(void)
 #endif
 
 #if defined(CONFIG_STM32L4_SPI3)
-  for (int i = 0; i < ARRAYSIZE(g_spi3gpio); i++)
+  for (int i = 0; i < nitems(g_spi3gpio); i++)
     {
       if (g_spi3gpio[i] != 0)
         {
@@ -387,7 +387,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi1, CONFIG_NUCLEO_SPI1_TEST_FREQ);
   SPI_SETBITS(spi1, CONFIG_NUCLEO_SPI1_TEST_BITS);
   SPI_SETMODE(spi1, CONFIG_NUCLEO_SPI1_TEST_MODE);
-  SPI_EXCHANGE(spi1, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi1, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
 #if defined(CONFIG_NUCLEO_SPI2_TEST)
@@ -404,7 +404,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi2, CONFIG_NUCLEO_SPI2_TEST_FREQ);
   SPI_SETBITS(spi2, CONFIG_NUCLEO_SPI2_TEST_BITS);
   SPI_SETMODE(spi2, CONFIG_NUCLEO_SPI2_TEST_MODE);
-  SPI_EXCHANGE(spi2, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi2, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
 #if defined(CONFIG_NUCLEO_SPI3_TEST)
@@ -421,7 +421,7 @@ int stm32_spidev_bus_test(void)
   SPI_SETFREQUENCY(spi3, CONFIG_NUCLEO_SPI3_TEST_FREQ);
   SPI_SETBITS(spi3, CONFIG_NUCLEO_SPI3_TEST_BITS);
   SPI_SETMODE(spi3, CONFIG_NUCLEO_SPI3_TEST_MODE);
-  SPI_EXCHANGE(spi3, tx, NULL, ARRAYSIZE(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
+  SPI_EXCHANGE(spi3, tx, NULL, nitems(CONFIG_NUCLEO_SPI_TEST_MESSAGE));
 #endif
 
   return OK;
diff --git a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_userleds.c 
b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_userleds.c
index ce8cf332e8..0db902fe80 100644
--- a/boards/arm/stm32l4/nucleo-l496zg/src/stm32_userleds.c
+++ b/boards/arm/stm32l4/nucleo-l496zg/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32l4_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32l4_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -120,7 +116,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32l4_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32l5/nucleo-l552ze/src/stm32_autoleds.c 
b/boards/arm/stm32l5/nucleo-l552ze/src/stm32_autoleds.c
index a478c68f5b..4dbb8ba594 100644
--- a/boards/arm/stm32l5/nucleo-l552ze/src/stm32_autoleds.c
+++ b/boards/arm/stm32l5/nucleo-l552ze/src/stm32_autoleds.c
@@ -28,6 +28,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 
 #include "chip.h"
@@ -39,12 +41,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -83,7 +79,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD1, LD2 and LD3 GPIOs for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32l5_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32l5/nucleo-l552ze/src/stm32_userleds.c 
b/boards/arm/stm32l5/nucleo-l552ze/src/stm32_userleds.c
index 22ea743350..59c96d7f67 100644
--- a/boards/arm/stm32l5/nucleo-l552ze/src/stm32_userleds.c
+++ b/boards/arm/stm32l5/nucleo-l552ze/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -77,7 +73,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32l5_configgpio(g_ledcfg[i]);
     }
@@ -97,7 +93,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32l5_gpiowrite(g_ledcfg[led], ledon);
     }
@@ -119,7 +115,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32l5_gpiowrite(g_ledcfg[i], (ledset & (1 << i)) != 0);
     }
diff --git a/boards/arm/stm32l5/stm32l562e-dk/src/stm32_autoleds.c 
b/boards/arm/stm32l5/stm32l562e-dk/src/stm32_autoleds.c
index 1a9d8249b5..8e45ddc4c5 100644
--- a/boards/arm/stm32l5/stm32l562e-dk/src/stm32_autoleds.c
+++ b/boards/arm/stm32l5/stm32l562e-dk/src/stm32_autoleds.c
@@ -28,6 +28,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 
 #include "chip.h"
@@ -39,12 +41,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -82,7 +78,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LD9 and LD10 GPIOs for output. Initial state is OFF */
 
-  for (i = 0; i < ARRAYSIZE(g_ledmap); i++)
+  for (i = 0; i < nitems(g_ledmap); i++)
     {
       stm32l5_configgpio(g_ledmap[i]);
     }
diff --git a/boards/arm/stm32l5/stm32l562e-dk/src/stm32_userleds.c 
b/boards/arm/stm32l5/stm32l562e-dk/src/stm32_userleds.c
index a165bbfbdf..b4baf76768 100644
--- a/boards/arm/stm32l5/stm32l562e-dk/src/stm32_userleds.c
+++ b/boards/arm/stm32l5/stm32l562e-dk/src/stm32_userleds.c
@@ -27,6 +27,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -35,12 +37,6 @@
 
 #ifndef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -76,7 +72,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure LED1-2 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32l5_configgpio(g_ledcfg[i]);
     }
@@ -96,7 +92,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_ledcfg))
+  if ((unsigned)led < nitems(g_ledcfg))
     {
       stm32l5_gpiowrite(g_ledcfg[led], !ledon);
     }
@@ -118,7 +114,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-2 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_ledcfg); i++)
+  for (i = 0; i < nitems(g_ledcfg); i++)
     {
       stm32l5_gpiowrite(g_ledcfg[i], !(ledset & (1 << i)));
     }
diff --git a/boards/arm64/a64/pinephone/src/pinephone_autoleds.c 
b/boards/arm64/a64/pinephone/src/pinephone_autoleds.c
index 1bce21a600..95da430575 100644
--- a/boards/arm64/a64/pinephone/src/pinephone_autoleds.c
+++ b/boards/arm64/a64/pinephone/src/pinephone_autoleds.c
@@ -28,6 +28,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -37,12 +39,6 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -116,7 +112,7 @@ void board_autoled_initialize(void)
 
   /* Configure the LED GPIO for output. */
 
-  for (i = 0; i < ARRAYSIZE(g_led_map); i++)
+  for (i = 0; i < nitems(g_led_map); i++)
     {
       ret = a64_pio_config(g_led_map[i]);
       DEBUGASSERT(ret == OK);
diff --git a/boards/arm64/a64/pinephone/src/pinephone_userleds.c 
b/boards/arm64/a64/pinephone/src/pinephone_userleds.c
index 87fdd1dc9e..1e6754d6cc 100644
--- a/boards/arm64/a64/pinephone/src/pinephone_userleds.c
+++ b/boards/arm64/a64/pinephone/src/pinephone_userleds.c
@@ -28,6 +28,8 @@
 #include <stdbool.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/board.h>
 #include <arch/board/board.h>
 
@@ -37,12 +39,6 @@
 
 #ifdef CONFIG_USERLED
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -102,7 +98,7 @@ uint32_t board_userled_initialize(void)
 
   /* Configure the LED GPIO for output. */
 
-  for (i = 0; i < ARRAYSIZE(g_led_map); i++)
+  for (i = 0; i < nitems(g_led_map); i++)
     {
       ret = a64_pio_config(g_led_map[i]);
       DEBUGASSERT(ret == OK);
@@ -142,7 +138,7 @@ uint32_t board_userled_initialize(void)
 
 void board_userled(int led, bool ledon)
 {
-  if ((unsigned)led < ARRAYSIZE(g_led_map))
+  if ((unsigned)led < nitems(g_led_map))
     {
       a64_pio_write(g_led_map[led], ledon);
     }
@@ -182,7 +178,7 @@ void board_userled_all(uint32_t ledset)
 
   /* Configure LED1-3 GPIOs for output */
 
-  for (i = 0; i < ARRAYSIZE(g_led_map); i++)
+  for (i = 0; i < nitems(g_led_map); i++)
     {
       a64_pio_write(g_led_map[i], (ledset & g_led_setmap[i]) != 0);
     }
diff --git a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c 
b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c
index 83c7621317..7f3b696d26 100644
--- a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c
+++ b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c
@@ -36,6 +36,8 @@
 #include <debug.h>
 #include <syslog.h>
 
+#include <sys/param.h>
+
 #include <nuttx/fs/fs.h>
 #include <nuttx/sched.h>
 #include "renesas_internal.h"
@@ -101,15 +103,13 @@
   0 \
 }
 
-#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
-
 /* For Assert keep this much of the file name */
 
 #define MAX_FILE_PATH_LENGTH 40
 
 #define HEADER_TIME_FMT      "%Y-%m-%d-%H:%M:%S"
 #define HEADER_TIME_FMT_NUM  (2+ 0+ 0+ 0+ 0+ 0)
-#define HEADER_TIME_FMT_LEN  (((ARRAYSIZE(HEADER_TIME_FMT)-1) + \
+#define HEADER_TIME_FMT_LEN  (((nitems(HEADER_TIME_FMT)-1) + \
                                 HEADER_TIME_FMT_NUM))
 
 /****************************************************************************
@@ -420,8 +420,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
       copy_reverse((stack_word_t *)pdump->istack,
-                        &ps[ARRAYSIZE(pdump->istack) / 2],
-                    ARRAYSIZE(pdump->istack));
+                        &ps[nitems(pdump->istack) / 2],
+                    nitems(pdump->istack));
     }
 
   /* Is it Invalid? */
@@ -443,8 +443,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
       copy_reverse((stack_word_t *)pdump->ustack,
-                        &ps[ARRAYSIZE(pdump->ustack) / 2],
-                    ARRAYSIZE(pdump->ustack));
+                        &ps[nitems(pdump->ustack) / 2],
+                    nitems(pdump->ustack));
     }
 
   /* Is it Invalid? */
diff --git a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c 
b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c
index 42e51f5ac2..10f889fe9d 100644
--- a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c
+++ b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c
@@ -36,6 +36,8 @@
 #include <debug.h>
 #include <syslog.h>
 
+#include <sys/param.h>
+
 #include <nuttx/fs/fs.h>
 #include <nuttx/sched.h>
 #include "renesas_internal.h"
@@ -101,15 +103,13 @@
   0 \
 }
 
-#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
-
 /* For Assert keep this much of the file name */
 
 #define MAX_FILE_PATH_LENGTH 40
 
 #define HEADER_TIME_FMT      "%Y-%m-%d-%H:%M:%S"
 #define HEADER_TIME_FMT_NUM  (2+ 0+ 0+ 0+ 0+ 0)
-#define HEADER_TIME_FMT_LEN  (((ARRAYSIZE(HEADER_TIME_FMT)-1) + \
+#define HEADER_TIME_FMT_LEN  (((nitems(HEADER_TIME_FMT)-1) + \
                                 HEADER_TIME_FMT_NUM))
 
 /****************************************************************************
@@ -418,8 +418,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.interrupt.sp;
       copy_reverse((stack_word_t *)pdump->istack,
-                        &ps[ARRAYSIZE(pdump->istack) / 2],
-                    ARRAYSIZE(pdump->istack));
+                        &ps[nitems(pdump->istack) / 2],
+                    nitems(pdump->istack));
     }
 
   /* Is it Invalid? */
@@ -440,8 +440,8 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb,
     {
       stack_word_t *ps = (stack_word_t *) pdump->info.stacks.user.sp;
       copy_reverse((stack_word_t *)pdump->ustack,
-                        &ps[ARRAYSIZE(pdump->ustack) / 2],
-                    ARRAYSIZE(pdump->ustack));
+                        &ps[nitems(pdump->ustack) / 2],
+                    nitems(pdump->ustack));
     }
 
   /* Is it Invalid? */
diff --git a/boards/risc-v/esp32c3/common/src/esp32c3_board_spiflash.c 
b/boards/risc-v/esp32c3/common/src/esp32c3_board_spiflash.c
index 79a10547c2..98fe049a94 100644
--- a/boards/risc-v/esp32c3/common/src/esp32c3_board_spiflash.c
+++ b/boards/risc-v/esp32c3/common/src/esp32c3_board_spiflash.c
@@ -34,6 +34,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/kmalloc.h>
 #include <nuttx/spi/spi.h>
 #include <nuttx/mtd/mtd.h>
@@ -52,8 +54,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAYSIZE(x)                (sizeof((x)) / sizeof((x)[0]))
-
 #ifdef CONFIG_ESP32C3_OTA_PARTITION_ENCRYPT
 #  define OTA_ENCRYPT true
 #else
@@ -147,7 +147,7 @@ static int init_ota_partitions(void)
 #endif
   int ret = OK;
 
-  for (int i = 0; i < ARRAYSIZE(g_ota_partition_table); ++i)
+  for (int i = 0; i < nitems(g_ota_partition_table); ++i)
     {
       const struct ota_partition_s *part = &g_ota_partition_table[i];
       mtd = esp32c3_spiflash_alloc_mtdpart(part->offset, part->size,
diff --git a/boards/xtensa/esp32/common/src/esp32_board_spiflash.c 
b/boards/xtensa/esp32/common/src/esp32_board_spiflash.c
index 66bfcc0317..61fb6e0658 100644
--- a/boards/xtensa/esp32/common/src/esp32_board_spiflash.c
+++ b/boards/xtensa/esp32/common/src/esp32_board_spiflash.c
@@ -31,6 +31,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/fs/fs.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/mtd/mtd.h>
@@ -49,8 +51,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAYSIZE(x)                (sizeof((x)) / sizeof((x)[0]))
-
 #ifdef CONFIG_ESP32_OTA_PARTITION_ENCRYPT
 #  define OTA_ENCRYPT true
 #else
@@ -128,7 +128,7 @@ static int init_ota_partitions(void)
 #endif
   int ret = OK;
 
-  for (int i = 0; i < ARRAYSIZE(g_ota_partition_table); ++i)
+  for (int i = 0; i < nitems(g_ota_partition_table); ++i)
     {
       const struct ota_partition_s *part = &g_ota_partition_table[i];
       mtd = esp32_spiflash_alloc_mtdpart(part->offset, part->size,
diff --git a/boards/xtensa/esp32/esp32-lyrat/src/esp32_buttons.c 
b/boards/xtensa/esp32/esp32-lyrat/src/esp32_buttons.c
index 874540d6c9..d04ef4b006 100644
--- a/boards/xtensa/esp32/esp32-lyrat/src/esp32_buttons.c
+++ b/boards/xtensa/esp32/esp32-lyrat/src/esp32_buttons.c
@@ -30,6 +30,8 @@
 #include <stdbool.h>
 #include <stdio.h>
 
+#include <sys/param.h>
+
 #include <nuttx/arch.h>
 #include <arch/board/board.h>
 #include <nuttx/board.h>
@@ -45,10 +47,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define TOUCHPAD_REFH               (TOUCH_HVOLT_2V7)
 #define TOUCHPAD_REFL               (TOUCH_LVOLT_0V5)
 #define TOUCHPAD_ATTEN              (TOUCH_HVOLT_ATTEN_1V)
@@ -190,7 +188,7 @@ uint32_t board_buttons(void)
   bool b1;
   int n;
 
-  for (uint8_t btn_id = 0; btn_id < ARRAY_SIZE(g_buttons); btn_id++)
+  for (uint8_t btn_id = 0; btn_id < nitems(g_buttons); btn_id++)
     {
       iinfo("Reading button %d\n", btn_id);
 
@@ -265,7 +263,7 @@ uint32_t board_buttons(void)
 #ifdef CONFIG_ARCH_IRQBUTTONS
 int board_button_irq(int id, xcpt_t irqhandler, void *arg)
 {
-  DEBUGASSERT(id < ARRAY_SIZE(g_buttons));
+  DEBUGASSERT(id < nitems(g_buttons));
 
   int ret;
   button_type_t button_info = g_buttons[id];
diff --git a/crypto/testmngr.c b/crypto/testmngr.c
index 4f5489ccfc..6d32b175a4 100644
--- a/crypto/testmngr.c
+++ b/crypto/testmngr.c
@@ -31,6 +31,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/fs/fs.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/crypto/crypto.h>
@@ -43,10 +45,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #if defined(CONFIG_CRYPTO_AES)
 
 /****************************************************************************
@@ -94,14 +92,14 @@ static int test_aes(void)
 {
   int i;
 
-  AES_CYPHER_TEST(AES_MODE_ECB, "ECB", ARRAY_SIZE(aes_enc_tv_template),
-                  ARRAY_SIZE(aes_dec_tv_template), aes_enc_tv_template,
+  AES_CYPHER_TEST(AES_MODE_ECB, "ECB", nitems(aes_enc_tv_template),
+                  nitems(aes_dec_tv_template), aes_enc_tv_template,
                   aes_dec_tv_template)
-  AES_CYPHER_TEST(AES_MODE_CBC, "CBC", ARRAY_SIZE(aes_cbc_enc_tv_template),
-                  ARRAY_SIZE(aes_cbc_dec_tv_template),
+  AES_CYPHER_TEST(AES_MODE_CBC, "CBC", nitems(aes_cbc_enc_tv_template),
+                  nitems(aes_cbc_dec_tv_template),
                   aes_cbc_enc_tv_template, aes_cbc_dec_tv_template)
-  AES_CYPHER_TEST(AES_MODE_CTR, "CTR", ARRAY_SIZE(aes_ctr_enc_tv_template),
-                  ARRAY_SIZE(aes_ctr_dec_tv_template),
+  AES_CYPHER_TEST(AES_MODE_CTR, "CTR", nitems(aes_ctr_enc_tv_template),
+                  nitems(aes_ctr_dec_tv_template),
                   aes_ctr_enc_tv_template, aes_ctr_dec_tv_template)
 
   return OK;
diff --git a/drivers/audio/cs4344.c b/drivers/audio/cs4344.c
index ac83e83c33..c538772266 100644
--- a/drivers/audio/cs4344.c
+++ b/drivers/audio/cs4344.c
@@ -247,7 +247,7 @@ static int cs4344_setmclkfrequency(FAR struct cs4344_dev_s 
*priv)
 
   priv->mclk_freq = 0;
 
-  for (i = 0; i < ARRAY_SIZE(mclk_rate); i++)
+  for (i = 0; i < nitems(mclk_rate); i++)
     {
       if (mclk_rate[i].sample_rate == priv->samprate)
         {
diff --git a/drivers/audio/cs4344.h b/drivers/audio/cs4344.h
index 92a0d6b3f0..8379879bb7 100644
--- a/drivers/audio/cs4344.h
+++ b/drivers/audio/cs4344.h
@@ -31,6 +31,8 @@
 #include <pthread.h>
 #include <mqueue.h>
 
+#include <sys/param.h>
+
 #include <nuttx/wqueue.h>
 #include <nuttx/mutex.h>
 #include <nuttx/fs/ioctl.h>
@@ -41,10 +43,6 @@
  * Pre-Processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define CS4344_DEFAULT_SAMPRATE      11025     /* Initial sample rate */
 #define CS4344_DEFAULT_NCHANNELS     1         /* Initial number of channels */
 #define CS4344_DEFAULT_BPSAMP        16        /* Initial bits per sample */
diff --git a/drivers/audio/es8388.c b/drivers/audio/es8388.c
index 0a59e03628..7e81eba636 100644
--- a/drivers/audio/es8388.c
+++ b/drivers/audio/es8388.c
@@ -39,6 +39,8 @@
 #include <debug.h>
 #include <pthread.h>
 
+#include <sys/param.h>
+
 #include <nuttx/kmalloc.h>
 #include <nuttx/mqueue.h>
 #include <nuttx/queue.h>
@@ -53,14 +55,6 @@
 
 #include "es8388.h"
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /****************************************************************************
  * Private Function Prototypes
  ****************************************************************************/
@@ -465,7 +459,7 @@ static void es8388_setmclkfrequency(FAR struct es8388_dev_s 
*priv)
 {
   priv->mclk = 0;
 
-  for (int i = 0; i < ARRAY_SIZE(es8388_mclk_rate); i++)
+  for (int i = 0; i < nitems(es8388_mclk_rate); i++)
     {
       if (es8388_mclk_rate[i].sample_rate == priv->samprate)
         {
diff --git a/drivers/clk/clk_rpmsg.c b/drivers/clk/clk_rpmsg.c
index e0bbc50f35..20c633b1fd 100644
--- a/drivers/clk/clk_rpmsg.c
+++ b/drivers/clk/clk_rpmsg.c
@@ -26,6 +26,8 @@
 
 #include <string.h>
 
+#include <sys/param.h>
+
 #include <nuttx/clk/clk.h>
 #include <nuttx/clk/clk_provider.h>
 #include <nuttx/kmalloc.h>
@@ -48,10 +50,6 @@
 #define CLK_RPMSG_ROUNDRATE         6
 #define CLK_RPMSG_ISENABLED         7
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)             (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -606,7 +604,7 @@ static int clk_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept, 
FAR void *data,
           ret = 0;
         }
     }
-  else if (cmd < ARRAY_SIZE(g_clk_rpmsg_handler)
+  else if (cmd < nitems(g_clk_rpmsg_handler)
            && g_clk_rpmsg_handler[cmd])
     {
       hdr->response = 1;
diff --git a/drivers/ioexpander/ioe_rpmsg.c b/drivers/ioexpander/ioe_rpmsg.c
index 7507ce6adb..8020fced26 100644
--- a/drivers/ioexpander/ioe_rpmsg.c
+++ b/drivers/ioexpander/ioe_rpmsg.c
@@ -27,6 +27,8 @@
 #include <errno.h>
 #include <stdio.h>
 
+#include <sys/param.h>
+
 #include <nuttx/ioexpander/ioe_rpmsg.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/nuttx.h>
@@ -37,10 +39,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define IOE_RPMSG_EPT_FORMAT   "rpmsg-ioe-%s"
 
 #define IOE_RPMSG_DIRECTION    0
@@ -596,7 +594,7 @@ static int ioe_rpmsg_server_ept_cb(FAR struct 
rpmsg_endpoint *ept,
   FAR struct ioe_rpmsg_header_s *msg = data;
   uint32_t cmd = msg->command;
 
-  if (cmd < ARRAY_SIZE(g_ioe_rpmsg_handler) && g_ioe_rpmsg_handler[cmd])
+  if (cmd < nitems(g_ioe_rpmsg_handler) && g_ioe_rpmsg_handler[cmd])
     {
       return g_ioe_rpmsg_handler[cmd](ept, data, len, src, priv_);
     }
diff --git a/drivers/misc/rpmsgblk.c b/drivers/misc/rpmsgblk.c
index e88ecbba4a..0e8ea02bb8 100644
--- a/drivers/misc/rpmsgblk.c
+++ b/drivers/misc/rpmsgblk.c
@@ -986,7 +986,7 @@ static int rpmsgblk_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgblk_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgblk_handler))
+  if (command < nitems(g_rpmsgblk_handler))
     {
       return g_rpmsgblk_handler[command](ept, data, len, src, priv);
     }
diff --git a/drivers/misc/rpmsgblk.h b/drivers/misc/rpmsgblk.h
index 84d609e9d6..ab5be5c24d 100644
--- a/drivers/misc/rpmsgblk.h
+++ b/drivers/misc/rpmsgblk.h
@@ -27,14 +27,12 @@
 
 #include <nuttx/compiler.h>
 
+#include <sys/param.h>
+
 /****************************************************************************
  * Pre-processor definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)         (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define RPMSGBLK_NAME_PREFIX     "rpmsgblk-"
 #define RPMSGBLK_NAME_PREFIX_LEN 9
 
diff --git a/drivers/misc/rpmsgblk_server.c b/drivers/misc/rpmsgblk_server.c
index 2ef9cde8a9..210e227c8d 100644
--- a/drivers/misc/rpmsgblk_server.c
+++ b/drivers/misc/rpmsgblk_server.c
@@ -365,7 +365,7 @@ static int rpmsgblk_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgblk_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgblk_handler))
+  if (command < nitems(g_rpmsgblk_handler))
     {
       return g_rpmsgblk_handler[command](ept, data, len, src, priv);
     }
diff --git a/drivers/misc/rpmsgdev.c b/drivers/misc/rpmsgdev.c
index 4023b44501..a5fe49340c 100644
--- a/drivers/misc/rpmsgdev.c
+++ b/drivers/misc/rpmsgdev.c
@@ -1109,7 +1109,7 @@ static int rpmsgdev_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgdev_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgdev_handler))
+  if (command < nitems(g_rpmsgdev_handler))
     {
       return g_rpmsgdev_handler[command](ept, data, len, src, priv);
     }
diff --git a/drivers/misc/rpmsgdev.h b/drivers/misc/rpmsgdev.h
index c8b5611a3d..a276612df3 100644
--- a/drivers/misc/rpmsgdev.h
+++ b/drivers/misc/rpmsgdev.h
@@ -27,14 +27,12 @@
 
 #include <nuttx/compiler.h>
 
+#include <sys/param.h>
+
 /****************************************************************************
  * Pre-processor definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)         (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define RPMSGDEV_NAME_PREFIX     "rpmsgdev-"
 #define RPMSGDEV_NAME_PREFIX_LEN 9
 
diff --git a/drivers/misc/rpmsgdev_server.c b/drivers/misc/rpmsgdev_server.c
index 2b56571c8e..16965627bc 100644
--- a/drivers/misc/rpmsgdev_server.c
+++ b/drivers/misc/rpmsgdev_server.c
@@ -459,7 +459,7 @@ static int rpmsgdev_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgdev_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgdev_handler))
+  if (command < nitems(g_rpmsgdev_handler))
     {
       return g_rpmsgdev_handler[command](ept, data, len, src, priv);
     }
diff --git a/drivers/mtd/rpmsgmtd.c b/drivers/mtd/rpmsgmtd.c
index aeaa83814f..458dbd793a 100644
--- a/drivers/mtd/rpmsgmtd.c
+++ b/drivers/mtd/rpmsgmtd.c
@@ -995,7 +995,7 @@ static int rpmsgmtd_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgmtd_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgmtd_handler))
+  if (command < nitems(g_rpmsgmtd_handler))
     {
       return g_rpmsgmtd_handler[command](ept, data, len, src, priv);
     }
diff --git a/drivers/mtd/rpmsgmtd.h b/drivers/mtd/rpmsgmtd.h
index 523c515957..39d01b068f 100644
--- a/drivers/mtd/rpmsgmtd.h
+++ b/drivers/mtd/rpmsgmtd.h
@@ -27,15 +27,12 @@
 
 #include <nuttx/compiler.h>
 #include <sys/types.h>
+#include <sys/param.h>
 
 /****************************************************************************
  * Pre-processor definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)         (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define RPMSGMTD_NAME_PREFIX     "rpmsgmtd-"
 #define RPMSGMTD_NAME_PREFIX_LEN 9
 
diff --git a/drivers/mtd/rpmsgmtd_server.c b/drivers/mtd/rpmsgmtd_server.c
index fd6377866f..7a9654d730 100644
--- a/drivers/mtd/rpmsgmtd_server.c
+++ b/drivers/mtd/rpmsgmtd_server.c
@@ -383,7 +383,7 @@ static int rpmsgmtd_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgmtd_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgmtd_handler))
+  if (command < nitems(g_rpmsgmtd_handler))
     {
       return g_rpmsgmtd_handler[command](ept, data, len, src, priv);
     }
diff --git a/drivers/power/pm/pm_procfs.c b/drivers/power/pm/pm_procfs.c
index d4b8585a19..83b1a90a78 100644
--- a/drivers/power/pm/pm_procfs.c
+++ b/drivers/power/pm/pm_procfs.c
@@ -30,6 +30,8 @@
 #include <debug.h>
 #include <errno.h>
 
+#include <sys/param.h>
+
 #include <nuttx/nuttx.h>
 #include <nuttx/fs/fs.h>
 #include <nuttx/fs/procfs.h>
@@ -62,10 +64,6 @@
 
 #define PM_LINELEN 128
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 typedef ssize_t (*pm_read_t)(FAR struct file *filep,
                              FAR char *buffer, size_t buflen);
 
@@ -193,7 +191,7 @@ static int pm_open(FAR struct file *filep, FAR const char 
*relpath,
     }
 
   relpath += strlen("pm/");
-  for (i = 0; i < ARRAY_SIZE(g_pm_files); i++)
+  for (i = 0; i < nitems(g_pm_files); i++)
     {
       if (strncmp(relpath, g_pm_files[i].name,
                   strlen(g_pm_files[i].name)) == 0)
@@ -462,7 +460,7 @@ static int pm_opendir(FAR const char *relpath, FAR struct 
fs_dirent_s **dir)
   /* Initialize base structure components */
 
   level1->level    = 1;
-  level1->nentries = CONFIG_PM_NDOMAINS * ARRAY_SIZE(g_pm_files);
+  level1->nentries = CONFIG_PM_NDOMAINS * nitems(g_pm_files);
 
   *dir = (FAR struct fs_dirent_s *)level1;
   return OK;
@@ -511,8 +509,8 @@ static int pm_readdir(FAR struct fs_dirent_s *dir,
       return -ENOENT;
     }
 
-  domain = index / ARRAY_SIZE(g_pm_files);
-  fpos   = index % ARRAY_SIZE(g_pm_files);
+  domain = index / nitems(g_pm_files);
+  fpos   = index % nitems(g_pm_files);
 
   entry->d_type = DTYPE_FILE;
   snprintf(entry->d_name, NAME_MAX + 1, "%s%d",
diff --git a/drivers/power/supply/regulator_rpmsg.c 
b/drivers/power/supply/regulator_rpmsg.c
index ccd4edb0f7..8943618ee6 100644
--- a/drivers/power/supply/regulator_rpmsg.c
+++ b/drivers/power/supply/regulator_rpmsg.c
@@ -29,6 +29,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <sys/param.h>
+
 #include <nuttx/kmalloc.h>
 #include <nuttx/list.h>
 #include <nuttx/power/consumer.h>
@@ -38,10 +40,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define REGULATOR_RPMSG_EPT_NAME    "rpmsg-regulator"
 
 #define REGULATOR_RPMSG_ENABLE      0
@@ -400,7 +398,7 @@ static int regulator_rpmsg_ept_cb(FAR struct rpmsg_endpoint 
*ept,
       nxsem_post(&cookie->sem);
       ret = 0;
     }
-  else if (cmd < ARRAY_SIZE(g_regulator_rpmsg_handler)
+  else if (cmd < nitems(g_regulator_rpmsg_handler)
            && g_regulator_rpmsg_handler[cmd])
     {
       header->response = 1;
diff --git a/drivers/sensors/wtgahrs2.c b/drivers/sensors/wtgahrs2.c
index 8ae2156b50..8b349fea44 100644
--- a/drivers/sensors/wtgahrs2.c
+++ b/drivers/sensors/wtgahrs2.c
@@ -30,6 +30,8 @@
 #include <nuttx/kthread.h>
 #include <nuttx/kmalloc.h>
 
+#include <sys/param.h>
+
 #include <termios.h>
 #include <math.h>
 #include <fcntl.h>
@@ -40,8 +42,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define WTGAHRS2_ARRAYSIZE(a)      (sizeof((a))/sizeof(a[0]))
-
 #define WTGAHRS2_ACCEL_IDX         0
 #define WTGAHRS2_GYRO_IDX          1
 #define WTGAHRS2_MAG_IDX           2
@@ -170,7 +170,7 @@ static int wtgahrs2_set_interval(FAR struct 
sensor_lowerhalf_s *lower,
   FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower;
   int idx = 0;
 
-  for (; idx < WTGAHRS2_ARRAYSIZE(g_wtgahrs2_interval) - 1; idx++)
+  for (; idx < nitems(g_wtgahrs2_interval) - 1; idx++)
     {
       if (*interval >= g_wtgahrs2_interval[idx])
         {
diff --git a/drivers/usrsock/usrsock_dev.c b/drivers/usrsock/usrsock_dev.c
index d14e8a8df6..7ea170cc29 100644
--- a/drivers/usrsock/usrsock_dev.c
+++ b/drivers/usrsock/usrsock_dev.c
@@ -436,7 +436,7 @@ static int usrsockdev_poll(FAR struct file *filep, FAR 
struct pollfd *fds,
        * slot for the poll structure reference
        */
 
-      for (i = 0; i < ARRAY_SIZE(dev->pollfds); i++)
+      for (i = 0; i < nitems(dev->pollfds); i++)
         {
           /* Find an available slot */
 
@@ -450,7 +450,7 @@ static int usrsockdev_poll(FAR struct file *filep, FAR 
struct pollfd *fds,
             }
         }
 
-      if (i >= ARRAY_SIZE(dev->pollfds))
+      if (i >= nitems(dev->pollfds))
         {
           fds->priv = NULL;
           ret = -EBUSY;
@@ -470,7 +470,7 @@ static int usrsockdev_poll(FAR struct file *filep, FAR 
struct pollfd *fds,
           eventset |= POLLIN;
         }
 
-      poll_notify(dev->pollfds, ARRAY_SIZE(dev->pollfds), eventset);
+      poll_notify(dev->pollfds, nitems(dev->pollfds), eventset);
     }
   else
     {
@@ -521,7 +521,7 @@ int usrsock_request(FAR struct iovec *iov, unsigned int 
iovcnt)
 
       /* Notify daemon of new request. */
 
-      poll_notify(dev->pollfds, ARRAY_SIZE(dev->pollfds), POLLIN);
+      poll_notify(dev->pollfds, nitems(dev->pollfds), POLLIN);
     }
   else
     {
diff --git a/fs/rpmsgfs/rpmsgfs.h b/fs/rpmsgfs/rpmsgfs.h
index 6b9d2384af..271ab340b5 100644
--- a/fs/rpmsgfs/rpmsgfs.h
+++ b/fs/rpmsgfs/rpmsgfs.h
@@ -28,15 +28,12 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include <sys/statfs.h>
+#include <sys/param.h>
 
 /****************************************************************************
  * Pre-processor definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)         (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define RPMSGFS_NAME_PREFIX     "rpmsgfs-"
 
 #define RPMSGFS_OPEN            1
diff --git a/fs/rpmsgfs/rpmsgfs_client.c b/fs/rpmsgfs/rpmsgfs_client.c
index 5d360c096a..1811bcdb5e 100644
--- a/fs/rpmsgfs/rpmsgfs_client.c
+++ b/fs/rpmsgfs/rpmsgfs_client.c
@@ -323,7 +323,7 @@ static int rpmsgfs_ept_cb(FAR struct rpmsg_endpoint *ept,
   FAR struct rpmsgfs_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgfs_handler))
+  if (command < nitems(g_rpmsgfs_handler))
     {
       return g_rpmsgfs_handler[command](ept, data, len, src, priv);
     }
diff --git a/fs/rpmsgfs/rpmsgfs_server.c b/fs/rpmsgfs/rpmsgfs_server.c
index 4385a29034..92b3e51a71 100644
--- a/fs/rpmsgfs/rpmsgfs_server.c
+++ b/fs/rpmsgfs/rpmsgfs_server.c
@@ -904,7 +904,7 @@ static int rpmsgfs_ept_cb(FAR struct rpmsg_endpoint *ept,
   struct rpmsgfs_header_s *header = data;
   uint32_t command = header->command;
 
-  if (command < ARRAY_SIZE(g_rpmsgfs_handler))
+  if (command < nitems(g_rpmsgfs_handler))
     {
       return g_rpmsgfs_handler[command](ept, data, len, src, priv);
     }
diff --git a/include/nuttx/net/usrsock.h b/include/nuttx/net/usrsock.h
index 70e38e92ae..9336c06353 100644
--- a/include/nuttx/net/usrsock.h
+++ b/include/nuttx/net/usrsock.h
@@ -30,6 +30,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <sys/uio.h>
+#include <sys/param.h>
 
 #include <nuttx/net/netconfig.h>
 #include <nuttx/compiler.h>
@@ -38,10 +39,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /* Event message flags */
 
 #define USRSOCK_EVENT_ABORT          (1 << 1)
diff --git a/include/nuttx/wireless/bluetooth/bt_gatt.h 
b/include/nuttx/wireless/bluetooth/bt_gatt.h
index 3dad20f4df..7b9940404f 100644
--- a/include/nuttx/wireless/bluetooth/bt_gatt.h
+++ b/include/nuttx/wireless/bluetooth/bt_gatt.h
@@ -328,7 +328,7 @@
   .user_data = (&(struct _bt_gatt_ccc_s) \
                { \
                  .cfg          = _cfg, \
-                 .cfg_len      = ARRAY_SIZE(_cfg), \
+                 .cfg_len      = nitems(_cfg), \
                  .value_handle = _value_handle, \
                  .cfg_changed  = _cfg_changed, \
                }),\
diff --git a/libs/libc/termios/lib_cfspeed.c b/libs/libc/termios/lib_cfspeed.c
index 5086372f55..79f5025ddd 100644
--- a/libs/libc/termios/lib_cfspeed.c
+++ b/libs/libc/termios/lib_cfspeed.c
@@ -23,6 +23,7 @@
  ****************************************************************************/
 
 #include <sys/types.h>
+#include <sys/param.h>
 #include <termios.h>
 #include <assert.h>
 #include <errno.h>
@@ -34,8 +35,6 @@
 #define CBAUD          0010017  /* Baud speed mask (not in POSIX) */
 #define BOTHER         0010000  /* Magic token for custom baud rate */
 
-#define ARRAYSIZE(a)   (sizeof((a))/sizeof(a[0]))
-
 /****************************************************************************
  * Private Type Definitions
  ****************************************************************************/
@@ -147,7 +146,7 @@ int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
   size_t idx;
 
   DEBUGASSERT(termiosp);
-  for (idx = 0; idx < ARRAYSIZE(g_baud_table); idx++)
+  for (idx = 0; idx < nitems(g_baud_table); idx++)
     {
       if (speed == g_baud_table[idx].mask)
         {
@@ -162,7 +161,7 @@ int cfsetspeed(FAR struct termios *termiosp, speed_t speed)
         }
     }
 
-  if (idx == ARRAYSIZE(g_baud_table))
+  if (idx == nitems(g_baud_table))
     {
       termiosp->c_speed = speed;
       speed = BOTHER;
diff --git a/libs/libc/time/lib_asctimer.c b/libs/libc/time/lib_asctimer.c
index 14ccf2b206..a2bef81ff1 100644
--- a/libs/libc/time/lib_asctimer.c
+++ b/libs/libc/time/lib_asctimer.c
@@ -26,15 +26,9 @@
 
 #include <stdio.h>
 
-#include <nuttx/time.h>
+#include <sys/param.h>
 
-/****************************************************************************
- * Pre-processor definitions
- ****************************************************************************/
-
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x)         (sizeof(x) / sizeof((x)[0]))
-#endif
+#include <nuttx/time.h>
 
 /****************************************************************************
  * Private Data
@@ -82,8 +76,8 @@ FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf)
   char tmp[128];
 
   if (tp == NULL ||
-      tp->tm_wday >= ARRAY_SIZE(g_wday_name) ||
-      tp->tm_mon >= ARRAY_SIZE(g_mon_name))
+      tp->tm_wday >= nitems(g_wday_name) ||
+      tp->tm_mon >= nitems(g_mon_name))
     {
       return NULL;
     }
diff --git a/net/netfilter/ipt_sockopt.c b/net/netfilter/ipt_sockopt.c
index 3f9dc3612f..56e23bf3f9 100644
--- a/net/netfilter/ipt_sockopt.c
+++ b/net/netfilter/ipt_sockopt.c
@@ -27,6 +27,8 @@
 #include <stdint.h>
 #include <string.h>
 
+#include <sys/param.h>
+
 #include <nuttx/kmalloc.h>
 
 #include "netfilter/iptables.h"
@@ -37,10 +39,6 @@
 
 #define SWAP(a,b,t)    do { t = a; a = b; b = t; } while (0)
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
-
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -116,7 +114,7 @@ static void ipt_table_init(FAR struct ipt_table_s *table)
 static FAR struct ipt_table_s *ipt_table(FAR const char *name)
 {
   int i;
-  for (i = 0; i < ARRAY_SIZE(g_tables); i++)
+  for (i = 0; i < nitems(g_tables); i++)
     {
       ipt_table_init(&g_tables[i]);
       if (g_tables[i].repl != NULL &&
diff --git a/net/procfs/net_procfs.c b/net/procfs/net_procfs.c
index fb42e67445..837f7ff100 100644
--- a/net/procfs/net_procfs.c
+++ b/net/procfs/net_procfs.c
@@ -37,6 +37,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/kmalloc.h>
 #include <nuttx/fs/fs.h>
 #include <nuttx/fs/procfs.h>
@@ -48,12 +50,6 @@
 #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_PROCFS) && \
     !defined(CONFIG_FS_PROCFS_EXCLUDE_NET)
 
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Type Definitions
  ****************************************************************************/
@@ -214,7 +210,7 @@ static int netprocfs_open(FAR struct file *filep, FAR const 
char *relpath,
 
   /* For each net entries */
 
-  for (i = 0; i < ARRAY_SIZE(g_net_entries); i++)
+  for (i = 0; i < nitems(g_net_entries); i++)
     {
       if (strncmp(relpath + 4, g_net_entries[i].name,
                   strlen(g_net_entries[i].name)))
@@ -230,7 +226,7 @@ static int netprocfs_open(FAR struct file *filep, FAR const 
char *relpath,
       break;
     }
 
-  if (i == ARRAY_SIZE(g_net_entries) - 1)
+  if (i == nitems(g_net_entries) - 1)
     {
       FAR char *devname;
       FAR char *copy;
@@ -395,7 +391,7 @@ static int netprocfs_opendir(FAR const char *relpath,
 
   if (strlen(relpath) > 4)
     {
-      for (i = 0; i < ARRAY_SIZE(g_net_entries); i++)
+      for (i = 0; i < nitems(g_net_entries); i++)
         {
           if (strncmp(relpath + 4, g_net_entries[i].name,
                       strlen(g_net_entries[i].name)))
@@ -439,7 +435,7 @@ static int netprocfs_opendir(FAR const char *relpath,
 
       /* Add other enabled net components, except netdev */
 
-      level1->base.nentries += ARRAY_SIZE(g_net_entries) - 1;
+      level1->base.nentries += nitems(g_net_entries) - 1;
     }
   else
     {
@@ -517,7 +513,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
 
       /* Process other enabled net components, except netdev */
 
-      if (index < ARRAY_SIZE(g_net_entries) - 1)
+      if (index < nitems(g_net_entries) - 1)
         {
           entry->d_type = g_net_entries[index].type;
           strlcpy(entry->d_name,
@@ -558,7 +554,7 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir,
            * entry of last g_net_entries(-1) and start the devidx from 1)
            */
 
-          ifindex = index + 2 - ARRAY_SIZE(g_net_entries);
+          ifindex = index + 2 - nitems(g_net_entries);
 #endif
           /* Find the device corresponding to this device index */
 
@@ -637,7 +633,7 @@ static int netprocfs_stat(FAR const char *relpath, FAR 
struct stat *buf)
     }
   else
     {
-      for (i = 0; i < ARRAY_SIZE(g_net_entries); i++)
+      for (i = 0; i < nitems(g_net_entries); i++)
         {
           if (strcmp(relpath + 4, g_net_entries[i].name) == 0)
             {
diff --git a/net/usrsock/usrsock_accept.c b/net/usrsock/usrsock_accept.c
index da3c372eea..5e84a62aac 100644
--- a/net/usrsock/usrsock_accept.c
+++ b/net/usrsock/usrsock_accept.c
@@ -161,7 +161,7 @@ static int do_accept_request(FAR struct usrsock_conn_s 
*conn,
   bufs[0].iov_base = &req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
@@ -385,7 +385,7 @@ int usrsock_accept(FAR struct socket *psock, FAR struct 
sockaddr *addr,
       inbufs[1].iov_base = &newconn->usockid;
       inbufs[1].iov_len = sizeof(newconn->usockid);
 
-      usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
+      usrsock_setup_datain(conn, inbufs, nitems(inbufs));
 
       /* We might start getting events for this socket right after
        * returning to daemon, so setup 'newconn' already here.
diff --git a/net/usrsock/usrsock_bind.c b/net/usrsock/usrsock_bind.c
index 05dd73da68..0d2fa3cf68 100644
--- a/net/usrsock/usrsock_bind.c
+++ b/net/usrsock/usrsock_bind.c
@@ -110,7 +110,7 @@ static int do_bind_request(FAR struct usrsock_conn_s *conn,
   bufs[1].iov_base = (FAR void *)addr;
   bufs[1].iov_len = req.addrlen;
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_close.c b/net/usrsock/usrsock_close.c
index 1c2f11e1b4..4a388d5cef 100644
--- a/net/usrsock/usrsock_close.c
+++ b/net/usrsock/usrsock_close.c
@@ -106,7 +106,7 @@ static int do_close_request(FAR struct usrsock_conn_s *conn)
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_connect.c b/net/usrsock/usrsock_connect.c
index 76bee98e46..3f4ec85525 100644
--- a/net/usrsock/usrsock_connect.c
+++ b/net/usrsock/usrsock_connect.c
@@ -112,7 +112,7 @@ static int do_connect_request(FAR struct usrsock_conn_s 
*conn,
   bufs[1].iov_base = (FAR void *)addr;
   bufs[1].iov_len = addrlen;
 
-  ret = usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  ret = usrsock_do_request(conn, bufs, nitems(bufs));
   if (ret == -ENETDOWN)
     {
       ret = -ECONNABORTED;
diff --git a/net/usrsock/usrsock_getpeername.c 
b/net/usrsock/usrsock_getpeername.c
index 9058aa1d8a..b2d3d7b945 100644
--- a/net/usrsock/usrsock_getpeername.c
+++ b/net/usrsock/usrsock_getpeername.c
@@ -123,7 +123,7 @@ static int do_getpeername_request(FAR struct usrsock_conn_s 
*conn,
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
@@ -193,7 +193,7 @@ int usrsock_getpeername(FAR struct socket *psock,
   inbufs[0].iov_base = (FAR void *)addr;
   inbufs[0].iov_len = *addrlen;
 
-  usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
+  usrsock_setup_datain(conn, inbufs, nitems(inbufs));
 
   /* Request user-space daemon to close socket. */
 
diff --git a/net/usrsock/usrsock_getsockname.c 
b/net/usrsock/usrsock_getsockname.c
index e4de81989b..63e80db4e0 100644
--- a/net/usrsock/usrsock_getsockname.c
+++ b/net/usrsock/usrsock_getsockname.c
@@ -123,7 +123,7 @@ static int do_getsockname_request(FAR struct usrsock_conn_s 
*conn,
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
@@ -193,7 +193,7 @@ int usrsock_getsockname(FAR struct socket *psock,
   inbufs[0].iov_base = (FAR void *)addr;
   inbufs[0].iov_len = *addrlen;
 
-  usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
+  usrsock_setup_datain(conn, inbufs, nitems(inbufs));
 
   /* Request user-space daemon to handle request. */
 
diff --git a/net/usrsock/usrsock_getsockopt.c b/net/usrsock/usrsock_getsockopt.c
index 352baacace..69222f05be 100644
--- a/net/usrsock/usrsock_getsockopt.c
+++ b/net/usrsock/usrsock_getsockopt.c
@@ -134,7 +134,7 @@ static int do_getsockopt_request(FAR struct usrsock_conn_s 
*conn, int level,
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
@@ -216,7 +216,7 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, 
int option,
   inbufs[0].iov_base = (FAR void *)value;
   inbufs[0].iov_len = *value_len;
 
-  usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
+  usrsock_setup_datain(conn, inbufs, nitems(inbufs));
 
   /* Request user-space daemon to handle request. */
 
diff --git a/net/usrsock/usrsock_ioctl.c b/net/usrsock/usrsock_ioctl.c
index f3c6ad5851..4d9e264562 100644
--- a/net/usrsock/usrsock_ioctl.c
+++ b/net/usrsock/usrsock_ioctl.c
@@ -139,7 +139,7 @@ static int do_ioctl_request(FAR struct usrsock_conn_s 
*conn, int cmd,
     }
 #endif
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
@@ -227,7 +227,7 @@ int usrsock_ioctl(FAR struct socket *psock, int cmd, 
unsigned long arg_)
     }
 #endif
 
-  usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
+  usrsock_setup_datain(conn, inbufs, nitems(inbufs));
 
   /* Request user-space daemon to handle ioctl. */
 
diff --git a/net/usrsock/usrsock_listen.c b/net/usrsock/usrsock_listen.c
index 3887a8831f..7b0318151e 100644
--- a/net/usrsock/usrsock_listen.c
+++ b/net/usrsock/usrsock_listen.c
@@ -106,7 +106,7 @@ static int do_listen_request(FAR struct usrsock_conn_s 
*conn, int backlog)
   bufs[0].iov_base = &req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_recvmsg.c b/net/usrsock/usrsock_recvmsg.c
index 1d5499e35b..f072bc7ef7 100644
--- a/net/usrsock/usrsock_recvmsg.c
+++ b/net/usrsock/usrsock_recvmsg.c
@@ -175,7 +175,7 @@ static int do_recvfrom_request(FAR struct usrsock_conn_s 
*conn,
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
@@ -385,7 +385,7 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR 
struct msghdr *msg,
       inbufs[1].iov_base = (FAR void *)buf;
       inbufs[1].iov_len = len;
 
-      usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
+      usrsock_setup_datain(conn, inbufs, nitems(inbufs));
 
       /* MSG_DONTWAIT is only use in usrsock. */
 
diff --git a/net/usrsock/usrsock_sendmsg.c b/net/usrsock/usrsock_sendmsg.c
index 7dd9176c46..48fb8545f9 100644
--- a/net/usrsock/usrsock_sendmsg.c
+++ b/net/usrsock/usrsock_sendmsg.c
@@ -172,7 +172,7 @@ static int do_sendto_request(FAR struct usrsock_conn_s 
*conn,
 
   memcpy(&bufs[2], msg->msg_iov, sizeof(struct iovec) * msg->msg_iovlen);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_setsockopt.c b/net/usrsock/usrsock_setsockopt.c
index 61e1128859..6b5accdb07 100644
--- a/net/usrsock/usrsock_setsockopt.c
+++ b/net/usrsock/usrsock_setsockopt.c
@@ -128,7 +128,7 @@ static int do_setsockopt_request(FAR struct usrsock_conn_s 
*conn,
   bufs[1].iov_base = (FAR void *)value;
   bufs[1].iov_len = req.valuelen;
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_shutdown.c b/net/usrsock/usrsock_shutdown.c
index 94feb3b3e0..1d8762a816 100644
--- a/net/usrsock/usrsock_shutdown.c
+++ b/net/usrsock/usrsock_shutdown.c
@@ -106,7 +106,7 @@ static int do_shutdown_request(FAR struct usrsock_conn_s 
*conn, int how)
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/usrsock/usrsock_socket.c b/net/usrsock/usrsock_socket.c
index 362315158a..313e7971aa 100644
--- a/net/usrsock/usrsock_socket.c
+++ b/net/usrsock/usrsock_socket.c
@@ -137,7 +137,7 @@ static int do_socket_request(FAR struct usrsock_conn_s 
*conn, int domain,
   bufs[0].iov_base = (FAR void *)&req;
   bufs[0].iov_len = sizeof(req);
 
-  return usrsock_do_request(conn, bufs, ARRAY_SIZE(bufs));
+  return usrsock_do_request(conn, bufs, nitems(bufs));
 }
 
 /****************************************************************************
diff --git a/net/utils/net_snoop.c b/net/utils/net_snoop.c
index 6e1541c0a4..82b84d8c27 100644
--- a/net/utils/net_snoop.c
+++ b/net/utils/net_snoop.c
@@ -29,16 +29,14 @@
 #include <sys/time.h>
 #include <string.h>
 
+#include <sys/param.h>
+
 #include <nuttx/net/snoop.h>
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef ARRAY_SIZE
-#  define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 #define SNOOP_VERSION_1 1
 #define SNOOP_VERSION_2 2
 
@@ -336,7 +334,7 @@ int snoop_open(FAR struct snoop_s *snoop, FAR const char 
*filename,
               's', 'n', 'o', 'o', 'p', '\0', '\0', '\0'
             };
 
-          memcpy(header.magic, snoop_magic, ARRAY_SIZE(snoop_magic));
+          memcpy(header.magic, snoop_magic, nitems(snoop_magic));
           header.version = htobe32(SNOOP_VERSION_2);
           break;
         };
@@ -351,7 +349,7 @@ int snoop_open(FAR struct snoop_s *snoop, FAR const char 
*filename,
               'b', 't', 's', 'n', 'o', 'o', 'p', '\0'
             };
 
-          memcpy(header.magic, btsnoop_magic, ARRAY_SIZE(btsnoop_magic));
+          memcpy(header.magic, btsnoop_magic, nitems(btsnoop_magic));
           header.version = htobe32(SNOOP_VERSION_1);
           break;
         }
diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c
index 55b1d78000..24b2fffbdd 100644
--- a/wireless/bluetooth/bt_hcicore.c
+++ b/wireless/bluetooth/bt_hcicore.c
@@ -50,6 +50,8 @@
 #include <errno.h>
 #include <debug.h>
 
+#include <sys/param.h>
+
 #include <nuttx/clock.h>
 #include <nuttx/kthread.h>
 #include <nuttx/spinlock.h>
@@ -69,8 +71,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 /* Wait up to 2.5 seconds for a response.  This delay is arbitrary and
  * intended only to avoid hangs while waiting for a response.  It may need
  * to be adjusted.
@@ -2139,7 +2139,7 @@ FAR const char *bt_addr_str(FAR const bt_addr_t *addr)
   FAR char *str;
 
   str  = bufs[cur++];
-  cur %= ARRAY_SIZE(bufs);
+  cur %= nitems(bufs);
   bt_addr_to_str(addr, str, sizeof(bufs[cur]));
 
   return str;
@@ -2152,7 +2152,7 @@ FAR const char *bt_addr_le_str(FAR const bt_addr_le_t 
*addr)
   FAR char *str;
 
   str  = bufs[cur++];
-  cur %= ARRAY_SIZE(bufs);
+  cur %= nitems(bufs);
   bt_addr_le_to_str(addr, str, sizeof(bufs[cur]));
 
   return str;
diff --git a/wireless/bluetooth/bt_smp.c b/wireless/bluetooth/bt_smp.c
index 8bade5e1e6..f3977bdf25 100644
--- a/wireless/bluetooth/bt_smp.c
+++ b/wireless/bluetooth/bt_smp.c
@@ -44,6 +44,8 @@
 #include <errno.h>
 #include <string.h>
 
+#include <sys/param.h>
+
 #include <nuttx/wireless/bluetooth/bt_hci.h>
 #include <nuttx/wireless/bluetooth/bt_core.h>
 
@@ -61,8 +63,6 @@
 #define RECV_KEYS (BT_SMP_DIST_ID_KEY | BT_SMP_DIST_ENC_KEY)
 #define SEND_KEYS (BT_SMP_DIST_ENC_KEY)
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 /****************************************************************************
  * Private Types
  ****************************************************************************/
@@ -326,7 +326,7 @@ static const char *h(FAR const void *buf, size_t len)
   int i;
 
   str     = hexbufs[curbuf++];
-  curbuf %= ARRAY_SIZE(hexbufs);
+  curbuf %= nitems(hexbufs);
 
   maxlen  = (sizeof(hexbufs[0]) - 1) / 2;
   if (len > maxlen)

Reply via email to