Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3571242pxp; Tue, 8 Mar 2022 17:45:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoziZCeSkuEDNb8TaTTHAlN70JyXWHB1tpquQtqCQGk/xz6iqH8l8qUEG99Iv0yQlUNOJ2 X-Received: by 2002:a17:90a:8e85:b0:1bc:429b:513d with SMTP id f5-20020a17090a8e8500b001bc429b513dmr7867920pjo.11.1646790333434; Tue, 08 Mar 2022 17:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646790333; cv=none; d=google.com; s=arc-20160816; b=QoHPUOllh/Ff1PVFrqf8Gk315SpWf7QOuUrdijCAqC9eAViizFucSX6AQLKJRoWyMP AuE7tHZ3d482SRz2VvWoD6eF4cLxvJw1AmlXCpm4ZKJcMet0RO1DmjfLx4ZVX1q7gpHs +ZilXhhD3A6C+fxwdmH6qMOmB9Wfu+vTCsa7ZWX8Cm5q2wpdlz2l+UTaJuxryi/bzFlY 4WhiAn9CL/Zq43V5OQ8yiE1AITg025S02nh3lHU/FP0GPFeXxPSl4FsrXPM3ip0Qu+0R /++ikPsu5dx35jv3vrDH+HjFugRiuSAG9kksmM3kMY8LmKnShd6mr5qLSG/8yVY6/cxS oTKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=VWIbRky3HN4Qac7vpBx36JUWr20B8a7p+Sb0qhce1H4=; b=OC8DPtuBR7xs5vB4FiALX77QCxcPwlwFCR8KjSZWYb2WNzp5skZFCOlDScEA5XiH/0 zTrRC3DKdK2hYnRFIFqchNAjl7ku3nq4sv6fP6lk0dZ0aBL63A0K7WwTD1B74EvJYgNt 362w2znJaD6wQrTWW623naxAWSNnaZY+JFC1p8qGlZXAu0HDQarlfDJBm/Y1h2rNy9TQ OMkPj3X+4H1vmFErdYCIUnANLfIzPJr7Y2f+47Qlelchgg4m6w8t7ThONiXTLQorl3Gp ra1yAY1spORrT/jtZ1HZWqj/m7icWHJ57eFQLy318PhofdHdnknAiDLJCSioQ7At2rK4 Y61Q== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e12-20020a656bcc000000b003809d3dac56si549023pgw.844.2022.03.08.17.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:45:33 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6ABE215F603; Tue, 8 Mar 2022 16:23:48 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346069AbiCHPA3 (ORCPT + 99 others); Tue, 8 Mar 2022 10:00:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244592AbiCHPA1 (ORCPT ); Tue, 8 Mar 2022 10:00:27 -0500 Received: from www62.your-server.de (www62.your-server.de [213.133.104.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 121133917F; Tue, 8 Mar 2022 06:59:29 -0800 (PST) Received: from sslproxy01.your-server.de ([78.46.139.224]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1nRbIu-0007PU-Fm; Tue, 08 Mar 2022 15:59:12 +0100 Received: from [85.1.206.226] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nRbIu-000R4h-0o; Tue, 08 Mar 2022 15:59:12 +0100 Subject: Re: [PATCH] selftests/bpf: fix array_size.cocci warning To: Guo Zhengkui , Shuah Khan , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Dave Marchevsky , Yucong Sun , Christy Lee , Delyan Kratunov , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgense?= =?UTF-8?Q?n?= , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:BPF (Safe dynamic programs and tools)" , "open list:BPF (Safe dynamic programs and tools)" , open list Cc: zhengkui_guo@outlook.com References: <20220308091813.28574-1-guozhengkui@vivo.com> From: Daniel Borkmann Message-ID: Date: Tue, 8 Mar 2022 15:59:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20220308091813.28574-1-guozhengkui@vivo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.103.5/26475/Tue Mar 8 10:31:43 2022) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/8/22 10:17 AM, Guo Zhengkui wrote: > Fix the array_size.cocci warning in tools/testing/selftests/bpf/ > > Use `ARRAY_SIZE(arr)` instead of forms like `sizeof(arr)/sizeof(arr[0])`. > > syscall.c and test_rdonly_maps.c don't contain header files which > implement ARRAY_SIZE() macro. So I add `#include `, > in which ARRAY_SIZE(arr) not only calculates the size of `arr`, but also > checks that `arr` is really an array (using __must_be_array(arr)). > > Signed-off-by: Guo Zhengkui [...] > diff --git a/tools/testing/selftests/bpf/progs/syscall.c b/tools/testing/selftests/bpf/progs/syscall.c > index e550f728962d..85c6e7849463 100644 > --- a/tools/testing/selftests/bpf/progs/syscall.c > +++ b/tools/testing/selftests/bpf/progs/syscall.c > @@ -6,6 +6,7 @@ > #include > #include <../../../tools/include/linux/filter.h> > #include > +#include > > char _license[] SEC("license") = "GPL"; > > @@ -82,7 +83,7 @@ int bpf_prog(struct args *ctx) > static __u64 value = 34; > static union bpf_attr prog_load_attr = { > .prog_type = BPF_PROG_TYPE_XDP, > - .insn_cnt = sizeof(insns) / sizeof(insns[0]), > + .insn_cnt = ARRAY_SIZE(insns), > }; > int ret; > > diff --git a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c > index fc8e8a34a3db..ca75aac745a4 100644 > --- a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c > +++ b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c > @@ -3,6 +3,7 @@ > > #include > #include > +#include > #include > > const struct { > @@ -64,7 +65,7 @@ int full_loop(struct pt_regs *ctx) > { > /* prevent compiler to optimize everything out */ > unsigned * volatile p = (void *)&rdonly_values.a; > - int i = sizeof(rdonly_values.a) / sizeof(rdonly_values.a[0]); > + int i = ARRAY_SIZE(rdonly_values.a); > unsigned iters = 0, sum = 0; > There's bpf_util.h with ARRAY_SIZE definition which is used in selftests, pls change to reuse that one. Thanks, Daniel