Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8432956ybi; Tue, 9 Jul 2019 15:48:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqyo8yR2JuFwlsEWEgj3/vVY2w13WtqzMYE/qPTf9/MUDbY/9DDOrDqJtnGlNgZwkO1CyiCm X-Received: by 2002:a63:4b02:: with SMTP id y2mr22406253pga.135.1562712490241; Tue, 09 Jul 2019 15:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562712490; cv=none; d=google.com; s=arc-20160816; b=Ab4yuGFUiDi/aPyFnP4O0u1+VghJh5hnR/28a0Vk/RIfByZ8Ih5EXcbdDJ9SnhlpMI DaWq2KsM/ID5CdoP1YdZVHxbQW28z9rlZy9BHqb4hfYFY5daMn/W74ZCqYxhPH8saoUY 3c/JSuBIHhJ7qWG/IVIby6t9dEAT1JmUuk5MfzWsyIkeV2MMRnO/vpnely5ACgznecaI son81w8Y7icUlQkKfM0GO2eKlf0G23tJVTV0HZPnTbQKmEdq5xqoKjPX2vXRc4tOvnWV XVIWE0IIPcLamoSpmmefA1KIVxI/mzae8un+Sf1xDa70T6gM/lvLdnSof3tflQI7/Jsi GUsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7lStp7wKHf6Ask7O0Oc+ibRyWBiXzjLJTev2OPu1R8k=; b=zEfvgEVf1RI8uYuEUXmidsEBCYInbM8cM6ZCFgTlFTu4gzov7IH3aCzRX9Jt1HaGLF Bp2GNat/WpAuZ5HHIcqviyoo1MkYbGnRfGRVZKL/wmP+rtTiw59NLDygFyLIUKAKLM1P nYe1JD2alRq8ynXTL1Yfqg9rwZWC3IY86xQAknW427uml0oeKKq8dp2ETVOHsPJGDtfL jhjyc/CLtPQMldb60FMajTAKIEHAKOXHnRwXIfk6gVrWQ6fRRmTJI1NBaZpFE5h5XsJ/ byBJtioPbmuLCjpQBq3d0/ssofyaLRBmo5eI2L0uPPXpJiTZBAgMR7nZXkx33iLeNe5z jsBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TxK8nEyP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a63si218426pge.113.2019.07.09.15.47.55; Tue, 09 Jul 2019 15:48:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TxK8nEyP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbfGIWjK (ORCPT + 99 others); Tue, 9 Jul 2019 18:39:10 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:38219 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726458AbfGIWjK (ORCPT ); Tue, 9 Jul 2019 18:39:10 -0400 Received: by mail-pf1-f195.google.com with SMTP id y15so68239pfn.5 for ; Tue, 09 Jul 2019 15:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7lStp7wKHf6Ask7O0Oc+ibRyWBiXzjLJTev2OPu1R8k=; b=TxK8nEyP+BHCYENCDLzIjf/lr/5HGTOL959SnV2yVYjPi6FK3vVxaRDjiCQKxcqdtG 0qp7kBgnZ8I7VPmnloKcuPkRmLmfG1xRq3WbpCoM7PpWBpb/S8WfUj+S+AM/qoEUykZj PX9TC/sfh3jzPxeLGV7+a3YTZhW4U8iCW7406gtL5tfgz4nU2mzVWq3Lwwjb+mF2XE5m h6aKQmPc2+p6DCUXSb54VrZ8LhqZmnRvy2ikPfWioeDllOvDDjwUKNitNLuZVEkIC6/6 iZntav9Q2GIQHts9q0F07ApQzggmhk82DiQqdT46IzcZcn/qlCrkPficVdKN901fvAep yjSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7lStp7wKHf6Ask7O0Oc+ibRyWBiXzjLJTev2OPu1R8k=; b=QYUMvr2AYseSJIsaR90AcYkvgqU3Kw9a5Fvgh18spNKn58XQndfgsHS0sZq6z/372C N9MWjBmoB0vSMypKTco3qRT9I9xGe/eeMmIWWMz5HzTbbpZiXnyTWbJzrR4JElKbva+v st37/yJBOZzwbCdr/mBYAWvtLNsJxGealuCYhmx9c9VsF5p8I/TK05AWHETXQk2Je4ls IcVJu4wqxVkNTrxQFomVgUr73WH7iuOLy/rXIVqheNOI+GxPZKE+8JXs56OTZYW+CPNL F5ZhZI+R7VuM4iYzpDVJFZTMM7lx3N8vKkMW9JWCj3v+RwftbA4KCnazI3OhhOXpNdwq LiSg== X-Gm-Message-State: APjAAAXuUEjKEa9RHpliPB/7J5VJx8tGw7eyh13Tt4YYnfVBGIWz+lnh RZFleIZHta2WEhQ2Zk58mkPxmPwbOqB/YxUogpP1SQ== X-Received: by 2002:a63:52:: with SMTP id 79mr32862431pga.381.1562711948639; Tue, 09 Jul 2019 15:39:08 -0700 (PDT) MIME-Version: 1.0 References: <20190709221312.7089-1-natechancellor@gmail.com> In-Reply-To: <20190709221312.7089-1-natechancellor@gmail.com> From: Nick Desaulniers Date: Tue, 9 Jul 2019 15:38:57 -0700 Message-ID: Subject: Re: [PATCH] IB/rdmavt: Remove err declaration in if statement in rvt_create_cq To: Nathan Chancellor Cc: Dennis Dalessandro , Mike Marciniszyn , Doug Ledford , Jason Gunthorpe , Kamenee Arumugam , linux-rdma@vger.kernel.org, LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 9, 2019 at 3:13 PM Nathan Chancellor wrote: > > clang warns: > > drivers/infiniband/sw/rdmavt/cq.c:260:7: warning: variable 'err' is used Oh, !$*@, this is a tricky one. While the if scoped `err` declared on L250 is initialized when used at L260, the function scoped `err` declared on L211 is not initialized when it is used on L310 when control flow enters the if on L249 then the goto on L255 or L261. So this is a bug due to the if scoped `err` "shadowing" the function scoped `err`. Maybe not important enough to send a v2, but I feel like the commit message should say something along the lines of `fix a potential use of uninitialized memory due to shadowing`. Either way, this fixes a real bug, so thanks for the patch. Reviewed-by: Nick Desaulniers > uninitialized whenever 'if' condition is true > [-Wsometimes-uninitialized] > if (err) > ^~~ > drivers/infiniband/sw/rdmavt/cq.c:310:9: note: uninitialized use occurs > here > return err; > ^~~ > drivers/infiniband/sw/rdmavt/cq.c:260:3: note: remove the 'if' if its > condition is always false > if (err) > ^~~~~~~~ > drivers/infiniband/sw/rdmavt/cq.c:253:7: warning: variable 'err' is used > uninitialized whenever 'if' condition is true > [-Wsometimes-uninitialized] > if (!cq->ip) { > ^~~~~~~ > drivers/infiniband/sw/rdmavt/cq.c:310:9: note: uninitialized use occurs > here > return err; > ^~~ > drivers/infiniband/sw/rdmavt/cq.c:253:3: note: remove the 'if' if its > condition is always false > if (!cq->ip) { > ^~~~~~~~~~~~~~ > drivers/infiniband/sw/rdmavt/cq.c:211:9: note: initialize the variable > 'err' to silence this warning > int err; > ^ > = 0 > 2 warnings generated. > > There are two err declarations in this function: at the top and within > an if statement; clang warns because the assignments to err in the if > statement are local to the if statement so err will be used > uninitialized if this error handling is used. Remove the if statement's > err declaration so that everything works properly. > > Fixes: 239b0e52d8aa ("IB/hfi1: Move rvt_cq_wc struct into uapi directory") > Link: https://github.com/ClangBuiltLinux/linux/issues/594 > Signed-off-by: Nathan Chancellor > --- > drivers/infiniband/sw/rdmavt/cq.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/drivers/infiniband/sw/rdmavt/cq.c b/drivers/infiniband/sw/rdmavt/cq.c > index fac87b13329d..a85571a4cf57 100644 > --- a/drivers/infiniband/sw/rdmavt/cq.c > +++ b/drivers/infiniband/sw/rdmavt/cq.c > @@ -247,8 +247,6 @@ int rvt_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, > * See rvt_mmap() for details. > */ > if (udata && udata->outlen >= sizeof(__u64)) { > - int err; > - -- Thanks, ~Nick Desaulniers