Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2074791pxb; Sun, 10 Jan 2021 23:19:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZvhp3I4y3ZR7dFKZhz/RBqjB/UnrV5cV/OwJ6kXHqRBtC7uS9hoXvAVvtXrL2mO33zTWl X-Received: by 2002:a17:906:a8e:: with SMTP id y14mr9629477ejf.47.1610349598554; Sun, 10 Jan 2021 23:19:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610349598; cv=none; d=google.com; s=arc-20160816; b=OIArFhvj2Zz/nNrAZpEtvssKX+H2vcEFOTsUcUu3j39XtsH5CzliD9Q5ezcBUiPhnH AaJw+EKZ6TBt+wWFaypx6vwUzJisWZO8n7++LM8WfT9HrI+I5mnQuOZ5z+M3e9GYy6Jc 6U8uZ3gj7gm30iahgiB+YBLlLM0FG/AxaBH6kMb7A3ihZYPzXXlaNJGsNP1/eAgg1shS PVD6X0oeKBa8K51VsKgDDh/zmLdOJMQvuNi8w4JJLHCoxaoXyHLYZ5kwwfupOTyE0WfF JGKae20WL8r8Bjk4GdQ+iiG3TJj7Y2lqtb8yaCwGOuaevnkDKqK0osdUidaSwfaxdC/v WBVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+lyh1ppXIwVihU1vaSfQka7MGwNTcAyGaSNwcJGbRT4=; b=IWOIZjbJ8TlhjDiagnlsB1iEDCFUY2KQtYUfSfy8nBgtTTyV5xz7NGMYV6bUGLXDaB nn+e4TvhupUAG4/fYxmqIqbvlTJnCTeRkZbjSCKcNaEfVSS5eFBYH91d/SiV8z9jFgyH P6mRIqf7q5ToGVJmS+KUn4HZvdifF/ed5jW87SQZH54EU5ZvxMcrtdmW1kqPe3duFVU5 Vs2T+J9Ceqtr8mFF4IEVgl2xwdeZUnIlWxJOV7H42QO/Z43u6Q/AbEGMBXAqst0H7m7C A5s8X7kVJDFaH3Knpey7m2U3zadA5Gb8sG0Y34yaVG09xTacd9SzZ+NQLbVie85cb0pr Nmzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloud.ionos.com header.s=google header.b=BQBzzfbH; 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 b7si6600120edy.561.2021.01.10.23.19.35; Sun, 10 Jan 2021 23:19:58 -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=@cloud.ionos.com header.s=google header.b=BQBzzfbH; 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 S1727517AbhAKG57 (ORCPT + 99 others); Mon, 11 Jan 2021 01:57:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbhAKG56 (ORCPT ); Mon, 11 Jan 2021 01:57:58 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 221F7C061786 for ; Sun, 10 Jan 2021 22:57:18 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id d17so23131579ejy.9 for ; Sun, 10 Jan 2021 22:57:18 -0800 (PST) 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=+lyh1ppXIwVihU1vaSfQka7MGwNTcAyGaSNwcJGbRT4=; b=BQBzzfbH/m620+N7MJFkTRbdXbHw1MUrP0quVj3E0xdU1n2clxvwAGEiwraS10+8wv 5YhjkZ3NlYaWjnaKX9eaU0oJjf87JLch1FudPerJMgAB7/qykhrg7meIlOpAS3GcWIv0 FTHEDoNm/NR1NEbXDTo97QP4rm2/9SUSbQ5aEg/Sk44HEVGROyg3gteWKUGXJPuBSTga h1fvzfhtXT3hFNbeCb1DJf7GWqmDCYnxJZknrJn7yfWvsk1Dteqr8oQnR9HkIZlDZQyV ztqmSCP7kNR3rhoRWY2IVpXhkK5UxH2D2x9s9J64edPJWJySO1SKjzVGlxafdTuHJz+z ciqg== 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=+lyh1ppXIwVihU1vaSfQka7MGwNTcAyGaSNwcJGbRT4=; b=b5lOdvIxPD4sUhBUx+lUBy8+cdvIvRFGA2TXgd4ks4iZ9EPzAbQFxTAQVGL5smMCMC be5RBel0U8TJv6fI4pgK/R1/GGchE2x02cYpI+mjNJIktji5CoDRF4J6Nc25P6GsvGAQ kVHGhHeFZGNjrKbZkyN2CPvu3uYaxRT5P8rKKm+Ii9LKrkEA6Q1io3WzXSVba8PKHQdp iOC31lFBJCo6cO8QN5V5W+dhwF2PfOGOOm/lidUv3kz4PmeLDhG/rfxOxFajcOocVy8A ojJX540QvpXEHdY1ISQD2Xch75+wxV1qTtxwuUCfP28734eu0+xe+ashOrp3svCfa7zZ Pt+w== X-Gm-Message-State: AOAM533klUgZNu71VJ6KvPLCMgAylDJynH9WG7Byu+wYwc8Q1qbDF2X9 nRy0Y6TzzwI1DaSIxupDS9MrTLilmbPUT5cF5pk7Bw== X-Received: by 2002:a17:907:4243:: with SMTP id np3mr9714493ejb.212.1610348235838; Sun, 10 Jan 2021 22:57:15 -0800 (PST) MIME-Version: 1.0 References: <20210110215726.861269-1-trix@redhat.com> In-Reply-To: <20210110215726.861269-1-trix@redhat.com> From: Jinpu Wang Date: Mon, 11 Jan 2021 07:57:05 +0100 Message-ID: Subject: Re: [PATCH] block/rnbd-clt: improve find_or_create_sess() return check To: Tom Rix , Nathan Chancellor Cc: Danil Kipnis , Jens Axboe , ndesaulniers@google.com, linux-block , open list , clang-built-linux@googlegroups.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 10, 2021 at 10:58 PM 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) > ^~~~~~ > > 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 Less LOC is better :) Acked-by: Jack Wang Thanks Tom and Nathan! > --- > 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 >