Skip to contentSkip to conversation

btrfs: fix error value in btrfs_get_extent

PATCH In review Pavel Machek 3 participants 5 messages Aug 3, 2020 – Aug 11, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: fix error value in btrfs_get_extent

btrfs_get_extent() sets variable ret, but out: error path expect error to be in variable err. Fix that.

---

Notice that patch introducing this problem is on its way to 4.19.137-stable.

fs/btrfs/inode.c +1 -1
index 7befb7c12bd3..4aaa01540f89 100644
@@ -7012,7 +7012,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	    found_type == BTRFS_FILE_EXTENT_PREALLOC) {
 		/* Only regular file could have regular/prealloc extent */
 		if (!S_ISREG(inode->vfs_inode.i_mode)) {
-			ret = -EUCLEAN;
+			err = -EUCLEAN;
 			btrfs_crit(fs_info,
 		"regular/prealloc extent found for non-regular inode %llu",
 				   btrfs_ino(inode));
Signature · 2 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Pavel Machek

btrfs_get_extent() sets variable ret, but out: error path expect error to be in variable err. Fix that.

Good catch, this also needs:

Fixes 6bf9e4bd6a27 ("btrfs: inode: Verify inode mode to avoid NULL

pointer dereference")

Quoted 19 lines

---

Notice that patch introducing this problem is on its way to 4.19.137-stable.

fs/btrfs/inode.c +1 -1
index 7befb7c12bd3..4aaa01540f89 100644
@@ -7012,7 +7012,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	    found_type == BTRFS_FILE_EXTENT_PREALLOC) {
 		/* Only regular file could have regular/prealloc extent */
 		if (!S_ISREG(inode->vfs_inode.i_mode)) {
-			ret = -EUCLEAN;
+			err = -EUCLEAN;
 			btrfs_crit(fs_info,
 		"regular/prealloc extent found for non-regular inode %llu",
 				   btrfs_ino(inode));
#2 lore raw
Quoted 6 lines · Nikolay Borisov
Quoted 3 lines · Pavel Machek

btrfs_get_extent() sets variable ret, but out: error path expect error to be in variable err. Fix that.

Quoted 8 lines
Quoted 1 line

Good catch, this also needs:

Fixes 6bf9e4bd6a27 ("btrfs: inode: Verify inode mode to avoid NULL

pointer dereference")

Actually the reason this error got introduced in the first place and I missed it during the review is that the function is doing something rather counter-intuitive - it's using 'err' variable as a synonym for 'ret'. A better approach would be to simply remove 'err' from that function. I'm now authoring such a patch, nevertheless the issue still stands.

Quoted 22 lines
Quoted 21 lines

---

Notice that patch introducing this problem is on its way to 4.19.137-stable.

fs/btrfs/inode.c +1 -1
index 7befb7c12bd3..4aaa01540f89 100644
@@ -7012,7 +7012,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	    found_type == BTRFS_FILE_EXTENT_PREALLOC) {
 		/* Only regular file could have regular/prealloc extent */
 		if (!S_ISREG(inode->vfs_inode.i_mode)) {
-			ret = -EUCLEAN;
+			err = -EUCLEAN;
 			btrfs_crit(fs_info,
 		"regular/prealloc extent found for non-regular inode %llu",
 				   btrfs_ino(inode));
#4 lore raw
In reply to Pavel Machek
Quoted 4 lines · Pavel Machek

btrfs_get_extent() sets variable ret, but out: error path expect error to be in variable err. Fix that.

Thanks, patch queued for 5.9.

Quoted 4 lines

---

Notice that patch introducing this problem is on its way to 4.19.137-stable.

Yeah, I'll let stable team know once this patch gets merged that the relevant patches can be picked.

#3 lore raw
In reply to Nikolay Borisov
Quoted 12 lines · Nikolay Borisov
Quoted 11 lines · Nikolay Borisov
Quoted 4 lines · Pavel Machek

btrfs_get_extent() sets variable ret, but out: error path expect error to be in variable err. Fix that.

Good catch, this also needs:

Fixes 6bf9e4bd6a27 ("btrfs: inode: Verify inode mode to avoid NULL

pointer dereference")

Quoted 8 lines
Quoted 1 line

Actually the reason this error got introduced in the first place and I missed it during the review is that the function is doing something rather counter-intuitive - it's using 'err' variable as a synonym for 'ret'. A better approach would be to simply remove 'err' from that function. I'm now authoring such a patch, nevertheless the issue still stands.

The expected pattern is to use 'ret' for function return value and add other temporary variables instead of the err/ret switching, which can be found in the oldish code still. So the cleanup is going to do the right thing, thanks.