[PATCH] lib: cpu_rmap: reject zero-sized maps
From: Jackie Liu
Date: Sat Jul 18 2026 - 00:22:20 EST
From: Jackie Liu <liuyun01@xxxxxxxxxx>
alloc_cpu_rmap() assigns an object index to each possible CPU using
cpu % size. Passing zero therefore triggers a divide error instead of
reporting that the map cannot be allocated.
Reject zero along with sizes that do not fit in the u16 map indices.
Fixes: c39649c331c7 ("lib: cpu_rmap: CPU affinity reverse-mapping")
Signed-off-by: Jackie Liu <liuyun01@xxxxxxxxxx>
---
lib/cpu_rmap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/cpu_rmap.c b/lib/cpu_rmap.c
index c86ab6e55d17..bbb41d37acb1 100644
--- a/lib/cpu_rmap.c
+++ b/lib/cpu_rmap.c
@@ -28,8 +28,8 @@ struct cpu_rmap *alloc_cpu_rmap(unsigned int size, gfp_t flags)
unsigned int cpu;
size_t obj_offset;
- /* This is a silly number of objects, and we use u16 indices. */
- if (size > 0xffff)
+ /* Empty maps are invalid, and we use u16 indices. */
+ if (!size || size > 0xffff)
return NULL;
/* Offset of object pointer array from base structure */
--
2.54.0