git: e1534bafdab9 - stable/13 - linuxkpi: Add `krealloc_array()`
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 24 Jan 2023 08:53:57 UTC
The branch stable/13 has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=e1534bafdab9c09f82b4a2bc429e5bf81fac75fb commit e1534bafdab9c09f82b4a2bc429e5bf81fac75fb Author: Jean-Sébastien Pédron <dumbbell@FreeBSD.org> AuthorDate: 2022-11-11 17:37:34 +0000 Commit: Emmanuel Vadot <manu@FreeBSD.org> CommitDate: 2023-01-24 09:08:00 +0000 linuxkpi: Add `krealloc_array()` In FreeBSD, this is a wrapper on top of `realloc()`. V2: Check if `n * size` would overflow and return `NULL` if that's the case. Suggested by hselasky@ and emaste@. Reviewed by: manu Approved by: manu Differential Revision: https://reviews.freebsd.org/D36959 (cherry picked from commit 1ad6b2b1daa8937b2e1ced43802adba5734ba92b) --- sys/compat/linuxkpi/common/include/linux/slab.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h index 7d590683f346..d76b376c01a2 100644 --- a/sys/compat/linuxkpi/common/include/linux/slab.h +++ b/sys/compat/linuxkpi/common/include/linux/slab.h @@ -178,6 +178,16 @@ krealloc(void *ptr, size_t size, gfp_t flags) return (realloc(ptr, size, M_KMALLOC, linux_check_m_flags(flags))); } +static inline void * +krealloc_array(void *ptr, size_t n, size_t size, gfp_t flags) +{ + if (WOULD_OVERFLOW(n, size)) { + return NULL; + } + + return (realloc(ptr, n * size, M_KMALLOC, linux_check_m_flags(flags))); +} + extern void linux_kfree_async(void *); static inline void