lib: cpu_rmap: reject zero-sized maps
PATCH 1/1 lib: cpu_rmap: reject zero-sized maps
From: Jackie Liu <[email protected]>
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.
--- lib/cpu_rmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/cpu_rmap.c +2 -2
@@ -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 */
Signature · 1 line
2.54.0
Andrew Morton
maintainerQuoted 5 lines · On Sat, 18 Jul 2026 12:21:55 +0800 Jackie Liu <[email protected]> wrote:
From: Jackie Liu <[email protected]>
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.
Is there any situation in which this is known to trigger?
Quoted 1 line
Reject zero along with sizes that do not fit in the u16 map indices.
If passing zero is a caller bug then a divide-by-zero exception is a fine way of reporting it. So I'm not seeing a need to make any change here.
2026年7月18日 12:56, "Andrew Morton" <[email protected] mailto:[email protected]?to=%22Andrew%20Morton%22%20%3Cakpm%40linux-foundation.org%3E > 写到:
Quoted 10 lines · On Sat, 18 Jul 2026 12:21:55 +0800 Jackie Liu <[email protected]> wrote:
Quoted 8 lines
From: Jackie Liu <[email protected]>
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.
Quoted 9 lines
Is there any situation in which this is known to trigger?
Quoted 3 lines
Reject zero along with sizes that do not fit in the u16 map indices.
If passing zero is a caller bug then a divide-by-zero exception is a fine way of reporting it. So I'm not seeing a need to make any change here.
Thanks. I rechecked all in-tree callers and couldn't find a path which can legitimately pass zero. The size is either explicitly checked or derived from successfully allocated IRQ/RX queue counts, whose minimum is one.
So zero would indeed indicate a caller bug. Please disregard this patch.