Commit 93d53f1c authored by Pei Xiao's avatar Pei Xiao Committed by Kent Overstreet
Browse files

bcachefs: add check NULL return of bio_kmalloc in journal_read_bucket



bio_kmalloc may return NULL, will cause NULL pointer dereference.
Add check NULL return for bio_kmalloc in journal_read_bucket.

Signed-off-by: default avatarPei Xiao <xiaopei01@kylinos.cn>
Fixes: ac10a961 ("bcachefs: Some fixes for building in userspace")
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent ef4f6c32
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@
	x(ENOMEM,			ENOMEM_dev_alloc)			\
	x(ENOMEM,			ENOMEM_disk_accounting)			\
	x(ENOMEM,			ENOMEM_stripe_head_alloc)		\
	x(ENOMEM,                       ENOMEM_journal_read_bucket)             \
	x(ENOSPC,			ENOSPC_disk_reservation)		\
	x(ENOSPC,			ENOSPC_bucket_alloc)			\
	x(ENOSPC,			ENOSPC_disk_label_add)			\
+2 −0
Original line number Diff line number Diff line
@@ -1012,6 +1012,8 @@ static int journal_read_bucket(struct bch_dev *ca,
			nr_bvecs = buf_pages(buf->data, sectors_read << 9);

			bio = bio_kmalloc(nr_bvecs, GFP_KERNEL);
			if (!bio)
				return -BCH_ERR_ENOMEM_journal_read_bucket;
			bio_init(bio, ca->disk_sb.bdev, bio->bi_inline_vecs, nr_bvecs, REQ_OP_READ);

			bio->bi_iter.bi_sector = offset;