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
This commit is contained in:
Jean-Sébastien Pédron 2022-11-11 18:37:34 +01:00
parent 0b8a423d07
commit 1ad6b2b1da
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC

View File

@ -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