Skip to content

Commit

Permalink
btrfs: handle empty eb->folios in num_extent_folios()
Browse files Browse the repository at this point in the history
num_extent_folios() unconditionally calls folio_order() on
eb->folios[0]. If that is NULL this will be a segfault. It is reasonable
for it to return 0 as the number of folios in the eb when the first
entry is NULL, so do that instead.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Boris Burkov <boris@bur.io>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Boris Burkov authored and David Sterba committed May 2, 2025
1 parent bc7e097 commit d6fe0c6
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fs/btrfs/extent_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ static inline int __pure num_extent_pages(const struct extent_buffer *eb)
*/
static inline int __pure num_extent_folios(const struct extent_buffer *eb)
{
if (!eb->folios[0])
return 0;
if (folio_order(eb->folios[0]))
return 1;
return num_extent_pages(eb);
Expand Down

0 comments on commit d6fe0c6

Please sign in to comment.