Under memory pressure, bio_alloc_bioset() may fail and return NULL. Add
a check to prevent NULL pointer dereference in iomap_alloc_ioend().
This could happen when the system is under memory pressure and the
allocation of the bio structure fails.
Signed-off-by: Ye Chey <yechey@ai-sast.com>
---
fs/iomap/buffered-io.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 5b08bd417..d243b191e 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -1618,6 +1618,8 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
bio = bio_alloc_bioset(wpc->iomap.bdev, BIO_MAX_VECS,
REQ_OP_WRITE | wbc_to_write_flags(wbc),
GFP_NOFS, &iomap_ioend_bioset);
+ if (!bio)
+ return NULL;
bio->bi_iter.bi_sector = iomap_sector(&wpc->iomap, pos);
bio->bi_end_io = iomap_writepage_end_bio;
bio->bi_write_hint = inode->i_write_hint;
--
2.44.0