* [PATCH] btrfs: free-space-cache: Fix error return code in __load_free_space_cache
@ 2020-11-20 1:08 Zhihao Cheng
2020-12-04 17:43 ` David Sterba
2020-12-04 17:52 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Zhihao Cheng @ 2020-11-20 1:08 UTC (permalink / raw)
To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, chengzhihao1, yi.zhang
Fix to return the error code(instead always 0) when memory allocating
failed in __load_free_space_cache().
Fixes: a67509c30079f4c50 ("Btrfs: add a io_ctl struct and helpers ...")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
fs/btrfs/free-space-cache.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index af0013d3df63..ae4059ce2f84 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -744,8 +744,10 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
while (num_entries) {
e = kmem_cache_zalloc(btrfs_free_space_cachep,
GFP_NOFS);
- if (!e)
+ if (!e) {
+ ret = -ENOMEM;
goto free_cache;
+ }
ret = io_ctl_read_entry(&io_ctl, e, &type);
if (ret) {
@@ -764,6 +766,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
e->trim_state = BTRFS_TRIM_STATE_TRIMMED;
if (!e->bytes) {
+ ret = -1;
kmem_cache_free(btrfs_free_space_cachep, e);
goto free_cache;
}
@@ -784,6 +787,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
e->bitmap = kmem_cache_zalloc(
btrfs_free_space_bitmap_cachep, GFP_NOFS);
if (!e->bitmap) {
+ ret = -ENOMEM;
kmem_cache_free(
btrfs_free_space_cachep, e);
goto free_cache;
--
2.25.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: free-space-cache: Fix error return code in __load_free_space_cache
2020-11-20 1:08 [PATCH] btrfs: free-space-cache: Fix error return code in __load_free_space_cache Zhihao Cheng
@ 2020-12-04 17:43 ` David Sterba
2020-12-04 17:52 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2020-12-04 17:43 UTC (permalink / raw)
To: Zhihao Cheng; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel, yi.zhang
On Fri, Nov 20, 2020 at 09:08:04AM +0800, Zhihao Cheng wrote:
> Fix to return the error code(instead always 0) when memory allocating
> failed in __load_free_space_cache().
Hm right the error handling flow in that function is a mess and the
error values are not set. Your patch is a minimal fix so I'll add it,
the function could use some cleanups though. Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: free-space-cache: Fix error return code in __load_free_space_cache
2020-11-20 1:08 [PATCH] btrfs: free-space-cache: Fix error return code in __load_free_space_cache Zhihao Cheng
2020-12-04 17:43 ` David Sterba
@ 2020-12-04 17:52 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2020-12-04 17:52 UTC (permalink / raw)
To: Zhihao Cheng; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel, yi.zhang
On Fri, Nov 20, 2020 at 09:08:04AM +0800, Zhihao Cheng wrote:
> Fix to return the error code(instead always 0) when memory allocating
> failed in __load_free_space_cache().
This lacks the analysis of consequences, so there's only one caller and
that will treat values <=0 as 'cache not loaded'. There's no functional
change but otherwise the error values should be there for clarity.
Changelog updated.
> Fixes: a67509c30079f4c50 ("Btrfs: add a io_ctl struct and helpers ...")
BTW, please don't trim the patch subject in the Fixes line.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-04 17:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 1:08 [PATCH] btrfs: free-space-cache: Fix error return code in __load_free_space_cache Zhihao Cheng
2020-12-04 17:43 ` David Sterba
2020-12-04 17:52 ` 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).