Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A74E4C43381 for ; Fri, 1 Mar 2019 06:19:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 702A82084F for ; Fri, 1 Mar 2019 06:19:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="Drj374Q6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726817AbfCAGTu (ORCPT ); Fri, 1 Mar 2019 01:19:50 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:59844 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725290AbfCAGTu (ORCPT ); Fri, 1 Mar 2019 01:19:50 -0500 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.27/8.16.0.27) with SMTP id x21622ZW012787 for ; Thu, 28 Feb 2019 22:19:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=facebook; bh=1I7NRcR62b7f4CiHVb46uQwaHKFui//V3+GzCypaiyE=; b=Drj374Q60GmfSzwgLifjmAUMzRUQlmogrlVoiC5X+qoreEASj/lUoP4PDuHrY18lNUI3 Vyht5AwCc8pCv8EmZzORTtldFGrDpZHuXMh6kMSxSqV1+6VNXQY0HUYtqymGVMOtXrpk 6ek4Bad7gtt4jCc7rNd88Py2uN/ZT4heIPc= Received: from maileast.thefacebook.com ([199.201.65.23]) by m0001303.ppops.net with ESMTP id 2qxugu8jry-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 28 Feb 2019 22:19:48 -0800 Received: from mx-out.facebook.com (2620:10d:c0a1:3::13) by mail.thefacebook.com (2620:10d:c021:18::171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Thu, 28 Feb 2019 22:19:47 -0800 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 946DB3702CAB; Thu, 28 Feb 2019 22:19:41 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig003.ftw2.facebook.com To: CC: Alexei Starovoitov , Daniel Borkmann , , Yonghong Song Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c Date: Thu, 28 Feb 2019 22:19:41 -0800 Message-ID: <20190301061941.2555233-1-yhs@fb.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-01_05:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Compiling xdpsock_user.c with 4.8.5, I hit the following compilation warning: HOSTCC samples/bpf/xdpsock_user.o /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c: In function =E2= =80=98main=E2=80=99: /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:449:6: warning= : =E2=80=98idx_cq=E2=80=99 may be used unini tialized in this function [-Wmaybe-uninitialized] u32 idx_cq, idx_fq; ^ /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:606:7: warning= : =E2=80=98idx_rx=E2=80=99 may be used unini tialized in this function [-Wmaybe-uninitialized] u32 idx_rx, idx_tx =3D 0; ^ /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:506:6: warning= : =E2=80=98idx_rx=E2=80=99 may be used unini tialized in this function [-Wmaybe-uninitialized] u32 idx_rx, idx_fq =3D 0; As an example, the code pattern looks like: u32 idx_cq; ... ret =3D xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); if (ret) { ... } ... idx_fq ... The compiler warns since it does not know whether &idx_fq is assigned or not inside the library function xsk_ring_prod__reserve(). Let us assign an initial value 0 to such auto variables to silence compiler warning. Fixes: 248c7f9c0e21 ("samples/bpf: convert xdpsock to use libbpf for AF_X= DP access") Signed-off-by: Yonghong Song --- samples/bpf/xdpsock_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 9c76d6d43deb..d08ee1ab7bb4 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -446,7 +446,7 @@ static void kick_tx(struct xsk_socket_info *xsk) =20 static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk) { - u32 idx_cq, idx_fq; + u32 idx_cq =3D 0, idx_fq =3D 0; unsigned int rcvd; size_t ndescs; =20 @@ -503,7 +503,7 @@ static inline void complete_tx_only(struct xsk_socket= _info *xsk) static void rx_drop(struct xsk_socket_info *xsk) { unsigned int rcvd, i; - u32 idx_rx, idx_fq =3D 0; + u32 idx_rx =3D 0, idx_fq =3D 0; int ret; =20 rcvd =3D xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx); @@ -603,7 +603,7 @@ static void l2fwd(struct xsk_socket_info *xsk) { for (;;) { unsigned int rcvd, i; - u32 idx_rx, idx_tx =3D 0; + u32 idx_rx =3D 0, idx_tx =3D 0; int ret; =20 for (;;) { --=20 2.17.1