2022-11-13 09:54:34

by KaiLong Wang

[permalink] [raw]
Subject: [PATCH] powerpc/xmon: Fix array_size.cocci warning

Fix the following coccicheck warning:

arch/powerpc/xmon/ppc-opc.c:957:67-68: WARNING: Use ARRAY_SIZE
arch/powerpc/xmon/ppc-opc.c:7280:24-25: WARNING: Use ARRAY_SIZE
arch/powerpc/xmon/ppc-opc.c:6972:25-26: WARNING: Use ARRAY_SIZE
arch/powerpc/xmon/ppc-opc.c:7211:21-22: WARNING: Use ARRAY_SIZE

Signed-off-by: KaiLong Wang <[email protected]>
---
arch/powerpc/xmon/ppc-opc.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
index 0774d711453e..ad64c2709757 100644
--- a/arch/powerpc/xmon/ppc-opc.c
+++ b/arch/powerpc/xmon/ppc-opc.c
@@ -954,9 +954,7 @@ const struct powerpc_operand powerpc_operands[] =
{ 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
};

-const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
- / sizeof (powerpc_operands[0]));
-
+const unsigned int num_powerpc_operands = ARRAY_SIZE(powerpc_operands);
/* The functions used to insert and extract complicated operands. */

/* The ARX, ARY, RX and RY operands are alternate encodings of GPRs. */
@@ -6968,8 +6966,7 @@ const struct powerpc_opcode powerpc_opcodes[] = {
{"fcfidu.", XRC(63,974,1), XRA_MASK, POWER7|PPCA2, PPCVLE, {FRT, FRB}},
};

-const int powerpc_num_opcodes =
- sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
+const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes);

/* The VLE opcode table.

@@ -7207,8 +7204,7 @@ const struct powerpc_opcode vle_opcodes[] = {
{"se_bl", BD8(58,0,1), BD8_MASK, PPCVLE, 0, {B8}},
};

-const int vle_num_opcodes =
- sizeof (vle_opcodes) / sizeof (vle_opcodes[0]);
+const int vle_num_opcodes = ARRAY_SIZE(vle_opcodes);

/* The macro table. This is only used by the assembler. */

@@ -7276,5 +7272,4 @@ const struct powerpc_macro powerpc_macros[] = {
{"e_clrlslwi",4, PPCVLE, "e_rlwinm %0,%1,%3,(%2)-(%3),31-(%3)"},
};

-const int powerpc_num_macros =
- sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
+const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);
--
2.25.1


2022-11-14 14:24:12

by Christophe Leroy

[permalink] [raw]
Subject: Re: [PATCH] powerpc/xmon: Fix array_size.cocci warning



Le 13/11/2022 à 10:13, [email protected] a écrit :
> Fix the following coccicheck warning:
>
> arch/powerpc/xmon/ppc-opc.c:957:67-68: WARNING: Use ARRAY_SIZE
> arch/powerpc/xmon/ppc-opc.c:7280:24-25: WARNING: Use ARRAY_SIZE
> arch/powerpc/xmon/ppc-opc.c:6972:25-26: WARNING: Use ARRAY_SIZE
> arch/powerpc/xmon/ppc-opc.c:7211:21-22: WARNING: Use ARRAY_SIZE
>
> Signed-off-by: KaiLong Wang <[email protected]>

This code is copied from Binutils.

This change has been rejected several times already.

See
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/#2006148

Christophe


> ---
> arch/powerpc/xmon/ppc-opc.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/arch/powerpc/xmon/ppc-opc.c b/arch/powerpc/xmon/ppc-opc.c
> index 0774d711453e..ad64c2709757 100644
> --- a/arch/powerpc/xmon/ppc-opc.c
> +++ b/arch/powerpc/xmon/ppc-opc.c
> @@ -954,9 +954,7 @@ const struct powerpc_operand powerpc_operands[] =
> { 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
> };
>
> -const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
> - / sizeof (powerpc_operands[0]));
> -
> +const unsigned int num_powerpc_operands = ARRAY_SIZE(powerpc_operands);
> /* The functions used to insert and extract complicated operands. */
>
> /* The ARX, ARY, RX and RY operands are alternate encodings of GPRs. */
> @@ -6968,8 +6966,7 @@ const struct powerpc_opcode powerpc_opcodes[] = {
> {"fcfidu.", XRC(63,974,1), XRA_MASK, POWER7|PPCA2, PPCVLE, {FRT, FRB}},
> };
>
> -const int powerpc_num_opcodes =
> - sizeof (powerpc_opcodes) / sizeof (powerpc_opcodes[0]);
> +const int powerpc_num_opcodes = ARRAY_SIZE(powerpc_opcodes);
>
> /* The VLE opcode table.
>
> @@ -7207,8 +7204,7 @@ const struct powerpc_opcode vle_opcodes[] = {
> {"se_bl", BD8(58,0,1), BD8_MASK, PPCVLE, 0, {B8}},
> };
>
> -const int vle_num_opcodes =
> - sizeof (vle_opcodes) / sizeof (vle_opcodes[0]);
> +const int vle_num_opcodes = ARRAY_SIZE(vle_opcodes);
>
> /* The macro table. This is only used by the assembler. */
>
> @@ -7276,5 +7272,4 @@ const struct powerpc_macro powerpc_macros[] = {
> {"e_clrlslwi",4, PPCVLE, "e_rlwinm %0,%1,%3,(%2)-(%3),31-(%3)"},
> };
>
> -const int powerpc_num_macros =
> - sizeof (powerpc_macros) / sizeof (powerpc_macros[0]);
> +const int powerpc_num_macros = ARRAY_SIZE(powerpc_macros);