diff options
author | Jean-Sébastien Pédron <dumbbell@FreeBSD.org> | 2022-11-11 17:37:34 +0000 |
---|---|---|
committer | Jean-Sébastien Pédron <dumbbell@FreeBSD.org> | 2022-11-11 17:37:34 +0000 |
commit | 1ad6b2b1daa8937b2e1ced43802adba5734ba92b (patch) | |
tree | a093396a536ca3b72abf97ed3652d29ba349e457 /sys/compat | |
parent | 0b8a423d073309ab5f24501c2f6b3f6b2cd8f422 (diff) | |
download | src-1ad6b2b1daa8937b2e1ced43802adba5734ba92b.tar.gz src-1ad6b2b1daa8937b2e1ced43802adba5734ba92b.zip |
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
Diffstat (limited to 'sys/compat')
-rw-r--r-- | sys/compat/linuxkpi/common/include/linux/slab.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/slab.h b/sys/compat/linuxkpi/common/include/linux/slab.h index 16b5afcea693..8f1cb433c36b 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 |