linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-next] fs: btrfs: fix returnvar.cocci warnings
@ 2021-08-20  2:32 jing yangyang
  2021-08-20  3:16 ` Qu Wenruo
  2021-08-20 10:40 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: jing yangyang @ 2021-08-20  2:32 UTC (permalink / raw)
  To: Chris Mason
  Cc: Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	jing yangyang, Zeal Robot

Remove unneeded variables when "0" can be returned.

Generated by: scripts/coccinelle/misc/returnvar.cocci

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: jing yangyang <jing.yangyang@zte.com.cn>
---
 fs/btrfs/extent_map.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 4a8e02f..58860d7 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -296,7 +296,6 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
 int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,
 		       u64 gen)
 {
-	int ret = 0;
 	struct extent_map *em;
 	bool prealloc = false;
 
@@ -328,7 +327,7 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,
 	free_extent_map(em);
 out:
 	write_unlock(&tree->lock);
-	return ret;
+	return 0;
 
 }
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH linux-next] fs: btrfs: fix returnvar.cocci warnings
  2021-08-20  2:32 [PATCH linux-next] fs: btrfs: fix returnvar.cocci warnings jing yangyang
@ 2021-08-20  3:16 ` Qu Wenruo
  2021-08-20 10:40 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2021-08-20  3:16 UTC (permalink / raw)
  To: jing yangyang, Chris Mason
  Cc: Josef Bacik, David Sterba, linux-btrfs, linux-kernel,
	jing yangyang, Zeal Robot



On 2021/8/20 上午10:32, jing yangyang wrote:
> Remove unneeded variables when "0" can be returned.
>
> Generated by: scripts/coccinelle/misc/returnvar.cocci
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: jing yangyang <jing.yangyang@zte.com.cn>
> ---
>   fs/btrfs/extent_map.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
> index 4a8e02f..58860d7 100644
> --- a/fs/btrfs/extent_map.c
> +++ b/fs/btrfs/extent_map.c
> @@ -296,7 +296,6 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)
>   int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,
>   		       u64 gen)
>   {
> -	int ret = 0;
>   	struct extent_map *em;
>   	bool prealloc = false;
>

Please just check the lines below:

	em = lookup_extent_mapping(tree, start, len);

	WARN_ON(!em || em->start != start);

	if (!em)
		goto out;

This looks more like a missing error handling.

Thus the proper way to fix it is not just simply remove the "int ret =
0;" line (which compiler is more than able to optimize it out), but
properly add the error handling, and modify the only caller to catch
such error properly.

Some diff like the below would be more meaningful:

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 4a8e02f7b6c7..9182d747a50e 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -303,10 +303,11 @@ int unpin_extent_cache(struct extent_map_tree
*tree, u64 start, u64 len,
  	write_lock(&tree->lock);
  	em = lookup_extent_mapping(tree, start, len);

-	WARN_ON(!em || em->start != start);
-
-	if (!em)
+	if (!em || em->start != start) {
+		WARN(1, KERN_WARNING "unexpected extent mapping\n");
+		ret = -EUCLEAN;
  		goto out;
+	}

  	em->generation = gen;
  	clear_bit(EXTENT_FLAG_PINNED, &em->flags);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2aa9646bce56..313b0a314c0b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2989,6 +2989,7 @@ static int btrfs_finish_ordered_io(struct
btrfs_ordered_extent *ordered_extent)
  	u64 start, end;
  	int compress_type = 0;
  	int ret = 0;
+	int ret2;
  	u64 logical_len = ordered_extent->num_bytes;
  	bool freespace_inode;
  	bool truncated = false;
@@ -3076,8 +3077,11 @@ static int btrfs_finish_ordered_io(struct
btrfs_ordered_extent *ordered_extent)
  						ordered_extent->disk_num_bytes);
  		}
  	}
-	unpin_extent_cache(&inode->extent_tree, ordered_extent->file_offset,
+	ret2 = unpin_extent_cache(&inode->extent_tree,
ordered_extent->file_offset,
  			   ordered_extent->num_bytes, trans->transid);
+	if (ret2 < 0 && !ret)
+		ret = ret2;
+
  	if (ret < 0) {
  		btrfs_abort_transaction(trans, ret);
  		goto out;


Thanks,
Qu
> @@ -328,7 +327,7 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,
>   	free_extent_map(em);
>   out:
>   	write_unlock(&tree->lock);
> -	return ret;
> +	return 0;
>
>   }
>
>

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH linux-next] fs: btrfs: fix returnvar.cocci warnings
  2021-08-20  2:32 [PATCH linux-next] fs: btrfs: fix returnvar.cocci warnings jing yangyang
  2021-08-20  3:16 ` Qu Wenruo
@ 2021-08-20 10:40 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2021-08-20 10:40 UTC (permalink / raw)
  To: jing yangyang
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs,
	linux-kernel, jing yangyang, Zeal Robot

On Thu, Aug 19, 2021 at 07:32:29PM -0700, jing yangyang wrote:
> Remove unneeded variables when "0" can be returned.
> 
> Generated by: scripts/coccinelle/misc/returnvar.cocci

Fixing that needs much more work that's not obvious from the function
itself.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-20 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20  2:32 [PATCH linux-next] fs: btrfs: fix returnvar.cocci warnings jing yangyang
2021-08-20  3:16 ` Qu Wenruo
2021-08-20 10:40 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).