Skip to content

Commit d6fe0c6

Browse files
boryaskdave
authored andcommitted
btrfs: handle empty eb->folios in num_extent_folios()
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 <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent bc7e097 commit d6fe0c6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/btrfs/extent_io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ static inline int __pure num_extent_pages(const struct extent_buffer *eb)
298298
*/
299299
static inline int __pure num_extent_folios(const struct extent_buffer *eb)
300300
{
301+
if (!eb->folios[0])
302+
return 0;
301303
if (folio_order(eb->folios[0]))
302304
return 1;
303305
return num_extent_pages(eb);

0 commit comments

Comments
 (0)