| Message ID | 20260120112938.463596-1-iamhswang@gmail.com |
|---|---|
| State | Changes Requested |
| Headers | show |
| Series | [1/2] um: add uml_kmalloc_array() helper to avoid potential | expand |
On Tue, 2026-01-20 at 19:28 +0800, iamhswang@gmail.com wrote: > 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. Personally, I think it's kind of pointless because the only two users have small static arguments ... but if you want to continue with this then > > +extern void *uml_kmalloc_array(int count, int size, int flags); the prototype should probably match better and use size_t, size_t, unsigned int? johannes
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,