samples/seccomp: fix array_size.cocci warning

Message ID 2b3f2420.130.184706d34e6.Coremail.wangkailong@jari.cn
State New
Headers
Series samples/seccomp: fix array_size.cocci warning |

Commit Message

KaiLong Wang Nov. 13, 2022, 9:58 a.m. UTC
  Fix following coccicheck warning:

samples/seccomp/bpf-fancy.c:83:39-40: WARNING: Use ARRAY_SIZE
samples/seccomp/bpf-fancy.c:86:44-45: WARNING: Use ARRAY_SIZE

Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
---
 samples/seccomp/bpf-fancy.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

kernel test robot Nov. 13, 2022, 3:52 p.m. UTC | #1
Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.1-rc4 next-20221111]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/wangkailong-jari-cn/samples-seccomp-fix-array_size-cocci-warning/20221113-180424
patch link:    https://lore.kernel.org/r/2b3f2420.130.184706d34e6.Coremail.wangkailong%40jari.cn
patch subject: [PATCH] samples/seccomp: fix array_size.cocci warning
config: i386-allyesconfig
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/ee8a383f3aac9a380696920bd2b5a80c6a92e6e9
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review wangkailong-jari-cn/samples-seccomp-fix-array_size-cocci-warning/20221113-180424
        git checkout ee8a383f3aac9a380696920bd2b5a80c6a92e6e9
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

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

   samples/seccomp/bpf-fancy.c: In function 'main':
>> samples/seccomp/bpf-fancy.c:83:41: warning: implicit declaration of function 'ARRAY_SIZE' [-Wimplicit-function-declaration]
      83 |                 .len = (unsigned short)(ARRAY_SIZE(filter)),
         |                                         ^~~~~~~~~~
--
   /usr/bin/ld: samples/seccomp/bpf-fancy.o: in function `main':
>> bpf-fancy.c:(.text.startup+0x4f2): undefined reference to `ARRAY_SIZE'
>> /usr/bin/ld: bpf-fancy.c:(.text.startup+0x507): undefined reference to `ARRAY_SIZE'
   collect2: error: ld returned 1 exit status
  
Stanislav Fomichev Nov. 14, 2022, 5:15 p.m. UTC | #2
On 11/13, wangkailong@jari.cn wrote:
> Fix following coccicheck warning:

> samples/seccomp/bpf-fancy.c:83:39-40: WARNING: Use ARRAY_SIZE
> samples/seccomp/bpf-fancy.c:86:44-45: WARNING: Use ARRAY_SIZE

Not sure this should go via bpf tree. CC'ed Kees

> Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
> ---
>   samples/seccomp/bpf-fancy.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

> diff --git a/samples/seccomp/bpf-fancy.c b/samples/seccomp/bpf-fancy.c
> index 1ccb435025b6..548f038924d6 100644
> --- a/samples/seccomp/bpf-fancy.c
> +++ b/samples/seccomp/bpf-fancy.c
> @@ -80,10 +80,10 @@ int main(int argc, char **argv)
>   	};
>   	struct sock_fprog prog = {
>   		.filter = filter,
> -		.len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
> +		.len = (unsigned short)(ARRAY_SIZE(filter)),
>   	};
>   	ssize_t bytes;
> -	bpf_resolve_jumps(&l, filter, sizeof(filter)/sizeof(*filter));
> +	bpf_resolve_jumps(&l, filter, ARRAY_SIZE(filter));

>   	if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
>   		perror("prctl(NO_NEW_PRIVS)");
> --
> 2.25.1
  
Kees Cook Nov. 18, 2022, 12:54 a.m. UTC | #3
On Mon, Nov 14, 2022 at 09:15:35AM -0800, sdf@google.com wrote:
> On 11/13, wangkailong@jari.cn wrote:
> > Fix following coccicheck warning:
> 
> > samples/seccomp/bpf-fancy.c:83:39-40: WARNING: Use ARRAY_SIZE
> > samples/seccomp/bpf-fancy.c:86:44-45: WARNING: Use ARRAY_SIZE
> 
> Not sure this should go via bpf tree. CC'ed Kees
> 
> > Signed-off-by: KaiLong Wang <wangkailong@jari.cn>
> > ---
> >   samples/seccomp/bpf-fancy.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> > diff --git a/samples/seccomp/bpf-fancy.c b/samples/seccomp/bpf-fancy.c
> > index 1ccb435025b6..548f038924d6 100644
> > --- a/samples/seccomp/bpf-fancy.c
> > +++ b/samples/seccomp/bpf-fancy.c
> > @@ -80,10 +80,10 @@ int main(int argc, char **argv)
> >   	};
> >   	struct sock_fprog prog = {
> >   		.filter = filter,
> > -		.len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
> > +		.len = (unsigned short)(ARRAY_SIZE(filter)),
> >   	};
> >   	ssize_t bytes;
> > -	bpf_resolve_jumps(&l, filter, sizeof(filter)/sizeof(*filter));
> > +	bpf_resolve_jumps(&l, filter, ARRAY_SIZE(filter));

Hm, this is the "samples" tree, so this was intentionally avoiding these
kinds of kernel-isms, but perhaps that doesn't realistically matter?

-Kees

> 
> >   	if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
> >   		perror("prctl(NO_NEW_PRIVS)");
> > --
> > 2.25.1
  
kernel test robot Nov. 22, 2022, 10:38 a.m. UTC | #4
Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.1-rc6 next-20221121]
[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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/wangkailong-jari-cn/samples-seccomp-fix-array_size-cocci-warning/20221113-180424
patch link:    https://lore.kernel.org/r/2b3f2420.130.184706d34e6.Coremail.wangkailong%40jari.cn
patch subject: [PATCH] samples/seccomp: fix array_size.cocci warning
config: x86_64-allyesconfig
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/ee8a383f3aac9a380696920bd2b5a80c6a92e6e9
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review wangkailong-jari-cn/samples-seccomp-fix-array_size-cocci-warning/20221113-180424
        git checkout ee8a383f3aac9a380696920bd2b5a80c6a92e6e9
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   /usr/bin/ld: samples/seccomp/bpf-fancy.o: in function `main':
   bpf-fancy.c:(.text.startup+0x7a7): undefined reference to `ARRAY_SIZE'
   /usr/bin/ld: bpf-fancy.c:(.text.startup+0x7bb): undefined reference to `ARRAY_SIZE'
>> collect2: error: ld returned 1 exit status
  

Patch

diff --git a/samples/seccomp/bpf-fancy.c b/samples/seccomp/bpf-fancy.c
index 1ccb435025b6..548f038924d6 100644
--- a/samples/seccomp/bpf-fancy.c
+++ b/samples/seccomp/bpf-fancy.c
@@ -80,10 +80,10 @@  int main(int argc, char **argv)
 	};
 	struct sock_fprog prog = {
 		.filter = filter,
-		.len = (unsigned short)(sizeof(filter)/sizeof(filter[0])),
+		.len = (unsigned short)(ARRAY_SIZE(filter)),
 	};
 	ssize_t bytes;
-	bpf_resolve_jumps(&l, filter, sizeof(filter)/sizeof(*filter));
+	bpf_resolve_jumps(&l, filter, ARRAY_SIZE(filter));
 
 	if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) {
 		perror("prctl(NO_NEW_PRIVS)");