Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1813732pxy; Sun, 2 May 2021 03:18:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWI9gMa6Vwe66TOHxdljBTHJ6WJ0gVDFSAXt2O/KMB/VQaaeIIKMirVrX/4hjt2cRga/KB X-Received: by 2002:a17:902:eac2:b029:ee:a909:4f9f with SMTP id p2-20020a170902eac2b02900eea9094f9fmr10817415pld.8.1619950722931; Sun, 02 May 2021 03:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619950722; cv=none; d=google.com; s=arc-20160816; b=tbW8NG0DtRqbAAIePWjW9Nktz61AU0D3hWg+2uZ96nWafIlqh4JR9odTPjH4BUrxQn dWJv4VvwJPRniPKMHQYbOWqMTdx+aZnaXw+cH0gJtWAJEaah1iobKdwe/RmSlMoHnthx xmEtyGa9RBtNCnjfcG6LV0QFApEktp34NPIT86Sr4jWD/dD5s+Ks3PGG1/J4vU59rBxn tP7KjvfYqxilh0ZNOlHK+MAmhi5vBVQkoaUpfDE/9cU2yHaruhqhAMtnP8b+Goy7A3TC MiVqiZIR0hZGzM/d8D/K/gKzX8fRHr8TqHOUg9kUgTiQdtQgTFilfjC5twiLOLYbz6a0 tm4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=VwM0UsEh0VHlHyYEeCVKO72rHpBPYxJFsQq3Y9lDdsA=; b=cLUGS2uQz/YgKC/s/vUlbGjvP805Zz4jzO66sssNav01/wI2wvz5MaTrTSOvE0XVeA Lt3sgtltnoHXYuKJdCf8oiJ2Acq7ffb9kaU7lvRB2y90/iGZogprFKM8J2BBHRviROOc zrtibYsRvYmXYxa3acjMsH+6b3sFD/FBmKgS2mbccy8mv5eAUqiaCa1iVbPHsQD5rZg9 oDwqb7+ulob9oOG4haclcoDKIp31OoiI+SLe68LSI/pB9AIRFQXDf0c8x40/kcjIKeEN +2n9gbKshIpwWIp1VbCr8D0hsu+VPKJRxc0XtnhXVV2m6rr8u4YRbDmxDPAbCWF9NbwA RiGQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d20si10847865pgi.311.2021.05.02.03.18.30; Sun, 02 May 2021 03:18:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbhEBKSu (ORCPT + 99 others); Sun, 2 May 2021 06:18:50 -0400 Received: from smtp04.smtpout.orange.fr ([80.12.242.126]:39857 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbhEBKSt (ORCPT ); Sun, 2 May 2021 06:18:49 -0400 Received: from [192.168.1.18] ([86.243.172.93]) by mwinf5d27 with ME id zmHs2400F21Fzsu03mHtWf; Sun, 02 May 2021 12:17:54 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 02 May 2021 12:17:54 +0200 X-ME-IP: 86.243.172.93 Subject: Re: [PATCH] fs/btrfs: Fix uninitialized variable To: Khaled ROMDHANI , clm@fb.com, josef@toxicpanda.com, dsterba@suse.com Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org References: <20210501225046.9138-1-khaledromdhani216@gmail.com> From: Christophe JAILLET Message-ID: Date: Sun, 2 May 2021 12:17:51 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210501225046.9138-1-khaledromdhani216@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 02/05/2021 à 00:50, Khaled ROMDHANI a écrit : > Fix the warning: variable 'zone' is used > uninitialized whenever '?:' condition is true. > > Fix that by preventing the code to reach > the last assertion. If the variable 'mirror' > is invalid, the assertion fails and we return > immediately. > > Reported-by: kernel test robot > Signed-off-by: Khaled ROMDHANI > --- > fs/btrfs/zoned.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c > index 8250ab3f0868..23da9d8dc184 100644 > --- a/fs/btrfs/zoned.c > +++ b/fs/btrfs/zoned.c > @@ -145,7 +145,7 @@ static inline u32 sb_zone_number(int shift, int mirror) > case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; > default: > ASSERT((u32)mirror < 3); > - break; > + return 0; > } > > ASSERT(zone <= U32_MAX); > > base-commit: b5c294aac8a6164ddf38bfbdd1776091b4a1eeba > Hi, just a few comments. If I understand correctly, what you try to do is to silence a compiler warning if no case branch is taken. First, all your proposals are based on the previous one. I find it hard to follow because we don't easily see what are the differences since the beginning. The "base-commit" at the bottom of your mail, is related to your own local tree, I guess. It can't be used by any-one. My understanding it that a patch, should it be v2, v3..., must apply to the current tree. (In my case, it is the latest linux-next) This is not the case here and you have to apply each step to see the final result. Should this version be fine, a maintainer wouldn't be able to apply it as-is. You also try to take into account previous comments to check for incorrect negative values for minor and catch (the can't happen today) cases, should BTRFS_SUPER_MIRROR_MAX change and this function remain the same. So, why hard-coding '3'? The reason of magic numbers are hard to remember. You should avoid them or add a comment about it. My own personal variation would be something like the code below (untested). Hope this helps. CJ diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index 70b23a0d03b1..75fe5f001d8b 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -138,11 +138,14 @@ static inline u32 sb_zone_number(int shift, int mirror) { u64 zone; - ASSERT(mirror < BTRFS_SUPER_MIRROR_MAX); + ASSERT(mirror >= 0 && mirror < BTRFS_SUPER_MIRROR_MAX); switch (mirror) { case 0: zone = 0; break; case 1: zone = 1ULL << (BTRFS_SB_LOG_FIRST_SHIFT - shift); break; case 2: zone = 1ULL << (BTRFS_SB_LOG_SECOND_SHIFT - shift); break; + default: + ASSERT(! "mirror < BTRFS_SUPER_MIRROR_MAX but not handled above."); + return 0; } ASSERT(zone <= U32_MAX);