Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2027406pxb; Sun, 10 Jan 2021 21:18:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJx96tCitxLqZ73l9+AfWCKEcH0hOTNxDSOOsA2JmbZ+1zpZm9v4UlDAfDiEXuEiEN0CBiqL X-Received: by 2002:a17:906:90d6:: with SMTP id v22mr9708126ejw.88.1610342337806; Sun, 10 Jan 2021 21:18:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610342337; cv=none; d=google.com; s=arc-20160816; b=xdIrfmCxAgJRKzfQIVjsRkbVoQ+tjBjaCZh0rJBb8VvWlUw9OTe+Ojfgrp1YBcnuDv R/s0n5hgTw7H6oFhvRE3+F9gvjyDVE3YWp/3IUzwNaLntDxVQlpmZikQAfhQmaY/PeST orzJJGZJVa9GAXorZyqfntGc5Jh1RCV9YIiEvXe6B/yMaeh8RSWK7j8zLIwesnPeRr51 oYeIIJC/7Ccpw1X3s8c6dRS7Py2WcPRYDJFpvWkKP9ui/epv0x5fZ2TzusDj7PvJluNy 7hfw7RMfdvYRGSLoh58lnGcHORBa1M2tw99y0L6srL6d9Aa3QHDYn1u0XQ9N+B4meQ84 NB3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Y6lvCdEIpkiMVJxjJGOjKpTSuStrIqmoYLqlHURBnTc=; b=u7QfiBxoV9cp/15isQKX9+UFpb2Zb7s6nRLTxYAMO/4ThXdrFUcAYg88M5QvpDCFzc U5EUyqQsTkzAYyjBjJvQrhPlp1XDLIh6rMevfj7J/vX4CznFHQhJa6QEZRmBg01A1imq SsqP7PJs23XDPVHYsfdczLEXXhMhdlpN1oishRLMi5fy5rnYI0EnziRI/wMlPFdjFRaS nTJqab6aIZdX2+3f4cKlH21CJErU+BFU5F/O4oZdRfaOiTFfJ7Xojlw3Y4pl/r12WFBp ThsKivRKhCjEcPB75WENrMc5Jq+BHOCC2vzjeIHeYgs8kwVVA0t+C4PwHrQOUeyk3EAt la1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=M0q755Sy; 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 cq19si6613584edb.81.2021.01.10.21.18.34; Sun, 10 Jan 2021 21:18:57 -0800 (PST) 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=M0q755Sy; 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 S1726625AbhAKFPQ (ORCPT + 99 others); Mon, 11 Jan 2021 00:15:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbhAKFPP (ORCPT ); Mon, 11 Jan 2021 00:15:15 -0500 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80DF7C061786; Sun, 10 Jan 2021 21:14:35 -0800 (PST) Received: by mail-io1-xd2a.google.com with SMTP id r9so16576986ioo.7; Sun, 10 Jan 2021 21:14:35 -0800 (PST) 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=Y6lvCdEIpkiMVJxjJGOjKpTSuStrIqmoYLqlHURBnTc=; b=M0q755SyxkmvlrYPMO4S+to7rGldxMlOyHWTYnI/Ki2C2xjwemOpxnsRPnCTYtSHyt 2B43OJ28LJ/6PYRF4bkuf1TzEbdA8Y53e75VMQdNcpbi/HfNUXkvZ5qw6kmkumW49wz1 PPrhmmTD+BHnL1TmHEBkc7/gw0bEuurM8wKEf77Tw3uO1WJ40XiftG6hL+YxV8Hp34Kf kiBSRWjpb1n/kcFmB4++HRqaP7it1/Eo81BUMm2VUDG0aFCZ24YTrVOG0xwuPfPVefFm J9xiZmCtuQYAtC7aHBwImwNB+0gHhs/9TY/DVnnNb+EErQocs8q8Z+BafBYyAWW5t8lm mjWg== 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=Y6lvCdEIpkiMVJxjJGOjKpTSuStrIqmoYLqlHURBnTc=; b=l+QMbQLmz9JRVuDytPOkvoZCTKoWbMbylUkvhUCR9H44iStNzLsXFwQDlrbTZpAwi+ Q6692nm/H8UOxX7Cvw3ETD+b2UySjRr6RQTNVMxPqwv+HB3BQOlMpX6hjpSH5xVdTcrW GheLgCLfDvozxXF0O/JI6vSo2yZ43cpgJCKaUOmDTngEnqecT9Cbl75L6SHhYTc6+j5h czjRqILdstjIeBYxhlu7Tm5bfv+87CJqqQxEGskvGzpN+YP+2yS6BUfVJ04zwcKAXzKX rZ6AJALE7eDrNVDn3082CWAj7UK9G5/C/dCxKX3LZWixm3pWkA7/g3OvJk3FcWTrffr/ TzDQ== X-Gm-Message-State: AOAM532jTbUyQLpUOLxBEzQRO8DnqKe3fqpsUbsiNh4CbNy4x5StWh71 S1q3dVFr0WwBEMh+9g2SFotB4CzEQhw= X-Received: by 2002:a5e:a916:: with SMTP id c22mr13188457iod.144.1610342074901; Sun, 10 Jan 2021 21:14:34 -0800 (PST) Received: from ubuntu-m3-large-x86 ([2604:1380:45f1:1d00::1]) by smtp.gmail.com with ESMTPSA id p10sm5318659ilg.68.2021.01.10.21.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jan 2021 21:14:33 -0800 (PST) Date: Sun, 10 Jan 2021 22:14:31 -0700 From: Nathan Chancellor To: trix@redhat.com Cc: danil.kipnis@cloud.ionos.com, jinpu.wang@cloud.ionos.com, axboe@kernel.dk, ndesaulniers@google.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] block/rnbd-clt: improve find_or_create_sess() return check Message-ID: <20210111051431.GA4167786@ubuntu-m3-large-x86> References: <20210110215726.861269-1-trix@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210110215726.861269-1-trix@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 10, 2021 at 01:57:26PM -0800, trix@redhat.com wrote: > From: Tom Rix > > clang static analysis reports this problem > > rnbd-clt.c:1212:11: warning: Branch condition evaluates to a > garbage value > else if (!first) > ^~~~~~ Ah, is it complaining that the 'if (IS_ERR(sess)) {' section in find_or_create_sess() does not initialize first even though that will be caught by the 'if (sess == ERR_PTR(-ENOMEM))' in find_and_get_or_create_sess() because alloc_sess() only returns an -ENOMEM error pointer? > This is triggered in the find_and_get_or_create_sess() call > because the variable first is not initialized and the > earlier check is specifically for > > if (sess == ERR_PTR(-ENOMEM)) > > This is false positive. > > But the if-check can be reduced by initializing first to > false and then returning if the call to find_or_creat_sess() > does not set it to true. When it remains false, either > sess will be valid or not. The not case is caught by > find_and_get_or_create_sess()'s caller rnbd_clt_map_device() > > sess = find_and_get_or_create_sess(...); > if (IS_ERR(sess)) > return ERR_CAST(sess); > > Since find_and_get_or_create_sess() initializes first to false > setting it in find_or_create_sess() is not needed. > > Signed-off-by: Tom Rix Every maintainer has their preference for where and how stuff gets initialized but this makes sense to me. I am not sure the commit above find_or_create_sess() is needed but again, personal preference. Reviewed-by: Nathan Chancellor > --- > drivers/block/rnbd/rnbd-clt.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c > index 96e3f9fe8241..251f747cf10d 100644 > --- a/drivers/block/rnbd/rnbd-clt.c > +++ b/drivers/block/rnbd/rnbd-clt.c > @@ -919,6 +919,7 @@ static struct rnbd_clt_session *__find_and_get_sess(const char *sessname) > return NULL; > } > > +/* caller is responsible for initializing 'first' to false */ > static struct > rnbd_clt_session *find_or_create_sess(const char *sessname, bool *first) > { > @@ -934,8 +935,7 @@ rnbd_clt_session *find_or_create_sess(const char *sessname, bool *first) > } > list_add(&sess->list, &sess_list); > *first = true; > - } else > - *first = false; > + } > mutex_unlock(&sess_lock); > > return sess; > @@ -1203,13 +1203,11 @@ find_and_get_or_create_sess(const char *sessname, > struct rnbd_clt_session *sess; > struct rtrs_attrs attrs; > int err; > - bool first; > + bool first = false; > struct rtrs_clt_ops rtrs_ops; > > sess = find_or_create_sess(sessname, &first); > - if (sess == ERR_PTR(-ENOMEM)) > - return ERR_PTR(-ENOMEM); > - else if (!first) > + if (!first) > return sess; > > if (!path_cnt) { > -- > 2.27.0 >