From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67161171D for ; Sat, 9 Dec 2023 00:21:35 -0800 (PST) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=guanjun@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Vy5DIlH_1702110092; Received: from localhost(mailfrom:guanjun@linux.alibaba.com fp:SMTPD_---0Vy5DIlH_1702110092) by smtp.aliyun-inc.com; Sat, 09 Dec 2023 16:21:33 +0800 From: 'Guanjun' To: wqu@suse.com, dsterba@suse.com, clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH 1/1] btrfs: scrub: Fix use of uninitialized variable Date: Sat, 9 Dec 2023 16:21:32 +0800 Message-Id: <20231209082132.2690130-1-guanjun@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Guanjun 'ret' will be uninitialized in case that the logical_length is 0. Even if the caller has already ensured that logical_length is greater than 0, we still need to fix this issue. Due to the compiler may complain like this: fs/btrfs/scrub.c: In function ‘scrub_simple_mirror.constprop’: fs/btrfs/scrub.c:2123:9: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 2123 | return ret; | ^~~ Fixes: 09022b14fafc (btrfs: scrub: introduce dedicated helper to scrub simple-mirror based range) Signed-off-by: Guanjun --- fs/btrfs/scrub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index a01807cbd4d4..13024131f77d 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2071,7 +2071,7 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx, struct btrfs_fs_info *fs_info = sctx->fs_info; const u64 logical_end = logical_start + logical_length; u64 cur_logical = logical_start; - int ret; + int ret = 0; /* The range must be inside the bg */ ASSERT(logical_start >= bg->start && logical_end <= bg->start + bg->length); -- 2.39.3