Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2846036pxa; Mon, 17 Aug 2020 22:31:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyk/wWftMR92FuIsRRcAE0TU9LKdxFRAF/ePGgyhS4IYd7FlC3GD3//jurEIqJdFCUrsGc X-Received: by 2002:a17:907:100f:: with SMTP id ox15mr18041704ejb.323.1597728665371; Mon, 17 Aug 2020 22:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597728665; cv=none; d=google.com; s=arc-20160816; b=eyrSlb0NnD3YCjs6dkGc1/Zv0eYsZqF4uKL7S5eSOhNfSulrfN8FUzBeChW3tSEye2 XqAIUAUpt0sLXRhhL/+AGHpZ9hwCjE7H95FnwzfS6GlGnzq1dFnBpCPA323TuCkFkK+x vxNhzqb7hwFU1LiIiz4jlMcFulClWsPNhq9LvBMcqXXX/nJ08fikpTk7DEmWA8rzMMU1 hdOywHdXr1YM4r6SqxDN0m2r9hIc650Ig9TjMSxUQaUvkUM+olF2w0z5phewSKnPIEo2 eawBCJ6b2i1J2f5XqYh53SuY+x0lqQC3hYNRhAHuNPkcFAI+l20SXyY3gT33nEkl4C0u nbag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=clmrhtEHnkuE6LcwVqYnlSll443zoXYKCOx0MPBjbtk=; b=AL31TD4ZKGToGQVsOqqEJsh6dHxcih0eL1dGOX4GThrNZb3jH8LnwrUps2U20zHdVa zubvmGPkzbm4GEXYNXRlt/GL3tBBf3+SVO4uDNSqV5g0ZC+xDsuef5JYCJG0OlhHEBRQ 8lFol7dDTrrXsyPnJp/NEqdFGG/ZM6ha9aLbmQjw9CRoQpLd0IaFUnVWYvMfO+7O2N6r veWYwJj7gV0nI/hazth9FdS4VcDjOlEf2n2AjmG3si21GpuAijE1ai4zzlpwSZxHLMJM deBDdT8xp7fs6zxGhf6BUF9Dw1H8AJSF5cG9IllxwMMnKrkQ+fDy7j9tr3jiqOnh/non KrSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FSpO836N; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v19si12495293ejf.83.2020.08.17.22.30.39; Mon, 17 Aug 2020 22:31:05 -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=@gmail.com header.s=20161025 header.b=FSpO836N; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726382AbgHRFaE (ORCPT + 99 others); Tue, 18 Aug 2020 01:30:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726228AbgHRFaB (ORCPT ); Tue, 18 Aug 2020 01:30:01 -0400 Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87110C061389; Mon, 17 Aug 2020 22:30:01 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id f19so9820265qtp.2; Mon, 17 Aug 2020 22:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=clmrhtEHnkuE6LcwVqYnlSll443zoXYKCOx0MPBjbtk=; b=FSpO836Nu0sLIbjI7R0n/GywVAllnHSOgajQheJ4LvlGzRNwCoH3uDem8Jo6zEd4vk eJszO1iJn48dQRINgqIQmPkHV7uVFN6l/+QNGjsnHrJ9s0jeNf/otsuCZ4FHRcJ8+Ebz x61E+o5Xaj2knzR/y3bLubXK/Mg0Avr2H83z6y9OxeSJSON3O676Prq6R/St4ZdtX3Qe Srm7D0uwzC18T7FNWau0Z01qTP6XvY739+/KI/4sbb7Tpe6cqwvKpsoAFtO62qzpR3HJ H+w3Ge0cNXAXg3ci23NfqPqGN3kaub3EocUQj2nFmrxPbbMRZPz+5Leoe3MK3mHdo7Ma JfVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=clmrhtEHnkuE6LcwVqYnlSll443zoXYKCOx0MPBjbtk=; b=lPPOUx7XTufGALZPMwFWxlq82Bl1rwABsGea0pmFgbj136/xUOZPLaxD1LApH4i4Dn 6upV4Jhp5oXnApG/0HjHU+Wk71tjjCQqbzWEf1EcqcuLexwPi1EymtvCwZuc4HWCv9m3 tuOrf9BzOVevkz8XNN+53vP0nf8R2E3k6ip7WDLzVOFQ2u6hOJKG7fbxrwb6mq66OztV dXQKddD9ROxBntuZAHuEh6OZuVWhsck2096Pol0DSG5yaHDqkabSjiJRp4LTLXnkoeQk gvhJQ+cNskiVbhuANspYtmqdXadZ8qIMBNoXtshItPrZ6xk0Q9eqKF6mZsmuMU0klIxf hG3Q== X-Gm-Message-State: AOAM5320QXdOP9XIdbmdscGHKiDL2s7f0Y5JZJyrreCRTzRDcaHx3eXx zIKwPKouZ1gEL/oU3lqshFg= X-Received: by 2002:ac8:1c3:: with SMTP id b3mr16860962qtg.240.1597728599880; Mon, 17 Aug 2020 22:29:59 -0700 (PDT) Received: from ubuntu-n2-xlarge-x86 ([2604:1380:45d1:2600::1]) by smtp.gmail.com with ESMTPSA id o48sm23401139qtf.14.2020.08.17.22.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 22:29:58 -0700 (PDT) Date: Mon, 17 Aug 2020 22:29:57 -0700 From: Nathan Chancellor To: Brooke Basile Cc: danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com, axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] block: rnbd: rnbd-srv: silence uninitialized variable warning Message-ID: <20200818052957.GA2253299@ubuntu-n2-xlarge-x86> References: <20200818040317.5926-1-brookebasile@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200818040317.5926-1-brookebasile@gmail.com> 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 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 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; }