From c9ed13789061af00d9239f9fab8e246adbed2076 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett (Google)" Date: Mon, 19 Oct 2026 23:31:28 -0400 Subject: [PATCH] tools/testing/shared: catch a failed posix_memalign() posix_memalign() returns zero or a positive error number and never sets errno, so the checks for a negative return in kmem_cache_alloc_lru() and kmem_cache_alloc_bulk() is not possible. A failed aligned allocation carries on with the pointer unset, into the constructor or the memset(). Test for any non-zero return. Link: https://lore.kernel.org/20261020033128.1934349-1-liam@infradead.org Fixes: 8801c35c3672 ("tools: fix -Wunused-result in linux.c") Signed-off-by: Liam R. Howlett (Google) Signed-off-by: Andrew Morton Reviewed-by: Andrew Morton Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Vishal Moola (Fractile) Reviewed-by: SJ Park Cc: Matthew Wilcox (Oracle) Cc: Vlastimil Babka --- tools/testing/shared/linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/shared/linux.c b/tools/testing/shared/linux.c index e0a0693df08f..a37d2f86d325 100644 --- a/tools/testing/shared/linux.c +++ b/tools/testing/shared/linux.c @@ -83,7 +83,7 @@ void *kmem_cache_alloc_lru(struct kmem_cache *cachep, struct list_lru *lru, } else { pthread_mutex_unlock(&cachep->lock); if (cachep->align) { - if (posix_memalign(&p, cachep->align, cachep->size) < 0) + if (posix_memalign(&p, cachep->align, cachep->size)) return NULL; } else { p = malloc(cachep->size); @@ -191,7 +191,7 @@ bool kmem_cache_alloc_bulk(struct kmem_cache *cachep, gfp_t gfp, size_t size, if (cachep->align) { if (posix_memalign(&p[i], cachep->align, - cachep->size) < 0) + cachep->size)) break; } else { p[i] = malloc(cachep->size);