Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2877870pxa; Mon, 17 Aug 2020 23:43:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzypQLBn18+FblWXDncztDVpi9unkyp41yjdz9hmyFBkfs5h1hxUZJEY8oGpvDls/y2jE4Y X-Received: by 2002:aa7:d58b:: with SMTP id r11mr17861593edq.302.1597733005528; Mon, 17 Aug 2020 23:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597733005; cv=none; d=google.com; s=arc-20160816; b=vVBLSsjEz1dr9h3hbdKK/AeaRgBV6UxkPNpDMUek8hdptIW1K7Q9jkNBr3ASLZbJ6y 9gPyplyDyEbV++K1yR6Y3lWrcIUShbKFmwn4U1aiMfaos35dmuSCkGwbGE+8+/JC9hnJ x+JeFIBL6utlzJRDqextY0TLHPUcnppj8Wyo8cahbFkAzFlKXzPoqKbF8QgEaqU1+tE2 fDv5nCV5damrbN0DwVxePgLLaM/OiAd8uYQCoWwf8ITgGRHG9AgGrPRLJ28rMilLlpoh h5SfSZbxRdEdvLFC/65t3OHZqpNkfA1UvEn/oz000D9LCmdAHsDAJn8knF9mhYnPb7On V7EA== 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=775qzk5G3HfBeCtXoCDJAjllre8IaZ3OdmJ8ASXAorY=; b=LyGAml/XTXwCTVGq+brRU0RrApGQCJmCEoYXPrRKZ3aGqvJ1oxWKesbkvnDa+INPCj 8XVsMhoFvy2e3DRK/o0AkxW7FB/bh/f/eeOWx6ngMExMgNnWVom5mAimUdXpYkS5XjzD G0kYvcoMW0XIwufTX7iiviknamv1eZDFjd2OJe6JrKBl4szY1APnpjazDiO+a/zPF2ap xBNbC3GMDC9s7DB69Mtc58kU1o1TK1Nwc5BBlX9EWA83vv5guQmTKGI1PP5Twsw+eTbE Z9wIvgQLnXzT2q1MJuazQwYT0zbdWTdCkq34wXd0UNjC4Crp+DJFl+SmVwf71KrxmFXI tmOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=Gm8Wbu1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ionos.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si13050299ejm.314.2020.08.17.23.43.01; Mon, 17 Aug 2020 23:43:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=Gm8Wbu1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ionos.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726628AbgHRGmV (ORCPT + 99 others); Tue, 18 Aug 2020 02:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbgHRGmU (ORCPT ); Tue, 18 Aug 2020 02:42:20 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34300C061342 for ; Mon, 17 Aug 2020 23:42:20 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id bo3so20681650ejb.11 for ; Mon, 17 Aug 2020 23:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=775qzk5G3HfBeCtXoCDJAjllre8IaZ3OdmJ8ASXAorY=; b=Gm8Wbu1x1AJcq/l7haOdWUzinyv1kkATVYdGzJWyJQcZjzKNYg1Ceoc7QamWOiRX91 j/0Sna8XVp4tdn3iu0VN64uLGFwDrkD3QyXv9eZ+cvhtwJGdHLnG5sP27MCf6vnanRrq 5gnGGadcbWftINqgeB95FzjqX5kuYAs7PEACIhPN/F/J2f4kgkikmv5cyozGJsszhohH 9O1W9tcIdbx9BGbUE2adtJU/UP1+pYh5KX3jEF0vfHx9kmvKlFX3DvRXlbKtEJmKdNj5 x2iWTQveL9Vd8HlmozC5wtt3jHEijtH03aRcL2YumKTKbtJMjHfCk1hUFhrsB1zer9ns QmTg== 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=775qzk5G3HfBeCtXoCDJAjllre8IaZ3OdmJ8ASXAorY=; b=kaub3n38Uj8SGohQ3AlrnNLwC6M+YQFVIxkJVtaflUc4+lScIEcovN9Ci5tk9naiG9 I2Y8ayOm7riUWkuFvVU54a0jVVfEaqo/5qRcADBeNEaTigzsU6+gDmnBPGNkPAMBq3oY xOWsw97sidCndUowekDHgLo3wy4OEQlg2Jjpc43sVGVl1W96m0OsFQa/oc/UFB0/hpD0 6vT6He8fNnmCZ0+J5C7QDQDUP4NQt1FBqjNWM523r4s36gjT48TXHkPAwwZMFEx8uT4/ JhO7uADpw3F4cQ0q3ZUdtrJNAe2SFd7QznyUSanMYmbDLD+INNnobiVmkddaZozEEwvZ PoEw== X-Gm-Message-State: AOAM533QjUf5/30hZ4O6hbVVdOttekOvtFQHEv7bbmN1aTxVtmbqAQjL lSh/Iwm1gqNVuWftoM+bBFe1tfsWoTWP3ZNdAkHd/w== X-Received: by 2002:a17:906:9399:: with SMTP id l25mr18532375ejx.212.1597732938235; Mon, 17 Aug 2020 23:42:18 -0700 (PDT) MIME-Version: 1.0 References: <20200818040317.5926-1-brookebasile@gmail.com> <20200818052957.GA2253299@ubuntu-n2-xlarge-x86> In-Reply-To: <20200818052957.GA2253299@ubuntu-n2-xlarge-x86> From: Jinpu Wang Date: Tue, 18 Aug 2020 08:42:06 +0200 Message-ID: Subject: Re: [PATCH] block: rnbd: rnbd-srv: silence uninitialized variable warning To: Nathan Chancellor Cc: Brooke Basile , Danil Kipnis , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com 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, Aug 18, 2020 at 7:30 AM Nathan Chancellor wrote: > > On Tue, Aug 18, 2020 at 12:03:18AM -0400, Brooke Basile wrote: > > Clang warns: > > drivers/block/rnbd/rnbd-srv.c:150:6: warning: variable 'err' is used > > uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > if (IS_ERR(bio)) { > > ^~~~~~~~~~~ > > drivers/block/rnbd/rnbd-srv.c:177:9: note: uninitialized use occurs here > > return err; > > ^~~ > > drivers/block/rnbd/rnbd-srv.c:126:9: note: initialize the variable 'err' > > to silence this warning > > int err; > > ^ > > = 0 > > > > Silence this by replacing `err` with `ret`, returning ret = 0 upon > > success. > > > > Signed-off-by: Brooke Basile > > --- > > drivers/block/rnbd/rnbd-srv.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c > > index 0fb94843a495..f515d1a048a9 100644 > > --- a/drivers/block/rnbd/rnbd-srv.c > > +++ b/drivers/block/rnbd/rnbd-srv.c > > @@ -123,10 +123,10 @@ static int process_rdma(struct rtrs_srv *sess, > > struct rnbd_io_private *priv; > > struct rnbd_srv_sess_dev *sess_dev; > > u32 dev_id; > > - int err; > > struct rnbd_dev_blk_io *io; > > struct bio *bio; > > short prio; > > + int ret = 0; > > > > priv = kmalloc(sizeof(*priv), GFP_KERNEL); > > if (!priv) > > @@ -138,7 +138,7 @@ static int process_rdma(struct rtrs_srv *sess, > > if (IS_ERR(sess_dev)) { > > pr_err_ratelimited("Got I/O request on session %s for unknown device id %d\n", > > srv_sess->sessname, dev_id); > > - err = -ENOTCONN; > > + ret = -ENOTCONN; > > goto err; > > } > > > > @@ -168,13 +168,13 @@ static int process_rdma(struct rtrs_srv *sess, > > > > submit_bio(bio); > > > > - return 0; > > + return ret; > > > > sess_dev_put: > > rnbd_put_sess_dev(sess_dev); > > err: > > kfree(priv); > > - return err; > > + return ret; > > } > > > > static void destroy_device(struct rnbd_srv_dev *dev) > > -- > > 2.28.0 > > > > I don't think this is a proper fix since the root cause of the warning > appears to be that we are ignoring the return value of > rnbd_bio_map_kern. Should we not set err to that value like this > (completely untested)? > > Cheers, > Nathan Thanks Nathan, thanks Brooke, I agree with Nathan, the problem is we forgot to set the err before "goto sess_dev_put". Nathan's patch is simpler, less code of change. > > diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c > index 0fb94843a495..1b71cb2a885d 100644 > --- a/drivers/block/rnbd/rnbd-srv.c > +++ b/drivers/block/rnbd/rnbd-srv.c > @@ -148,7 +148,8 @@ static int process_rdma(struct rtrs_srv *sess, > /* Generate bio with pages pointing to the rdma buffer */ > bio = rnbd_bio_map_kern(data, sess_dev->rnbd_dev->ibd_bio_set, datalen, GFP_KERNEL); > if (IS_ERR(bio)) { > - rnbd_srv_err(sess_dev, "Failed to generate bio, err: %ld\n", PTR_ERR(bio)); > + err = PTR_ERR(bio); > + rnbd_srv_err(sess_dev, "Failed to generate bio, err: %ld\n", err); > goto sess_dev_put; > } > Nathan, could you send a formal patch? Thanks