linux_compat: fix NULL pointer dereference in get_mem()

Add NULL check after memalign() call in get_mem() to prevent
potential NULL pointer dereference (CWE-476).

The function memalign() can return NULL on allocation failure.
Dereferencing the returned pointer without checking for NULL
may cause a crash in low-memory conditions.

Changes:
- Add NULL check after memalign() allocation
- Return NULL on failure, consistent with function semantics

This fixes the static analyzer warning:
  linux_compat.c:34: dereference of memalign return value without NULL check

Reported-by: static analyzer Svace
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Anton Moryakov
2026-02-27 00:27:28 +03:00
committed by Tom Rini
parent 660d8e4fe9
commit 21edd76ade

View File

@@ -32,6 +32,9 @@ struct kmem_cache *get_mem(int element_sz)
struct kmem_cache *ret;
ret = memalign(ARCH_DMA_MINALIGN, sizeof(struct kmem_cache));
if (!ret)
return NULL;
ret->sz = element_sz;
return ret;