Skip to content

Commit 0936db8

Browse files
boryasjfvogel
authored andcommitted
btrfs: handle empty eb->folios in num_extent_folios()
[ Upstream commit d6fe0c69b3aa5c985380b794bdf8e6e9b1811e60 ] 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]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 230c94ca3527dafc206666a56cb7823a7edc66a5) Signed-off-by: Jack Vogel <[email protected]>
1 parent 02f103c commit 0936db8

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
@@ -293,6 +293,8 @@ static inline int num_extent_pages(const struct extent_buffer *eb)
293293
*/
294294
static inline int num_extent_folios(const struct extent_buffer *eb)
295295
{
296+
if (!eb->folios[0])
297+
return 0;
296298
if (folio_order(eb->folios[0]))
297299
return 1;
298300
return num_extent_pages(eb);

0 commit comments

Comments
 (0)