public inbox for linux-um@lists.infradead.org
 help / color / mirror / Atom feed
From: iamhswang@gmail.com
To: richard@nod.at, anton.ivanov@cambridgegreys.com,
	johannes@sipsolutions.net, akpm@linux-foundation.org,
	dave.hansen@linux.intel.com, tiwei.btw@antgroup.com,
	rppt@kernel.org, kevin.brodsky@arm.com, snovitoll@gmail.com,
	linux@weissschuh.net
Cc: linux-um@lists.infradead.org, linux-kernel@vger.kernel.org,
	iamhswang@gmail.com
Subject: [PATCH 1/2] um: add uml_kmalloc_array() helper to avoid potential
Date: Tue, 20 Jan 2026 19:28:54 +0800	[thread overview]
Message-ID: <20260120112938.463596-1-iamhswang@gmail.com> (raw)

From: Haisu Wang <iamhswang@gmail.com>

Add uml_kmalloc_array to avoid potential dynamic multiplication
overflow. Since in Documentation/process/deprecated.rst,
the preferred way is avoid the open-coded arithmetic.

Signed-off-by: Haisu Wang <wanghs18@chinatelecom.cn>
---
 arch/um/include/shared/um_malloc.h | 1 +
 arch/um/kernel/mem.c               | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/arch/um/include/shared/um_malloc.h b/arch/um/include/shared/um_malloc.h
index 815dd03e8707..a55a81131e10 100644
--- a/arch/um/include/shared/um_malloc.h
+++ b/arch/um/include/shared/um_malloc.h
@@ -9,6 +9,7 @@
 #include <generated/asm-offsets.h>
 
 extern void *uml_kmalloc(int size, int flags);
+extern void *uml_kmalloc_array(int count, int size, int flags);
 extern void kfree(const void *ptr);
 
 extern void *vmalloc_noprof(unsigned long size);
diff --git a/arch/um/kernel/mem.c b/arch/um/kernel/mem.c
index 39c4a7e21c6f..3bf9e9bef3bf 100644
--- a/arch/um/kernel/mem.c
+++ b/arch/um/kernel/mem.c
@@ -126,6 +126,11 @@ void *uml_kmalloc(int size, int flags)
 	return kmalloc(size, flags);
 }
 
+void *uml_kmalloc_array(int count, int size, int flags)
+{
+	return kmalloc_array(count, size, flags);
+}
+
 static const pgprot_t protection_map[16] = {
 	[VM_NONE]					= PAGE_NONE,
 	[VM_READ]					= PAGE_READONLY,
-- 
2.52.0



             reply	other threads:[~2026-01-20 11:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 11:28 iamhswang [this message]
2026-01-20 11:28 ` [PATCH 2/2] um: use uml_kmalloc_array() instead of uml_malloc() iamhswang

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=20260120112938.463596-1-iamhswang@gmail.com \
    --to=iamhswang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=kevin.brodsky@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=linux@weissschuh.net \
    --cc=richard@nod.at \
    --cc=rppt@kernel.org \
    --cc=snovitoll@gmail.com \
    --cc=tiwei.btw@antgroup.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox