btrfs: turn unpin_extent_cache() into a void function
PATCH 1/1 btrfs: turn unpin_extent_cache() into a void function
The value of the 'ret' variable is never changed in function unpin_extent_cache(). And since the only caller of this function doesn't check the return value, it can simply be turned into a void function.
--- fs/btrfs/extent_map.c | 7 ++----- fs/btrfs/extent_map.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-)
fs/btrfs/extent_map.c +2 -5
@@ -292,10 +292,9 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)* to the generation that actually added the file item to the inode so we know * we need to sync this extent when we call fsync(). */ -int unpin_extent_cache (struct extent_map_tree *tree,u64 start,u64 len, -u64 gen) +void unpin_extent_cache (struct extent_map_tree *tree,u64 start,u64 len, +u64 gen) { -int ret =0 ;struct extent_map *em;bool prealloc = false;
@@ -327,8 +326,6 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,free_extent_map (em); out:write_unlock (&tree->lock); -return ret; - }void clear_em_logging (struct extent_map_tree *tree,struct extent_map *em)
fs/btrfs/extent_map.h +1 -1
@@ -97,7 +97,7 @@ struct extent_map *alloc_extent_map(void);void free_extent_map (struct extent_map *em);int __init extent_map_init (void );void __cold extent_map_exit (void ); -int unpin_extent_cache (struct extent_map_tree *tree,u64 start,u64 len,u64 gen); +void unpin_extent_cache (struct extent_map_tree *tree,u64 start,u64 len,u64 gen);void clear_em_logging (struct extent_map_tree *tree,struct extent_map *em);struct extent_map *search_extent_mapping (struct extent_map_tree *tree,u64 start,u64 len);
Quoted 5 lines · Luís Henriques
The value of the 'ret' variable is never changed in function
unpin_extent_cache(). And since the only caller of this function doesn't check the return value, it can simply be turned into a void function.Signed-off-by Luís Henriques <[email protected]>
Hmm but inside unpin_extent_cache() there is this:
/* [...] */ em = lookup_extent_mapping(tree, start, len); WARN_ON(!em || em->start != start); if (!em) goto out; /* [...] */
out:
write_unlock(&tree->lock); return ret;
}
Wouldn't it be better to either actually handle the error, OR change the WARN_ON() into an ASSERT()?
Given the fact, that if the lookup fails, we've passed wrong parameters somehow, an ASSERT() would be a good way IMHO.
Thoughts?
Quoted 25 lines · Johannes Thumshirn
Quoted 5 lines · Luís Henriques
The value of the 'ret' variable is never changed in function
unpin_extent_cache(). And since the only caller of this function doesn't check the return value, it can simply be turned into a void function.Signed-off-by Luís Henriques <[email protected]>Hmm but inside
unpin_extent_cache()there is this:/* [...] */ em = lookup_extent_mapping(tree, start, len); WARN_ON(!em || em->start != start); if (!em) goto out; /* [...] */out:
write_unlock(&tree->lock); return ret;}
Quoted 7 lines
Wouldn't it be better to either actually handle the error, OR change the
WARN_ON()into anASSERT()?Given the fact, that if the lookup fails, we've passed wrong parameters somehow, an
ASSERT()would be a good way IMHO.Thoughts?
OK, I guess that using ASSERT() makes sense -- it's used in several other places where lookup_extent_mapping() is called.
Returning an error to the caller can also be done but I wonder if the only place where it is called actually cares about it. That's in btrfs_finish_one_ordered(), and it basically does:
if (test_bit(BTRFS_ORDERED_PREALLOC))
ret = btrfs_mark_extent_written();
else
ret = insert_ordered_extent_file_extent();
unpin_extent_cache();
if (ret < 0) {
btrfs_abort_transaction();
goto out;
}Even if unpin_extent_cache() would return an error, I'd say that it is better to try to proceed anyway rather than abort if unpinning an extent from cache fails. But my opinion isn't very solid ;-)
Cheers,
Signature · 1 line
Luís
Quoted 28 lines · Luís Henriques
The value of the 'ret' variable is never changed in function
unpin_extent_cache(). And since the only caller of this function doesn't check the return value, it can simply be turned into a void function.Signed-off-by Luís Henriques <[email protected]>--- fs/btrfs/extent_map.c | 7 ++----- fs/btrfs/extent_map.h | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-)fs/btrfs/extent_map.c +2
-3@@ -292,10 +292,9 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em)* to the generation that actually added the file item to the inode so we know * we need to sync this extent when we call fsync(). */ -int unpin_extent_cache (struct extent_map_tree *tree,u64 start,u64 len, -u64 gen) +void unpin_extent_cache (struct extent_map_tree *tree,u64 start,u64 len, +u64 gen) { -int ret =0 ;struct extent_map *em;bool prealloc = false;
fs/btrfs/extent_map.c int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, · line 329
Quoted 6 lines
fs/btrfs/extent_map.c +0
-2@@ -327,8 +326,6 @@ int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len,free_extent_map (em); out:write_unlock (&tree->lock); -return ret; - }
This function has unfortunatelly attracting attention to do a simple fix to just return void, several have been aleary sent but none of them fixes it properly. To the point I don't want to reply anymore.
https://lore.kernel.org/linux-btrfs/[email protected]/
https://lore.kernel.org/linux-btrfs/[email protected]/
https://patchwork.kernel.org/project/linux-btrfs/patch/[email protected]/#22596309
"When switching a fuction to return void, please check the whole callgraph for functions that do not properly handler errors and do BUG_ON. You won't see errors passed from them so this gives the impression no error handling is needed in the caller."