Skip to contentSkip to conversation

btrfs: remove unused return value assignment in btrfs_finish_extent_commit()

PATCH Superseded Jingkai Tan 3 participants 5 messages Jan 22 – Feb 4 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: remove unused return value assignment in btrfs_finish_extent_commit()

Coverity (ID: 1226842) reported that the return value of btrfs_discard_extent() is assigned to ret but is immediately overwritten by unpin_extent_range() without being checked.

---
 fs/btrfs/extent-tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/extent-tree.c +2 -2
index e4cae34620d1..0d69c3067ed8 100644
@@ -2838,8 +2838,8 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
 		struct extent_state *next_state;
 
 		if (btrfs_test_opt(fs_info, DISCARD_SYNC))
-			ret = btrfs_discard_extent(fs_info, start,
-						   end + 1 - start, NULL);
+			btrfs_discard_extent(fs_info, start,
+					     end + 1 - start, NULL);
 
 		next_state = btrfs_next_extent_state(unpin, cached_state);
 		btrfs_clear_extent_dirty(unpin, start, end, &cached_state);
Signature · 1 line
2.52.0
#1 lore raw
Quoted 14 lines · Jingkai Tan

Coverity (ID: 1226842) reported that the return value of btrfs_discard_extent() is assigned to ret but is immediately overwritten by unpin_extent_range() without being checked.

---
  fs/btrfs/extent-tree.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/extent-tree.c +0 -0
index e4cae34620d1..0d69c3067ed8 100644

fs/btrfs/extent-tree.c int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans) · line 2842

Quoted 7 lines
fs/btrfs/extent-tree.c +2 -2
@@ -2838,8 +2838,8 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
  		struct extent_state *next_state;
 
  		if (btrfs_test_opt(fs_info, DISCARD_SYNC))
-			ret = btrfs_discard_extent(fs_info, start,
-						   end + 1 - start, NULL);
+			btrfs_discard_extent(fs_info, start,
+					     end + 1 - start, NULL);

If you really want to silent coverity, do a proper error handling other than blindly removing the return value.

Especially there is already a proper error handling of btrfs_discard_extent() later in the function.

Quoted 3 lines
fs/btrfs/extent-tree.c +0 -0
  		next_state = btrfs_next_extent_state(unpin, cached_state);
  		btrfs_clear_extent_dirty(unpin, start, end, &cached_state);
#2 lore raw

PATCH v2 1/1 btrfs: handle return value assignment in btrfs_finish_extent_commit()

Coverity (ID: 1226842) reported that the return value of btrfs_discard_extent() is assigned to ret but is immediately overwritten by unpin_extent_range() without being checked.

Use the same error handling that is used for btrfs_discard_extent in extent-tree.c

---
Thanks for the feedback Wenruo. Updated to use the same error handling as the call to btrfs_discard_extent further down in btrfs_finish_extent_commit.

Apologies as I have just started learning how to contribute to the linux kernel and am looking for relatively simple low hanging fruits to familarize myself with the process.

 fs/btrfs/extent-tree.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +9 -1
index e4cae34620d1..67d6afb04bc1 100644
@@ -2837,9 +2837,17 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
 	while (!TRANS_ABORTED(trans) && cached_state) {
 		struct extent_state *next_state;
 
-		if (btrfs_test_opt(fs_info, DISCARD_SYNC))
+		if (btrfs_test_opt(fs_info, DISCARD_SYNC)) {
 			ret = btrfs_discard_extent(fs_info, start,
 						   end + 1 - start, NULL);
+			if (ret) {
+				const char *errstr = btrfs_decode_error(ret);
+
+				btrfs_warn(fs_info,
+					   "discard failed for extent [%llu, %llu]: errno=%d %s",
+					   start, end, ret, errstr);
+			}
+		}
 
 		next_state = btrfs_next_extent_state(unpin, cached_state);
 		btrfs_clear_extent_dirty(unpin, start, end, &cached_state);
Signature · 1 line
2.52.0
#3 lore raw

Re: [PATCH v2] btrfs: handle return value assignment in btrfs_finish_extent_commit()

Quoted 4 lines · Jingkai Tan

Coverity (ID: 1226842) reported that the return value of btrfs_discard_extent() is assigned to ret but is immediately overwritten by unpin_extent_range() without being checked.

Quoted 8 lines

Use the same error handling that is used for btrfs_discard_extent in extent-tree.c

---
Thanks for the feedback Wenruo. Updated to use the same error handling as the call to btrfs_discard_extent further down in btrfs_finish_extent_commit.

Added to for-next, thanks. I was thinking if we want to report the error at all, ie. not checking the error value at all but a report seems better also because it's done in the other part of the function.

Quoted 3 lines

Apologies as I have just started learning how to contribute to the linux kernel and am looking for relatively simple low hanging fruits to familarize myself with the process.

I did a minor simplification to your patch, the errstr variable is not needed. You can send a separate patch to do the same in the other loop in btrfs_finish_extent_commit() for consistency. Thanks.

#4 lore raw

PATCH 1/1 btrfs: remove unnecessary errstr variable in btrfs_finish_extent_commit()

inline the errstr variable in btrfs_finish_extent_commit for consistency.

---
As requested, remove errstr variable and inline the call to btrfs_decode_error

 fs/btrfs/extent-tree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/extent-tree.c +1 -2
index 03cf9f242c70..5b71a6955683 100644
@@ -3008,10 +3008,9 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans)
 		btrfs_put_block_group(block_group);
 
 		if (ret) {
-			const char *errstr = btrfs_decode_error(ret);
 			btrfs_warn(fs_info,
 			   "discard failed while removing blockgroup: errno=%d %s",
-				   ret, errstr);
+				   ret, btrfs_decode_error(ret));
 		}
 	}
 
Signature · 1 line
2.52.0