Skip to content

Commit 3a0fdb0

Browse files
anchaoxiaoxiang781216
authored andcommitted
nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
Signed-off-by: chao an <[email protected]>
1 parent cf0769d commit 3a0fdb0

File tree

95 files changed

+291
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+291
-451
lines changed

arch/arm/include/cxd56xx/crashdump.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#include <stdint.h>
3131

32+
#include <sys/param.h>
33+
3234
#include <nuttx/irq.h>
3335

3436
/****************************************************************************
@@ -54,8 +56,6 @@
5456
#define CONFIG_USTACK_SIZE (CRASHLOG_LEFTOVER / NUMBER_STACKS / \
5557
sizeof(stack_word_t))
5658

57-
#define ARRAYSIZE(a) (sizeof((a))/sizeof(a[0]))
58-
5959
/* For Assert keep this much of the file name */
6060

6161
#define MAX_FILE_PATH_LENGTH 40

arch/arm/src/cxd56xx/cxd56_pinconfig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <nuttx/config.h>
2929

3030
#include <sys/types.h>
31+
#include <sys/param.h>
3132
#include <stdint.h>
3233
#include <stdbool.h>
3334

@@ -119,7 +120,7 @@
119120

120121
#define CXD56_PIN_CONFIGS(pin) do { \
121122
uint32_t p[] = pin; \
122-
cxd56_pin_configs((p), sizeof(p) / sizeof((p)[0])); \
123+
cxd56_pin_configs((p), nitems(p)); \
123124
} while (0)
124125

125126
/****************************************************************************

arch/arm/src/rtl8720c/chip.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
# include <stdint.h>
3030
# include <sys/types.h>
3131
#endif
32+
33+
#include <sys/param.h>
34+
3235
#include <arch/chip/chip.h>
3336

3437
/****************************************************************************
3538
* Pre-processor Definitions
3639
****************************************************************************/
3740

38-
#ifndef ARRAY_SIZE
39-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
40-
#endif
4141
/* If the common ARMv7-M vector handling logic is used,
4242
* then it expects the following
4343
* definition in this file that provides the number of

arch/arm/src/stm32h7/stm32_fmc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
#include <assert.h>
3232
#include <debug.h>
3333

34+
#include <sys/param.h>
35+
3436
#include <nuttx/arch.h>
3537
#include <arch/board/board.h>
3638

37-
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
38-
3939
/****************************************************************************
4040
* To use FMC, you must first enable it in configuration:
4141
*
@@ -265,7 +265,7 @@ void stm32_fmc_init(void)
265265

266266
/* Set up FMC GPIOs */
267267

268-
for (regval = 0; regval < ARRAY_SIZE(fmc_gpios); regval++)
268+
for (regval = 0; regval < nitems(fmc_gpios); regval++)
269269
stm32_configgpio(fmc_gpios[regval]);
270270

271271
/* Set up FMC registers */

arch/arm64/src/a64/a64_boot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static const struct arm_mmu_region mmu_regions[] =
6262

6363
const struct arm_mmu_config mmu_config =
6464
{
65-
.num_regions = ARRAY_SIZE(mmu_regions),
65+
.num_regions = nitems(mmu_regions),
6666
.mmu_regions = mmu_regions,
6767
};
6868

arch/arm64/src/common/arm64_arch.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@
145145

146146
#define STRINGIFY(x) #x
147147

148-
#ifndef ARRAY_SIZE
149-
# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
150-
#endif
151-
152148
#define GET_EL(mode) (((mode) >> MODE_EL_SHIFT) & MODE_EL_MASK)
153149

154150
/* MPIDR_EL1, Multiprocessor Affinity Register */

arch/arm64/src/common/arm64_mmu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ static const struct arm_mmu_region mmu_nxrt_regions[] =
186186

187187
static const struct arm_mmu_config mmu_nxrt_config =
188188
{
189-
.num_regions = ARRAY_SIZE(mmu_nxrt_regions),
189+
.num_regions = nitems(mmu_nxrt_regions),
190190
.mmu_regions = mmu_nxrt_regions,
191191
};
192192

arch/arm64/src/qemu/qemu_boot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static const struct arm_mmu_region mmu_regions[] =
6262

6363
const struct arm_mmu_config mmu_config =
6464
{
65-
.num_regions = ARRAY_SIZE(mmu_regions),
65+
.num_regions = nitems(mmu_regions),
6666
.mmu_regions = mmu_regions,
6767
};
6868

arch/sim/src/sim/posix/sim_hostusrsock.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/uio.h>
2727
#include <sys/socket.h>
2828
#include <sys/ioctl.h>
29+
#include <sys/param.h>
2930

3031
#include <stdbool.h>
3132
#include <stdio.h>
@@ -39,12 +40,6 @@
3940

4041
#include "sim_hostusrsock.h"
4142

42-
/****************************************************************************
43-
* Pre-processor Definitions
44-
****************************************************************************/
45-
46-
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
47-
4843
/****************************************************************************
4944
* Private Data
5045
****************************************************************************/

binfmt/libelf/libelf_coredump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <nuttx/config.h>
2626

2727
#include <sys/stat.h>
28+
#include <sys/param.h>
2829

2930
#include <stdio.h>
3031
#include <stdint.h>
@@ -44,7 +45,6 @@
4445

4546
#define ELF_PAGESIZE 4096
4647

47-
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
4848
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
4949

5050
/****************************************************************************
@@ -244,7 +244,7 @@ static void elf_emit_note_info(FAR struct elf_dumpinfo_s *cinfo)
244244

245245
status.pr_pid = tcb->pid;
246246

247-
for (j = 0; j < ARRAY_SIZE(status.pr_regs); j++)
247+
for (j = 0; j < nitems(status.pr_regs); j++)
248248
{
249249
status.pr_regs[j] = *(uintptr_t *)((uint8_t *)tcb +
250250
g_tcbinfo.reg_off.p[j]);

0 commit comments

Comments
 (0)