All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib: cpu_rmap: reject zero-sized maps
@ 2026-07-18  4:21 Jackie Liu
  2026-07-18  4:56 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Jackie Liu @ 2026-07-18  4:21 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel

From: Jackie Liu <liuyun01@kylinos.cn>

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@kylinos.cn>
---
 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib: cpu_rmap: reject zero-sized maps
  2026-07-18  4:21 [PATCH] lib: cpu_rmap: reject zero-sized maps Jackie Liu
@ 2026-07-18  4:56 ` Andrew Morton
  2026-07-19  3:36   ` Jackie Liu
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-07-18  4:56 UTC (permalink / raw)
  To: Jackie Liu; +Cc: linux-kernel

On Sat, 18 Jul 2026 12:21:55 +0800 Jackie Liu <liu.yun@linux.dev> wrote:

> From: Jackie Liu <liuyun01@kylinos.cn>
> 
> 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?

> 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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib: cpu_rmap: reject zero-sized maps
  2026-07-18  4:56 ` Andrew Morton
@ 2026-07-19  3:36   ` Jackie Liu
  0 siblings, 0 replies; 3+ messages in thread
From: Jackie Liu @ 2026-07-19  3:36 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

2026年7月18日 12:56, "Andrew Morton" <akpm@linux-foundation.org mailto:akpm@linux-foundation.org?to=%22Andrew%20Morton%22%20%3Cakpm%40linux-foundation.org%3E > 写到:


> 
> On Sat, 18 Jul 2026 12:21:55 +0800 Jackie Liu <liu.yun@linux.dev> wrote:
> 
> > 
> > From: Jackie Liu <liuyun01@kylinos.cn>
> >  
> >  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?
> 
> > 
> > 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-19  3:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18  4:21 [PATCH] lib: cpu_rmap: reject zero-sized maps Jackie Liu
2026-07-18  4:56 ` Andrew Morton
2026-07-19  3:36   ` Jackie Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.