From patchwork Fri Jan 27 05:41:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13118168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 458A3C54EAA for ; Fri, 27 Jan 2023 05:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbjA0Flp (ORCPT ); Fri, 27 Jan 2023 00:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjA0Flm (ORCPT ); Fri, 27 Jan 2023 00:41:42 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 340EE73768 for ; Thu, 26 Jan 2023 21:41:39 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C2C5E21C4F for ; Fri, 27 Jan 2023 05:41:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674798097; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CBGUgPq/VXnm7K9YDvLRdAUvJHyDk96V34+sbzGSpw4=; b=XoPlu/izNTQqANr3fGS0q1dIOhAc+Tqdi07WUwkF79X3FSo9XfAiLIkLzloKBHSYhVVwHH YBrxud8sKwD9suFJF5TpVdjSorqUwNu+wrwWgcMXtuvAWlzrTE2ZA22Tg+xDyCaMB94zfp PxtnSffLViDcm/QEcQPZRUyu7bGlDa8= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 24391134F5 for ; Fri, 27 Jan 2023 05:41:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2M7VNxBk02OnLwAAMHmgww (envelope-from ) for ; Fri, 27 Jan 2023 05:41:36 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/5] btrfs-progs: remove an unnecessary branch to silent the clang warning Date: Fri, 27 Jan 2023 13:41:14 +0800 Message-Id: <0268c78594151742044d27b6e1dce877c63ef5fb.1674797823.git.wqu@suse.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org [FALSE ALERT] With clang 15.0.7, there is a false alert on uninitialized value in ctree.c: kernel-shared/ctree.c:3418:13: warning: variable 'offset' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] } else if (ret < 0) { ^~~~~~~ kernel-shared/ctree.c:3428:41: note: uninitialized use occurs here write_extent_buffer(eb, &subvol_id_le, offset, sizeof(subvol_id_le)); ^~~~~~ kernel-shared/ctree.c:3418:9: note: remove the 'if' if its condition is always true } else if (ret < 0) { ^~~~~~~~~~~~~ kernel-shared/ctree.c:3380:22: note: initialize the variable 'offset' to silence this warning unsigned long offset; ^ = 0 kernel-shared/ctree.c:3418:13: warning: variable 'eb' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] } else if (ret < 0) { ^~~~~~~ kernel-shared/ctree.c:3429:26: note: uninitialized use occurs here btrfs_mark_buffer_dirty(eb); ^~ kernel-shared/ctree.c:3418:9: note: remove the 'if' if its condition is always true } else if (ret < 0) { ^~~~~~~~~~~~~ kernel-shared/ctree.c:3378:26: note: initialize the variable 'eb' to silence this warning struct extent_buffer *eb; ^ = NULL [CAUSE] The original code is handling the return value from btrfs_insert_empty_item() like this: ret = btrfs_insert_empty_item(); if (ret >= 0) { /* Do something for it. */ } else if (ret == -EEXIST) { /* Do something else. */ } else if (ret < 0) { /* Error handling. */ } But the problem is, the last one check is always true if we can reach there. Thus clang is providing the hint to remove the if () chekc. [FIX] Normally we prefer to do error handling first, so move the error handling first so we don't need the if () else if () chain. Signed-off-by: Qu Wenruo --- kernel-shared/ctree.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index 9f8bc9a5904c..759ee47aaadd 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -3400,14 +3400,22 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, ret = btrfs_insert_empty_item(trans, uuid_root, path, &key, sizeof(subvol_id_le)); + if (ret < 0 && ret != -EEXIST) { + warning( + "inserting uuid item failed (0x%016llx, 0x%016llx) type %u: %d", + (unsigned long long)key.objectid, + (unsigned long long)key.offset, type, ret); + goto out; + } + if (ret >= 0) { /* Add an item for the type for the first time */ eb = path->nodes[0]; slot = path->slots[0]; offset = btrfs_item_ptr_offset(eb, slot); - } else if (ret == -EEXIST) { + } else { /* - * An item with that type already exists. + * ret == -EEXIST case, An item with that type already exists. * Extend the item and store the new subvol_id at the end. */ btrfs_extend_item(uuid_root, path, sizeof(subvol_id_le)); @@ -3415,12 +3423,6 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, slot = path->slots[0]; offset = btrfs_item_ptr_offset(eb, slot); offset += btrfs_item_size(eb, slot) - sizeof(subvol_id_le); - } else if (ret < 0) { - warning( - "inserting uuid item failed (0x%016llx, 0x%016llx) type %u: %d", - (unsigned long long)key.objectid, - (unsigned long long)key.offset, type, ret); - goto out; } ret = 0; From patchwork Fri Jan 27 05:41:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13118169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5910C61DA3 for ; Fri, 27 Jan 2023 05:41:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbjA0Flp (ORCPT ); Fri, 27 Jan 2023 00:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbjA0Fln (ORCPT ); Fri, 27 Jan 2023 00:41:43 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55408721CF for ; Thu, 26 Jan 2023 21:41:41 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D0F4C21C70 for ; Fri, 27 Jan 2023 05:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674798098; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDZCWWpgULB40YxDEqg/vOhKoope109BO1h4pWEGtUM=; b=UxALgJwpwFI4Be+OBYpRx7MxlJjbMctXs6HgmKWF/ejY2LrnaCQ0QAe8DtC+HgMPRdi1ej TsYmBngc6M4ukwraVXfhqoPJpRFseHrVWStX2aKHAhh7CB8bluDHMf2lohTEH9oMQtsOj6 r+mjvlgJKZ/mgyQxsFETy2aVNFd5qwg= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 30D83134F5 for ; Fri, 27 Jan 2023 05:41:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EIjwOhFk02OnLwAAMHmgww (envelope-from ) for ; Fri, 27 Jan 2023 05:41:37 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/5] btrfs-progs: fix a false alert on an uninitialized variable when BUG_ON() is involved. Date: Fri, 27 Jan 2023 13:41:15 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org [FALSE ALERT] Clang 15.0.7 gives the following false alert in get_dev_extent_len(): kernel-shared/extent-tree.c:3328:2: warning: variable 'div' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized] default: ^~~~~~~ kernel-shared/extent-tree.c:3332:24: note: uninitialized use occurs here return map->ce.size / div; ^~~ kernel-shared/extent-tree.c:3311:9: note: initialize the variable 'div' to silence this warning int div; ^ = 0 And one in btrfs_stripe_length() too: kernel-shared/volumes.c:2781:2: warning: variable 'stripe_len' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized] default: ^~~~~~~ kernel-shared/volumes.c:2785:9: note: uninitialized use occurs here return stripe_len; ^~~~~~~~~~ kernel-shared/volumes.c:2754:16: note: initialize the variable 'stripe_len' to silence this warning u64 stripe_len; ^ = 0 [CAUSE] Clang doesn't really understand what BUG_ON() means, thus in that default case, we won't get uninitialized value but crash directly. [FIX] Silent the errors by assigning the default value properly using the value of SINGLE profile. Signed-off-by: Qu Wenruo --- kernel-shared/extent-tree.c | 4 ++-- kernel-shared/volumes.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index 0b0c40afe9a9..4c6ad64f5ba8 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -3308,7 +3308,7 @@ out: static u64 get_dev_extent_len(struct map_lookup *map) { - int div; + int div = 1; switch (map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) { case 0: /* Single */ @@ -3316,7 +3316,7 @@ static u64 get_dev_extent_len(struct map_lookup *map) case BTRFS_BLOCK_GROUP_RAID1: case BTRFS_BLOCK_GROUP_RAID1C3: case BTRFS_BLOCK_GROUP_RAID1C4: - div = 1; + /* The default value can already handle it. */ break; case BTRFS_BLOCK_GROUP_RAID5: case BTRFS_BLOCK_GROUP_RAID6: diff --git a/kernel-shared/volumes.c b/kernel-shared/volumes.c index 65147d064934..1e2c88955719 100644 --- a/kernel-shared/volumes.c +++ b/kernel-shared/volumes.c @@ -2758,6 +2758,7 @@ u64 btrfs_stripe_length(struct btrfs_fs_info *fs_info, BTRFS_BLOCK_GROUP_PROFILE_MASK; chunk_len = btrfs_chunk_length(leaf, chunk); + stripe_len = chunk_len; switch (profile) { case 0: /* Single profile */ @@ -2765,7 +2766,7 @@ u64 btrfs_stripe_length(struct btrfs_fs_info *fs_info, case BTRFS_BLOCK_GROUP_RAID1C3: case BTRFS_BLOCK_GROUP_RAID1C4: case BTRFS_BLOCK_GROUP_DUP: - stripe_len = chunk_len; + /* The default value is already fine. */ break; case BTRFS_BLOCK_GROUP_RAID0: stripe_len = chunk_len / num_stripes; From patchwork Fri Jan 27 05:41:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13118171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1A6CC38142 for ; Fri, 27 Jan 2023 05:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229908AbjA0Flr (ORCPT ); Fri, 27 Jan 2023 00:41:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbjA0Flo (ORCPT ); Fri, 27 Jan 2023 00:41:44 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5526570D54 for ; Thu, 26 Jan 2023 21:41:41 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DEE9121C87 for ; Fri, 27 Jan 2023 05:41:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674798099; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4BtTcAzT3Bx1Aey+gPaJ3QfhiAdPXlz0K9FmIsvMCLo=; b=WnaZGIz3nbzhIVZ1tSOGU5/qKstxxWXzF1/ONQXgDyS6b5dnvZ19/7v7Jp3cHupNiC717o wZOaZoL6/S86Pfe+6f7JBoDsWcK8BYBLM1kocgcxbCSu8JfNU1OCuwx7UZfnq0BVEhC2Tm MIUfcemmYAqlNM7Wvj6QYCPWsfV9bB4= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3E462134F5 for ; Fri, 27 Jan 2023 05:41:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YHGaAhNk02OnLwAAMHmgww (envelope-from ) for ; Fri, 27 Jan 2023 05:41:39 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/5] btrfs-progs: fix fallthrough cases with proper attributes Date: Fri, 27 Jan 2023 13:41:16 +0800 Message-Id: <56794e8e6e0717c5fc981cfb3a96e4b1b5180818.1674797823.git.wqu@suse.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org [FALSE ALERT] Unlike gcc, clang doesn't really understand the comments, thus it's reportings tons of fall through related errors: cmds/reflink.c:124:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] case 'r': ^ cmds/reflink.c:124:3: note: insert '__attribute__((fallthrough));' to silence this warning case 'r': ^ __attribute__((fallthrough)); cmds/reflink.c:124:3: note: insert 'break;' to avoid fall-through case 'r': ^ break; [CAUSE] Although gcc is fine with /* fallthrough */ comments, clang is not. [FIX] So just introduce a fallthrough macro to handle the situation properly, and use that macro instead. Signed-off-by: Qu Wenruo --- cmds/reflink.c | 2 +- cmds/scrub.c | 10 +++--- common/format-output.c | 2 +- common/parse-utils.c | 12 +++---- common/units.c | 6 ++-- crypto/xxhash.c | 73 +++++++++++++++++++------------------- image/main.c | 2 +- kerncompat.h | 8 +++++ kernel-shared/print-tree.c | 2 +- 9 files changed, 63 insertions(+), 54 deletions(-) diff --git a/cmds/reflink.c b/cmds/reflink.c index 5ed9a12770e2..53f4784838c1 100644 --- a/cmds/reflink.c +++ b/cmds/reflink.c @@ -120,7 +120,7 @@ static int cmd_reflink_clone(const struct cmd_struct *cmd, int argc, char **argv switch (c) { case 's': same_file = true; - /* fallthrough */ + fallthrough; case 'r': range = malloc(sizeof(struct reflink_range)); if (!range) { diff --git a/cmds/scrub.c b/cmds/scrub.c index e6513b39f2bf..782a1310816b 100644 --- a/cmds/scrub.c +++ b/cmds/scrub.c @@ -602,7 +602,7 @@ again: memset(p[curr], 0, sizeof(**p)); p[curr + 1] = NULL; ++state; - /* fall through */ + fallthrough; case 2: /* start of line, skip space */ while (isspace(l[i]) && i < avail) { if (l[i] == '\n') @@ -613,7 +613,7 @@ again: (!eof && !memchr(l + i, '\n', avail - i))) goto again; ++state; - /* fall through */ + fallthrough; case 3: /* read fsid */ if (i == avail) continue; @@ -629,7 +629,7 @@ again: _SCRUB_INVALID; i += j + 1; ++state; - /* fall through */ + fallthrough; case 4: /* read dev id */ for (j = 0; isdigit(l[i + j]) && i+j < avail; ++j) ; @@ -638,7 +638,7 @@ again: p[curr]->devid = atoll(&l[i]); i += j + 1; ++state; - /* fall through */ + fallthrough; case 5: /* read key/value pair */ ret = 0; _SCRUB_KVREAD(ret, &i, data_extents_scrubbed, avail, l, @@ -682,7 +682,7 @@ again: if (ret != 1) _SCRUB_INVALID; ++state; - /* fall through */ + fallthrough; case 6: /* after number */ if (l[i] == '|') state = 5; diff --git a/common/format-output.c b/common/format-output.c index c7e021b58f2c..18993ad66636 100644 --- a/common/format-output.c +++ b/common/format-output.c @@ -74,7 +74,7 @@ static void print_escaped(const char *str) case '"': case '\\': putchar('\\'); - /* fallthrough */ + fallthrough; default: putchar(*str); } diff --git a/common/parse-utils.c b/common/parse-utils.c index f16b7aac1b3b..bb3c2bbf366a 100644 --- a/common/parse-utils.c +++ b/common/parse-utils.c @@ -184,22 +184,22 @@ u64 parse_size_from_string(const char *s) switch (c) { case 'e': mult *= 1024; - /* fallthrough */ + fallthrough; case 'p': mult *= 1024; - /* fallthrough */ + fallthrough; case 't': mult *= 1024; - /* fallthrough */ + fallthrough; case 'g': mult *= 1024; - /* fallthrough */ + fallthrough; case 'm': mult *= 1024; - /* fallthrough */ + fallthrough; case 'k': mult *= 1024; - /* fallthrough */ + fallthrough; case 'b': break; default: diff --git a/common/units.c b/common/units.c index 698dc1d0508e..8d708cddc03e 100644 --- a/common/units.c +++ b/common/units.c @@ -89,15 +89,15 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_size, unsigned unit_mod case UNITS_TBYTES: base *= mult; num_divs++; - /* fallthrough */ + fallthrough; case UNITS_GBYTES: base *= mult; num_divs++; - /* fallthrough */ + fallthrough; case UNITS_MBYTES: base *= mult; num_divs++; - /* fallthrough */ + fallthrough; case UNITS_KBYTES: num_divs++; break; diff --git a/crypto/xxhash.c b/crypto/xxhash.c index c2f1be9f7449..7f7f3f74328c 100644 --- a/crypto/xxhash.c +++ b/crypto/xxhash.c @@ -116,6 +116,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp #define XXH_STATIC_LINKING_ONLY #include "xxhash.h" +#include "kerncompat.h" /* ************************************* * Compiler Specific Options @@ -397,41 +398,41 @@ XXH32_finalize(U32 h32, const void* ptr, size_t len, XXH_alignment align) } else { switch(len&15) /* or switch(bEnd - p) */ { case 12: PROCESS4; - /* fallthrough */ + fallthrough; case 8: PROCESS4; - /* fallthrough */ + fallthrough; case 4: PROCESS4; return XXH32_avalanche(h32); case 13: PROCESS4; - /* fallthrough */ + fallthrough; case 9: PROCESS4; - /* fallthrough */ + fallthrough; case 5: PROCESS4; PROCESS1; return XXH32_avalanche(h32); case 14: PROCESS4; - /* fallthrough */ + fallthrough; case 10: PROCESS4; - /* fallthrough */ + fallthrough; case 6: PROCESS4; PROCESS1; PROCESS1; return XXH32_avalanche(h32); case 15: PROCESS4; - /* fallthrough */ + fallthrough; case 11: PROCESS4; - /* fallthrough */ + fallthrough; case 7: PROCESS4; - /* fallthrough */ + fallthrough; case 3: PROCESS1; - /* fallthrough */ + fallthrough; case 2: PROCESS1; - /* fallthrough */ + fallthrough; case 1: PROCESS1; - /* fallthrough */ + fallthrough; case 0: return XXH32_avalanche(h32); } XXH_ASSERT(0); @@ -825,63 +826,63 @@ XXH64_finalize(U64 h64, const void* ptr, size_t len, XXH_alignment align) } else { switch(len & 31) { case 24: PROCESS8_64; - /* fallthrough */ + fallthrough; case 16: PROCESS8_64; - /* fallthrough */ + fallthrough; case 8: PROCESS8_64; return XXH64_avalanche(h64); case 28: PROCESS8_64; - /* fallthrough */ + fallthrough; case 20: PROCESS8_64; - /* fallthrough */ + fallthrough; case 12: PROCESS8_64; - /* fallthrough */ + fallthrough; case 4: PROCESS4_64; return XXH64_avalanche(h64); case 25: PROCESS8_64; - /* fallthrough */ + fallthrough; case 17: PROCESS8_64; - /* fallthrough */ + fallthrough; case 9: PROCESS8_64; PROCESS1_64; return XXH64_avalanche(h64); case 29: PROCESS8_64; - /* fallthrough */ + fallthrough; case 21: PROCESS8_64; - /* fallthrough */ + fallthrough; case 13: PROCESS8_64; - /* fallthrough */ + fallthrough; case 5: PROCESS4_64; PROCESS1_64; return XXH64_avalanche(h64); case 26: PROCESS8_64; - /* fallthrough */ + fallthrough; case 18: PROCESS8_64; - /* fallthrough */ + fallthrough; case 10: PROCESS8_64; PROCESS1_64; PROCESS1_64; return XXH64_avalanche(h64); case 30: PROCESS8_64; - /* fallthrough */ + fallthrough; case 22: PROCESS8_64; - /* fallthrough */ + fallthrough; case 14: PROCESS8_64; - /* fallthrough */ + fallthrough; case 6: PROCESS4_64; PROCESS1_64; PROCESS1_64; return XXH64_avalanche(h64); case 27: PROCESS8_64; - /* fallthrough */ + fallthrough; case 19: PROCESS8_64; - /* fallthrough */ + fallthrough; case 11: PROCESS8_64; PROCESS1_64; PROCESS1_64; @@ -889,19 +890,19 @@ XXH64_finalize(U64 h64, const void* ptr, size_t len, XXH_alignment align) return XXH64_avalanche(h64); case 31: PROCESS8_64; - /* fallthrough */ + fallthrough; case 23: PROCESS8_64; - /* fallthrough */ + fallthrough; case 15: PROCESS8_64; - /* fallthrough */ + fallthrough; case 7: PROCESS4_64; - /* fallthrough */ + fallthrough; case 3: PROCESS1_64; - /* fallthrough */ + fallthrough; case 2: PROCESS1_64; - /* fallthrough */ + fallthrough; case 1: PROCESS1_64; - /* fallthrough */ + fallthrough; case 0: return XXH64_avalanche(h64); } } diff --git a/image/main.c b/image/main.c index 8900297ebe1a..ecf464e5b0a2 100644 --- a/image/main.c +++ b/image/main.c @@ -1431,7 +1431,7 @@ static int restore_one_work(struct mdrestore_struct *mdres, switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; - __attribute__ ((fallthrough)); + fallthrough; case Z_DATA_ERROR: case Z_MEM_ERROR: goto out; diff --git a/kerncompat.h b/kerncompat.h index 6fb79ac88351..74383ed9ff6c 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -227,6 +227,14 @@ static inline int mutex_is_locked(struct mutex *m) #define __attribute_const__ __attribute__((__const__)) #endif +/* To silent compilers like clang which doesn't understand comments. */ + +#if __has_attribute(__fallthrough__) +# define fallthrough __attribute__((__fallthrough__)) +#else +# define fallthrough do {} while (0) /* fallthrough */ +#endif + /** * __set_bit - Set a bit in memory * @nr: the bit to set diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index ba1caa88fcf1..534166283997 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -796,7 +796,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type) fprintf(stream, "FIRST_CHUNK_TREE"); break; } - /* fall-thru */ + fallthrough; default: fprintf(stream, "%llu", (unsigned long long)objectid); } From patchwork Fri Jan 27 05:41:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13118170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C9BAC61DA7 for ; Fri, 27 Jan 2023 05:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbjA0Flq (ORCPT ); Fri, 27 Jan 2023 00:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230015AbjA0Flo (ORCPT ); Fri, 27 Jan 2023 00:41:44 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36623721D1 for ; Thu, 26 Jan 2023 21:41:42 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id ED3D21FF5F for ; Fri, 27 Jan 2023 05:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674798100; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CpIZgtGzaQZ5PCJtGuXbLfblmSGTOwDexI9nsq3zou4=; b=tlhz1UMX3shsrMkjL/12P4k7oDrVnmGXp8xSwLGdbxJB32DN9xbVM39OpANkV0JXNBY/si Z6x7eXQPjd7bOw7J3eKD7jMeZshPwEl74befHaTPicfLwzRjG3TgJaaKGEJ8KtfRDIDxs0 hSMhcgju5VU5U5mSjqbwVfOKu6G3a9Y= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4CBF0134F5 for ; Fri, 27 Jan 2023 05:41:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id YKUmBhRk02OnLwAAMHmgww (envelope-from ) for ; Fri, 27 Jan 2023 05:41:40 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/5] btrfs-progs: move a union with variable sized type to the end Date: Fri, 27 Jan 2023 13:41:17 +0800 Message-Id: <34378b3e8906ca7e24f981caf7296087767510ac.1674797823.git.wqu@suse.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org [WARNING] Clang 15.0.7 gives the following warning: image/main.c:95:2: warning: field '' with variable sized type 'union metadump_struct::(anonymous at image/main.c:95:2)' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end] union { ^ [CAUSE] The union contains meta_cluster, which variable sized: struct meta_cluster { struct meta_cluster_header header; struct meta_cluster_item items[]; } __attribute__ ((__packed__)); Thus clang gives above warning since it's a GNU extension. [FIX] Just move the union to the end of the structure. Signed-off-by: Qu Wenruo --- image/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/image/main.c b/image/main.c index ecf464e5b0a2..d4a1fe349d31 100644 --- a/image/main.c +++ b/image/main.c @@ -92,11 +92,6 @@ struct metadump_struct { struct btrfs_root *root; FILE *out; - union { - struct meta_cluster cluster; - char meta_cluster_bytes[IMAGE_BLOCK_SIZE]; - }; - pthread_t threads[MAX_WORKER_THREADS]; size_t num_threads; pthread_mutex_t mutex; @@ -119,6 +114,11 @@ struct metadump_struct { enum sanitize_mode sanitize_names; int error; + + union { + struct meta_cluster cluster; + char meta_cluster_bytes[IMAGE_BLOCK_SIZE]; + }; }; struct mdrestore_struct { From patchwork Fri Jan 27 05:41:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13118172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 699B2C61DB3 for ; Fri, 27 Jan 2023 05:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229469AbjA0Fls (ORCPT ); Fri, 27 Jan 2023 00:41:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbjA0Flp (ORCPT ); Fri, 27 Jan 2023 00:41:45 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449EB721FB for ; Thu, 26 Jan 2023 21:41:43 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 064C31FF5E for ; Fri, 27 Jan 2023 05:41:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674798102; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k5U7X7WmI96snEVUO0HsUsDvrq3hPR2AJiRrcOAGhUY=; b=lkhEhVktCorQzh/c8txVJa4JvsZKZIM2dgkIS9BWoSlgxiWdcKsY12OfEwL9NjWyvp70Sv vPXQJQyJakMpC2L1nUfMyrqcouiy/yAhadwKMu+TeR1rdxSV7Fwvu3ksGzNvDj3WkdBBYw 6Jxr7KTsXjTf9IkBUyDk5qusoMM3Ies= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 5B246134F5 for ; Fri, 27 Jan 2023 05:41:41 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id uFSjCRVk02OnLwAAMHmgww (envelope-from ) for ; Fri, 27 Jan 2023 05:41:41 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/5] btrfs-progs: fix set but not used variables Date: Fri, 27 Jan 2023 13:41:18 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org [WARNING] Clang 15.0.7 warns about several unused variables: kernel-shared/zoned.c:829:6: warning: variable 'num_sequential' set but not used [-Wunused-but-set-variable] u32 num_sequential = 0, num_conventional = 0; ^ cmds/scrub.c:1174:6: warning: variable 'n_skip' set but not used [-Wunused-but-set-variable] int n_skip = 0; ^ mkfs/main.c:493:6: warning: variable 'total_block_count' set but not used [-Wunused-but-set-variable] u64 total_block_count = 0; ^ image/main.c:2246:6: warning: variable 'bytenr' set but not used [-Wunused-but-set-variable] u64 bytenr = 0; ^ [CAUSE] Most of them just straightforward set but not used variables. The only exception is total_block_count, which has commented out code relying on it. [FIX] Just remove those variables, and for @total_block_count, also remove the comments. Signed-off-by: Qu Wenruo --- cmds/scrub.c | 2 -- image/main.c | 3 --- kernel-shared/zoned.c | 6 ++---- mkfs/main.c | 4 ---- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/cmds/scrub.c b/cmds/scrub.c index 782a1310816b..65c7c5b6fe8a 100644 --- a/cmds/scrub.c +++ b/cmds/scrub.c @@ -1171,7 +1171,6 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, int ioprio_class = IOPRIO_CLASS_IDLE; int ioprio_classdata = 0; int n_start = 0; - int n_skip = 0; int n_resume = 0; struct btrfs_ioctl_fs_info_args fi_args; struct btrfs_ioctl_dev_info_args *di_args = NULL; @@ -1337,7 +1336,6 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, sp[i].scrub_args.start = last_scrub->p.last_physical; sp[i].resumed = last_scrub; } else if (resume) { - ++n_skip; sp[i].skip = 1; sp[i].resumed = last_scrub; continue; diff --git a/image/main.c b/image/main.c index d4a1fe349d31..8aa4c1552807 100644 --- a/image/main.c +++ b/image/main.c @@ -2243,7 +2243,6 @@ static int build_chunk_tree(struct mdrestore_struct *mdres, struct meta_cluster_header *header; struct meta_cluster_item *item = NULL; u32 i, nritems; - u64 bytenr = 0; u8 *buffer; int ret; @@ -2265,7 +2264,6 @@ static int build_chunk_tree(struct mdrestore_struct *mdres, return -EIO; } - bytenr += IMAGE_BLOCK_SIZE; mdres->compress_method = header->compress; nritems = le32_to_cpu(header->nritems); for (i = 0; i < nritems; i++) { @@ -2273,7 +2271,6 @@ static int build_chunk_tree(struct mdrestore_struct *mdres, if (le64_to_cpu(item->bytenr) == BTRFS_SUPER_INFO_OFFSET) break; - bytenr += le32_to_cpu(item->size); if (fseek(mdres->in, le32_to_cpu(item->size), SEEK_CUR)) { error("seek failed: %m"); return -EIO; diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index a79fc6a5dbc3..f06ee24322bf 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -826,7 +826,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, int i; u64 *alloc_offsets = NULL; u64 last_alloc = 0; - u32 num_sequential = 0, num_conventional = 0; + u32 num_conventional = 0; if (!btrfs_is_zoned(fs_info)) return 0; @@ -870,9 +870,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_fs_info *fs_info, } is_sequential = btrfs_dev_is_sequential(device, physical); - if (is_sequential) - num_sequential++; - else + if (!is_sequential) num_conventional++; if (!is_sequential) { diff --git a/mkfs/main.c b/mkfs/main.c index 9f106e33f869..341ba4089484 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -490,7 +490,6 @@ static void list_all_devices(struct btrfs_root *root) struct btrfs_fs_devices *fs_devices; struct btrfs_device *device; int number_of_devices = 0; - u64 total_block_count = 0; fs_devices = root->fs_info->fs_devices; @@ -500,8 +499,6 @@ static void list_all_devices(struct btrfs_root *root) list_sort(NULL, &fs_devices->devices, _cmp_device_by_id); printf("Number of devices: %d\n", number_of_devices); - /* printf("Total devices size: %10s\n", */ - /* pretty_size(total_block_count)); */ printf("Devices:\n"); printf(" ID SIZE PATH\n"); list_for_each_entry(device, &fs_devices->devices, dev_list) { @@ -509,7 +506,6 @@ static void list_all_devices(struct btrfs_root *root) device->devid, pretty_size(device->total_bytes), device->name); - total_block_count += device->total_bytes; } printf("\n");