The @ret from the original function can only be 0 or <0.
<0 case is from write_one_eb() which can only return 0 or <0.

So just return @ret if something went wrong. For anything else, return
@flush_ret.

Also add a ASSERT() to catch unexpected >0 return value from
write_one_eb().

Signed-off-by: Qu Wenruo <w...@suse.com>
---
 fs/btrfs/extent_io.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index bc3426dff5a3..5573c2355e05 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3865,8 +3865,10 @@ int btree_write_cache_pages(struct address_space 
*mapping,
                goto retry;
        }
        flush_ret = flush_write_bio(&epd);
-       BUG_ON(flush_ret < 0);
-       return ret;
+       ASSERT(ret <= 0);
+       if (ret)
+               return ret;
+       return flush_ret;
 }
 
 /**
-- 
2.20.1

Reply via email to