From: Jackie Liu <liu.yun@linux.dev>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] lib: cpu_rmap: reject zero-sized maps
Date: Sat, 18 Jul 2026 12:21:55 +0800 [thread overview]
Message-ID: <20260718042155.31020-1-liu.yun@linux.dev> (raw)
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
next reply other threads:[~2026-07-18 4:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 4:21 Jackie Liu [this message]
2026-07-18 4:56 ` [PATCH] lib: cpu_rmap: reject zero-sized maps Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260718042155.31020-1-liu.yun@linux.dev \
--to=liu.yun@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.