misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>.
Use the new math_extras functions instead of calling builtins directly.
Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.
Signed-off-by: Jakob Olesen <jolesen@fb.com>
diff --git a/kernel/mempool.c b/kernel/mempool.c
index a611e4b..f124447 100644
--- a/kernel/mempool.c
+++ b/kernel/mempool.c
@@ -10,6 +10,7 @@
#include <init.h>
#include <string.h>
#include <misc/__assert.h>
+#include <misc/math_extras.h>
#include <stdbool.h>
/* Linker-defined symbols bound the static pool structs */
@@ -144,8 +145,7 @@
* get a block large enough to hold an initial (hidden) block
* descriptor, as well as the space the caller requested
*/
- if (__builtin_add_overflow(size, sizeof(struct k_mem_block_id),
- &size)) {
+ if (size_add_overflow(size, sizeof(struct k_mem_block_id), &size)) {
return NULL;
}
if (k_mem_pool_alloc(pool, &block, size, K_NO_WAIT) != 0) {
@@ -193,7 +193,7 @@
void *ret;
size_t bounds;
- if (__builtin_mul_overflow(nmemb, size, &bounds)) {
+ if (size_mul_overflow(nmemb, size, &bounds)) {
return NULL;
}