Skip to contentSkip to conversation

Three patches that address static analyzer reports

PATCH In review Bart Van Assche 3 participants 8 messages Jun 20, 2018 – Jun 21, 2018 Btrfs file system

lore
Share & tools
lore
#0 lore raw

v2 cover Three patches that address static analyzer reports

Hello Chris and Josef,

The three patches in this series address complaints reported by static analyzers (gcc + W=1, sparse, smatch). These patches do not change any functionality. Please consider these for inclusion in the upstream kernel.

Thanks,

Bart.

Bart Van Assche (3):
btrfs: Fix indentation
btrfs: Annotate fall-through
btrfs: Fix a C compliance issue

 fs/btrfs/extent-tree.c | 4 ++--
 fs/btrfs/ioctl.c       | 4 ++--
 fs/btrfs/reada.c       | 2 +-
 fs/btrfs/super.c       | 7 ++++---
 4 files changed, 9 insertions(+), 8 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/3 btrfs: Fix indentation

This patch avoids that building the BTRFS source code with smatch triggers complaints about inconsistent indenting.

---
 fs/btrfs/extent-tree.c | 4 ++--
 fs/btrfs/ioctl.c       | 4 ++--
 fs/btrfs/reada.c       | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/extent-tree.c +2 -2
index 3d9fe58c0080..db46ceb62b3f 100644
@@ -6279,7 +6279,7 @@ static int update_block_group(struct btrfs_trans_handle *trans,
 		if (list_empty(&cache->dirty_list)) {
 			list_add_tail(&cache->dirty_list,
 				      &trans->transaction->dirty_bgs);
-				trans->transaction->num_dirty_bgs++;
+			trans->transaction->num_dirty_bgs++;
 			btrfs_get_block_group(cache);
 		}
 		spin_unlock(&trans->transaction->dirty_bgs_lock);
@@ -7534,7 +7534,7 @@ static noinline int find_free_extent(struct btrfs_fs_info *fs_info,
 		 * for the proper type.
 		 */
 		if (!block_group_bits(block_group, flags)) {
-		    u64 extra = BTRFS_BLOCK_GROUP_DUP |
+			u64 extra = BTRFS_BLOCK_GROUP_DUP |
 				BTRFS_BLOCK_GROUP_RAID1 |
 				BTRFS_BLOCK_GROUP_RAID5 |
 				BTRFS_BLOCK_GROUP_RAID6 |
fs/btrfs/ioctl.c +2 -2
index c2837a32d689..93b23549ee1e 100644
@@ -2507,8 +2507,8 @@ static int btrfs_search_path_in_tree_user(struct inode *inode,
 static noinline int btrfs_ioctl_ino_lookup(struct file *file,
 					   void __user *argp)
 {
-	 struct btrfs_ioctl_ino_lookup_args *args;
-	 struct inode *inode;
+	struct btrfs_ioctl_ino_lookup_args *args;
+	struct inode *inode;
 	int ret = 0;
 
 	args = memdup_user(argp, sizeof(*args));
fs/btrfs/reada.c +1 -1
index 40f1bcef394d..4be425f70c2d 100644
@@ -355,7 +355,7 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info,
 		dev = bbio->stripes[nzones].dev;
 
 		/* cannot read ahead on missing device. */
-		 if (!dev->bdev)
+		if (!dev->bdev)
 			continue;
 
 		zone = reada_find_zone(dev, logical, bbio);
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH v2 1/3] btrfs: Fix indentation

Review

Quoted 12 lines · Bart Van Assche
(quoted diff) +2 -2
 		if (list_empty(&cache->dirty_list)) {
 			list_add_tail(&cache->dirty_list,
 				      &trans->transaction->dirty_bgs);
-				trans->transaction->num_dirty_bgs++;
+			trans->transaction->num_dirty_bgs++;
 
 		if (!block_group_bits(block_group, flags)) {
-		    u64 extra = BTRFS_BLOCK_GROUP_DUP |
+			u64 extra = BTRFS_BLOCK_GROUP_DUP |
 				BTRFS_BLOCK_GROUP_RAID1 |
 				BTRFS_BLOCK_GROUP_RAID5 |
 				BTRFS_BLOCK_GROUP_RAID6 |

In the two cases the indentation makes the code less readable, but

fs/btrfs/ioctl.c static int btrfs_search_path_in_tree_user(struct inode *inode,

Quoted 8 lines
fs/btrfs/ioctl.c +3 -3
-	 struct btrfs_ioctl_ino_lookup_args *args;
-	 struct inode *inode;
+	struct btrfs_ioctl_ino_lookup_args *args;
+	struct inode *inode;
 
-		 if (!dev->bdev)
+		if (!dev->bdev)
 			continue;

this is purely whitespace change that is not applied in general. You mention that it's reported by smatch, that would be a reason to fix it so the output is less noisy.

#3 lore raw

PATCH v2 2/3 btrfs: Annotate fall-through

In reply to Bart Van Assche

This patch avoids that the compiler complains that a fall-through annotation is missing when building with W=1.

---
 fs/btrfs/super.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/super.c +1 -0
index 81107ad49f3a..3e298f26a383 100644
@@ -760,6 +760,7 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
 		case Opt_recovery:
 			btrfs_warn(info,
 				   "'recovery' is deprecated, use 'usebackuproot' instead");
+			/* fall through */
 		case Opt_usebackuproot:
 			btrfs_info(info,
 				   "trying to use backup root at mount time");
Signature · 1 line
2.17.1
#4 lore raw

PATCH v2 3/3 btrfs: Fix a C compliance issue

In reply to Bart Van Assche

The C programming language does not allow to use preprocessor statements inside macro arguments (pr_info() is defined as a macro). Hence rework the pr_info() statement in btrfs_print_mod_info() such that it becomes compliant. This patch allows tools like sparse to analyze the BTRFS source code.

Fixes 62e855771dac ("btrfs: convert printk(KERN_* to use pr_* calls")
Cc Jeff Mahoney <[email protected]>
Cc David Sterba <[email protected]>
Cc Nikolay Borisov <[email protected]>
---
 fs/btrfs/super.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/super.c +3 -3
index 3e298f26a383..972d9fbd7e96 100644
@@ -2370,7 +2370,7 @@ static __cold void btrfs_interface_exit(void)
 
 static void __init btrfs_print_mod_info(void)
 {
-	pr_info("Btrfs loaded, crc32c=%s"
+	static const char options[] =
 #ifdef CONFIG_BTRFS_DEBUG
 			", debug=on"
 #endif
@@ -2383,8 +2383,8 @@ static void __init btrfs_print_mod_info(void)
 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
 			", ref-verify=on"
 #endif
-			"\n",
-			crc32c_impl());
+			;
+	pr_info("Btrfs loaded, crc32c=%s%s\n", crc32c_impl(), options);
 }
 
 static int __init init_btrfs_fs(void)
Signature · 1 line
2.17.1
#5 lore raw

Re: [PATCH v2 3/3] btrfs: Fix a C compliance issue

I love your patch! Yet something to improve:

Hi Bart,

I love your patch! Yet something to improve:

[auto build test ERROR on v4.18-rc1]
[also build test ERROR on next-20180620]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Bart-Van-Assche/Three-patches-that-address-static-analyzer-reports/20180621-041247
config: m68k-sun3_defconfig (attached as .config)
compiler: m68k-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=m68k

All errors (new ones prefixed by >>):

fs//btrfs/super.c: In function 'btrfs_print_mod_info':

>> fs//btrfs/super.c:2386:4: error: expected expression before ';' token
       ;
       ^

vim +2386 fs//btrfs/super.c

2370
2371 static void __init btrfs_print_mod_info(void)
2372 {
2373 static const char options[] =
2374 #ifdef CONFIG_BTRFS_DEBUG
2375 ", debug=on"
2376 #endif
2377 #ifdef CONFIG_BTRFS_ASSERT
2378 ", assert=on"
2379 #endif
2380 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
2381 ", integrity-checker=on"
2382 #endif
2383 #ifdef CONFIG_BTRFS_FS_REF_VERIFY
2384 ", ref-verify=on"
2385 #endif

> 2386				;

2387 pr_info("Btrfs loaded, crc32c=%s%s\n", crc32c_impl(), options);
2388 }
2389

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#6 lore raw

Re: [PATCH v2 3/3] btrfs: Fix a C compliance issue

Quoted 18 lines · kbuild test robot

Hi Bart,

I love your patch! Yet something to improve:

[auto build test ERROR on v4.18-rc1]
[also build test ERROR on next-20180620]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Bart-Van-Assche/Three-patches-that-address-static-analyzer-reports/20180621-041247
config: m68k-sun3_defconfig (attached as .config)
compiler: m68k-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=m68k

Quoted 6 lines

All errors (new ones prefixed by >>):

fs//btrfs/super.c: In function 'btrfs_print_mod_info':

Quoted 1 line
Quoted 1 line

fs//btrfs/super.c:2386:4: error: expected expression before ';' token

       ;
       ^

That's probably because none of the config option is turned on and this results to

	const char options[] = ;

but a "" should fix it.

#7 lore raw
In reply to Bart Van Assche
Quoted 6 lines · Bart Van Assche

Hello Chris and Josef,

The three patches in this series address complaints reported by static analyzers (gcc + W=1, sparse, smatch). These patches do not change any functionality. Please consider these for inclusion in the upstream kernel.

Applied thanks, with the fixup to patch 3.