Add error checking for mempool_alloc return value to avoid potential NULL pointer dereference when memory allocation fails.
Signed-off-by: Ye Chey <[email protected]> --- fs/bcachefs/bkey_buf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/bcachefs/bkey_buf.h b/fs/bcachefs/bkey_buf.h index a30c4ae8e..8272a1830 100644 --- a/fs/bcachefs/bkey_buf.h +++ b/fs/bcachefs/bkey_buf.h @@ -16,6 +16,8 @@ static inline void bch2_bkey_buf_realloc(struct bkey_buf *s, if (s->k == (void *) s->onstack && u64s > ARRAY_SIZE(s->onstack)) { s->k = mempool_alloc(&c->large_bkey_pool, GFP_NOFS); + if (!s->k) + return; memcpy(s->k, s->onstack, sizeof(s->onstack)); } } -- 2.44.0
