2021-02-20 08:26:31

by Yang Li

[permalink] [raw]
Subject: [PATCH] KVM: s390: use ARRAY_SIZE instead of division operation

This eliminates the following coccicheck warning:
./arch/s390/tools/gen_facilities.c:154:37-38: WARNING: Use ARRAY_SIZE
./arch/s390/tools/gen_opcode_table.c:141:39-40: WARNING: Use ARRAY_SIZE

Reported-by: Abaci Robot <[email protected]>
Signed-off-by: Yang Li <[email protected]>
---
arch/s390/tools/gen_facilities.c | 2 +-
arch/s390/tools/gen_opcode_table.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/s390/tools/gen_facilities.c b/arch/s390/tools/gen_facilities.c
index 61ce5b5..5366817 100644
--- a/arch/s390/tools/gen_facilities.c
+++ b/arch/s390/tools/gen_facilities.c
@@ -151,7 +151,7 @@ static void print_facility_lists(void)
{
unsigned int i;

- for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
+ for (i = 0; i < ARRAY_SIZE(facility_defs); i++)
print_facility_list(&facility_defs[i]);
}

diff --git a/arch/s390/tools/gen_opcode_table.c b/arch/s390/tools/gen_opcode_table.c
index a1bc02b..468b70c 100644
--- a/arch/s390/tools/gen_opcode_table.c
+++ b/arch/s390/tools/gen_opcode_table.c
@@ -138,7 +138,7 @@ static struct insn_type *insn_format_to_type(char *format)
strcpy(tmp, format);
base_format = tmp;
base_format = strsep(&base_format, "_");
- for (i = 0; i < sizeof(insn_type_table) / sizeof(insn_type_table[0]); i++) {
+ for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {
ptr = insn_type_table[i].format;
while (*ptr) {
if (!strcmp(base_format, *ptr))
--
1.8.3.1


2021-02-20 13:59:32

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: use ARRAY_SIZE instead of division operation

Hi Yang,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on s390/features]
[also build test ERROR on v5.11 next-20210219]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Yang-Li/KVM-s390-use-ARRAY_SIZE-instead-of-division-operation/20210220-162731
base: https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git features
config: s390-randconfig-c003-20210220 (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/ce79423dfac31c407de75ffe6d6da451d633f3d3
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Yang-Li/KVM-s390-use-ARRAY_SIZE-instead-of-division-operation/20210220-162731
git checkout ce79423dfac31c407de75ffe6d6da451d633f3d3
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=s390

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All error/warnings (new ones prefixed by >>):

arch/s390/tools/gen_facilities.c: In function 'print_facility_lists':
>> arch/s390/tools/gen_facilities.c:154:18: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(facility_defs); i++)
^~~~~~~~~~
/usr/bin/ld: /tmp/ccZg6NYL.o: in function `main':
>> gen_facilities.c:(.text.startup+0x8a): undefined reference to `ARRAY_SIZE'
collect2: error: ld returned 1 exit status
--
arch/s390/tools/gen_opcode_table.c: In function 'insn_format_to_type':
>> arch/s390/tools/gen_opcode_table.c:141:18: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {
^~~~~~~~~~
/usr/bin/ld: /tmp/ccK5Yn5L.o: in function `main':
>> gen_opcode_table.c:(.text.startup+0xa1): undefined reference to `ARRAY_SIZE'
collect2: error: ld returned 1 exit status
--
arch/s390/tools/gen_opcode_table.c: In function 'insn_format_to_type':
>> arch/s390/tools/gen_opcode_table.c:141:18: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {
^~~~~~~~~~
arch/s390/tools/gen_facilities.c: In function 'print_facility_lists':
>> arch/s390/tools/gen_facilities.c:154:18: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(facility_defs); i++)
^~~~~~~~~~
/usr/bin/ld: /tmp/ccxTOhkE.o: in function `main':
>> gen_facilities.c:(.text.startup+0x8a): undefined reference to `ARRAY_SIZE'
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:95: arch/s390/tools/gen_facilities] Error 1
/usr/bin/ld: /tmp/cchswEND.o: in function `main':
>> gen_opcode_table.c:(.text.startup+0xa1): undefined reference to `ARRAY_SIZE'
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:95: arch/s390/tools/gen_opcode_table] Error 1
make[2]: Target 'kapi' not remade because of errors.
make[1]: *** [arch/s390/Makefile:170: archprepare] Error 2
make[1]: Target 'modules_prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'modules_prepare' not remade because of errors.
--
arch/s390/tools/gen_facilities.c: In function 'print_facility_lists':
>> arch/s390/tools/gen_facilities.c:154:18: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(facility_defs); i++)
^~~~~~~~~~
arch/s390/tools/gen_opcode_table.c: In function 'insn_format_to_type':
>> arch/s390/tools/gen_opcode_table.c:141:18: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {
^~~~~~~~~~
/usr/bin/ld: /tmp/ccMuoSEP.o: in function `main':
>> gen_facilities.c:(.text.startup+0x8a): undefined reference to `ARRAY_SIZE'
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:95: arch/s390/tools/gen_facilities] Error 1
/usr/bin/ld: /tmp/ccQtRcUO.o: in function `main':
>> gen_opcode_table.c:(.text.startup+0xa1): undefined reference to `ARRAY_SIZE'
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:95: arch/s390/tools/gen_opcode_table] Error 1
make[2]: Target 'kapi' not remade because of errors.
make[1]: *** [arch/s390/Makefile:170: archprepare] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (5.29 kB)
.config.gz (26.22 kB)
Download all attachments

2021-02-21 19:10:25

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH] KVM: s390: use ARRAY_SIZE instead of division operation

On Sat, Feb 20, 2021 at 04:22:37PM +0800, Yang Li wrote:
> This eliminates the following coccicheck warning:
> ./arch/s390/tools/gen_facilities.c:154:37-38: WARNING: Use ARRAY_SIZE
> ./arch/s390/tools/gen_opcode_table.c:141:39-40: WARNING: Use ARRAY_SIZE
>
> Reported-by: Abaci Robot <[email protected]>
> Signed-off-by: Yang Li <[email protected]>
> ---
> arch/s390/tools/gen_facilities.c | 2 +-
> arch/s390/tools/gen_opcode_table.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/s390/tools/gen_facilities.c b/arch/s390/tools/gen_facilities.c
> index 61ce5b5..5366817 100644
> --- a/arch/s390/tools/gen_facilities.c
> +++ b/arch/s390/tools/gen_facilities.c
> @@ -151,7 +151,7 @@ static void print_facility_lists(void)
> {
> unsigned int i;
>
> - for (i = 0; i < sizeof(facility_defs) / sizeof(facility_defs[0]); i++)
> + for (i = 0; i < ARRAY_SIZE(facility_defs); i++)
> print_facility_list(&facility_defs[i]);
> }
>
> diff --git a/arch/s390/tools/gen_opcode_table.c b/arch/s390/tools/gen_opcode_table.c
> index a1bc02b..468b70c 100644
> --- a/arch/s390/tools/gen_opcode_table.c
> +++ b/arch/s390/tools/gen_opcode_table.c
> @@ -138,7 +138,7 @@ static struct insn_type *insn_format_to_type(char *format)
> strcpy(tmp, format);
> base_format = tmp;
> base_format = strsep(&base_format, "_");
> - for (i = 0; i < sizeof(insn_type_table) / sizeof(insn_type_table[0]); i++) {
> + for (i = 0; i < ARRAY_SIZE(insn_type_table); i++) {

There is a reason why this doesn't use ARRAY_SIZE()...
Please stop sending trivial patches without even looking at the code.