Skip to contentSkip to conversation

btrfs: get rid of goto in alloc_test_extent_buffer()

PATCH In review Daniel Vacek 2 participants 3 messages Apr 25, 2025 – Apr 30, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: get rid of goto in alloc_test_extent_buffer()

The free_eb label is used only once. Simplify by moving the code inplace.

---
 fs/btrfs/extent_io.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +2 -4
index ea38c73d4bc5f..20cdddd924852 100644
@@ -3004,15 +3004,13 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 			goto again;
 		}
 		xa_unlock_irq(&fs_info->buffer_tree);
-		goto free_eb;
+		btrfs_release_extent_buffer(eb);
+		return exists;
 	}
 	xa_unlock_irq(&fs_info->buffer_tree);
 	check_buffer_tree_ref(eb);
 
 	return eb;
-free_eb:
-	btrfs_release_extent_buffer(eb);
-	return exists;
 #else
 	/* Stub to avoid linker error when compiled with optimizations turned off. */
 	return NULL;
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Daniel Vacek

The free_eb label is used only once. Simplify by moving the code inplace.

---
 fs/btrfs/extent_io.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +0 -0
index ea38c73d4bc5f..20cdddd924852 100644
@@ -3004,15 +3004,13 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 			goto again;
 		}
 		xa_unlock_irq(&fs_info->buffer_tree);

fs/btrfs/extent_io.c struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, · line 3014

Quoted 10 lines
fs/btrfs/extent_io.c +2 -3
-		goto free_eb;
+		btrfs_release_extent_buffer(eb);
+		return exists;
 	}
 	xa_unlock_irq(&fs_info->buffer_tree);
 	check_buffer_tree_ref(eb);
 
 	return eb;
-free_eb:
-	btrfs_release_extent_buffer(eb);

So the xarray conversion removed the other use of the free_eb label and calls btrfs_release_extent_buffer() + return. Doing the same here and removing the label completely looks as an improvement, as the whole function does direct returns instead of goto exit block.

#2 lore raw
Quoted 32 lines · David Sterba
Quoted 15 lines · Daniel Vacek

The free_eb label is used only once. Simplify by moving the code inplace.

---
 fs/btrfs/extent_io.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +0 -0
index ea38c73d4bc5f..20cdddd924852 100644
@@ -3004,15 +3004,13 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 			goto again;
 		}
 		xa_unlock_irq(&fs_info->buffer_tree);

fs/btrfs/extent_io.c struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, · line 3014

Quoted 10 lines
fs/btrfs/extent_io.c +2 -3
-		goto free_eb;
+		btrfs_release_extent_buffer(eb);
+		return exists;
 	}
 	xa_unlock_irq(&fs_info->buffer_tree);
 	check_buffer_tree_ref(eb);
 
 	return eb;
-free_eb:
-	btrfs_release_extent_buffer(eb);

So the xarray conversion removed the other use of the free_eb label and calls btrfs_release_extent_buffer() + return. Doing the same here and removing the label completely looks as an improvement, as the whole function does direct returns instead of goto exit block.

Quoted 1 line

Xarray conversion is now in for-next so I've added this patch too.