Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp762957pxp; Fri, 11 Mar 2022 14:28:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJx94oCs20TOPTvqVmwjFYJR7pQmYnXL/wKuPBFO3Z0ckG5qLNFVe2JXni5ItSZvv+OZUMYL X-Received: by 2002:a63:d158:0:b0:374:d6b4:991c with SMTP id c24-20020a63d158000000b00374d6b4991cmr10174827pgj.581.1647037707438; Fri, 11 Mar 2022 14:28:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647037707; cv=none; d=google.com; s=arc-20160816; b=BMPf4ET11b63pB9kO9zbhaGVO14W1wd/qNGeGZwW/0rtHkVZ7fyCJoe/JungWDMaWS vI6uQiyvu20hSc3jtL0cMF8i8UoG0lea+mZbDjgp9AWrmZifDWBDd4X3CUD+NS7OTXoQ gwvxsLu6dEkRUyGJS7ZpEd0aPrzWbJ0BwXyLaD1G2gN0p23k+48wve09IvSfmprhu0sd 5A8FmxDEJ8k+PEogsQdDP50a74hGGeiJ8+TvUzm74TpLaLj9zRcT4MiN1of83sctCF50 HCHT9Bw4rMbwt6JOyEofYG/sIV1KxCEBM8cW1wkoOzUfy1MaL+6PatPFIO3aM98mL8D2 cMtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WFI9p5E2R1wq2NWvgYHqRIb+Zo5MSuZDRoBWnSp8cC0=; b=KwwxxXT4ZjiD6V9aQ+YmcdxSNo8bd4Z5LIou5hZKJ2RsjN4n25kzrYaoaIPj1ceLQe nh6MOkRaAR8HCEwq/1zqY20vpmH1usiqlS0GkA2iaagXOGVmARMnc4eBgGntizLij6Mi jFlZu+jzh8DwRXk9CmUDGWwla54wNr637i3znV6+JEaY4VydjU6tJ5BqKCYoLY2p5Dfm m+NiA7GH9YU2/VVe/YNt9UdiFqFhyBfbRr1t8t0ked91Xgo6LgEtwTdHm3yta31So/W1 HflGUdx9sPiK1EjhlHfSwIXkPtLzyX2Su2/kQxZlRqVOI8I38nza6Pfhh+N/sCaMwWLm Aqrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Hz3qF2Jc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y21-20020a1709029b9500b0014ae66b576fsi9020507plp.250.2022.03.11.14.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:28:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Hz3qF2Jc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D43CD191A22; Fri, 11 Mar 2022 13:36:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350955AbiCKSjt (ORCPT + 99 others); Fri, 11 Mar 2022 13:39:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240230AbiCKSjs (ORCPT ); Fri, 11 Mar 2022 13:39:48 -0500 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F05C45F8EB; Fri, 11 Mar 2022 10:38:42 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id b16so11146388ioz.3; Fri, 11 Mar 2022 10:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WFI9p5E2R1wq2NWvgYHqRIb+Zo5MSuZDRoBWnSp8cC0=; b=Hz3qF2Jc/oDqlPTyODeX6aJQMsymr4mAoQa/4iAsl+s+AcF7H76WTBaUcvqqHezecW Caq83ucTlRONEvHL6A75juWpGkNRjv+7NosLvVgx1Nl2iORThEFQxIN7kKR9QEvz60WL ogrT0hc9l+uc2i7OIhyA/mZqv2G9Ztpk9n/ru+8TXm8uFCkk58VYqlVaeNRh0DVdX0ep 79Gg+qviEwPZHp3ezLtIZSDB+6qicFDbmpHraRxEprWl8R9pCxayyL8Z8ie67DYsxMjh O16+Gi5uMiQc5BGr2z06DFg60HsziOkdOvgXL582mcqkh4XZ2o2IWgKYB/4uD5nOInfC 5Z7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WFI9p5E2R1wq2NWvgYHqRIb+Zo5MSuZDRoBWnSp8cC0=; b=rDjWE3tbitOA6MIH8sjY6329LnnEjGqoyDz6neGHZ9AxUHeT80/uKlIf+bjhBhohp7 0UwFalgu6cQMzq8f02WgMGtIXr3WSVY8PkCwaWMJ3J5iY7iWPFuWPuYGGOW8uUghdjq7 GUZRlumQ0ZM+XvyLiZO5PVPZ6n/aBB2dByt9Bi4car6qMfEgLAco5covyW+vzup6MoTY oc1B0eaYSRKq/CgoSozpVCwnLfAyA/L1JNWWybBgoW8aeJXymJrzQXilFYng2YjKO5mk v6b8mo7IWjn725VXIo+rTOVn3rIreQ58azHqzXUWqUveRsEY/oxLqd+WyykKuTI35yXw ZerA== X-Gm-Message-State: AOAM532S/mLYJWgWRr4UViaUCWMvf2Y3u8DZANRYWY30wwJFr9OtBuiW 5g7Ug0C00TlZUwGXOh/iTyf3Xs92uwlzJ+ovfrs= X-Received: by 2002:a02:c00e:0:b0:317:c548:97c with SMTP id y14-20020a02c00e000000b00317c548097cmr9696778jai.234.1647023922364; Fri, 11 Mar 2022 10:38:42 -0800 (PST) MIME-Version: 1.0 References: <20220309033518.1743-1-guozhengkui@vivo.com> In-Reply-To: <20220309033518.1743-1-guozhengkui@vivo.com> From: Andrii Nakryiko Date: Fri, 11 Mar 2022 10:38:31 -0800 Message-ID: Subject: Re: [PATCH v2] selftests/bpf: fix array_size.cocci warning To: Guo Zhengkui Cc: Shuah Khan , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Yucong Sun , Dave Marchevsky , Christy Lee , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Delyan Kratunov , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:BPF (Safe dynamic programs and tools)" , "open list:BPF (Safe dynamic programs and tools)" , open list , zhengkui_guo@outlook.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 Tue, Mar 8, 2022 at 7:36 PM Guo Zhengkui wrote: > > Fix the array_size.cocci warning in tools/testing/selftests/bpf/ > > Use `ARRAY_SIZE(arr)` in bpf_util.h instead of forms like > `sizeof(arr)/sizeof(arr[0])`. > > Signed-off-by: Guo Zhengkui > --- > .../selftests/bpf/prog_tests/cgroup_attach_autodetach.c | 2 +- > .../testing/selftests/bpf/prog_tests/cgroup_attach_multi.c | 2 +- > .../selftests/bpf/prog_tests/cgroup_attach_override.c | 2 +- > tools/testing/selftests/bpf/prog_tests/global_data.c | 6 +++--- > tools/testing/selftests/bpf/prog_tests/obj_name.c | 2 +- > tools/testing/selftests/bpf/progs/syscall.c | 3 ++- > tools/testing/selftests/bpf/progs/test_rdonly_maps.c | 3 ++- > tools/testing/selftests/bpf/test_cgroup_storage.c | 2 +- > tools/testing/selftests/bpf/test_lru_map.c | 4 ++-- > tools/testing/selftests/bpf/test_sock_addr.c | 6 +++--- > tools/testing/selftests/bpf/test_sockmap.c | 4 ++-- > 11 files changed, 19 insertions(+), 17 deletions(-) > [...] > diff --git a/tools/testing/selftests/bpf/progs/test_rdonly_maps.c b/tools/testing/selftests/bpf/progs/test_rdonly_maps.c > index fc8e8a34a3db..a500f2c15970 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 bpf_util.h isn't supposed to be included from BPF source code side. Is this ARRAY_SIZE() use so important for BPF programs? Maybe just leave existing code under progs/*.c as is? > #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; > > /* validate verifier can allow full loop as well */ [...]