summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-08-01 20:18:33 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-08-01 22:13:03 -0400
commit87179c7a6e2a210ea57951d444a3055e883d08fa (patch)
tree3445e8b5d6724518cbc6f659f9d0b0ff59b08bfa /include/linux
parent2d7982de784b24e24baa20eee0a97dea451b8fa7 (diff)
Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/kernel.h3
-rw-r--r--include/linux/math.h15
-rw-r--r--include/linux/rhashtable.h3
-rw-r--r--include/linux/slab.h12
4 files changed, 27 insertions, 6 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 01466c40..35a7207e 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -13,6 +13,9 @@
#include <linux/compiler.h>
#include <linux/math.h>
+#define BIT(nr) (1UL << (nr))
+#define BIT_ULL(nr) (1ULL << (nr))
+
#define __ARG_PLACEHOLDER_1 0,
#define __take_second_arg(__ignored, val, ...) val
diff --git a/include/linux/math.h b/include/linux/math.h
index db7cdd23..85c8c8aa 100644
--- a/include/linux/math.h
+++ b/include/linux/math.h
@@ -153,4 +153,19 @@ static inline u32 int_sqrt64(u64 x)
}
#endif
+#define abs(x) __abs_choose_expr(x, long long, \
+ __abs_choose_expr(x, long, \
+ __abs_choose_expr(x, int, \
+ __abs_choose_expr(x, short, \
+ __abs_choose_expr(x, char, \
+ __builtin_choose_expr( \
+ __builtin_types_compatible_p(typeof(x), char), \
+ (char)({ signed char __x = (x); __x<0?-__x:__x; }), \
+ ((void)0)))))))
+
+#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \
+ __builtin_types_compatible_p(typeof(x), signed type) || \
+ __builtin_types_compatible_p(typeof(x), unsigned type), \
+ ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
+
#endif /* _LINUX_MATH_H */
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index adeef329..1c6dbdc8 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -27,9 +27,6 @@
#include <linux/rculist.h>
#include <linux/bit_spinlock.h>
-#define BIT(nr) (1UL << (nr))
-#define BIT_ULL(nr) (1ULL << (nr))
-
#include <linux/rhashtable-types.h>
/*
* Objects in an rhashtable have an embedded struct rhash_head
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 78f906a8..25ccf1a7 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -80,9 +80,15 @@ static inline void *krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t
}
#define kzalloc(size, flags) kmalloc(size, flags|__GFP_ZERO)
-#define kmalloc_array(n, size, flags) \
- ((size) != 0 && (n) > SIZE_MAX / (size) \
- ? NULL : kmalloc((n) * (size), flags))
+
+static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
+{
+ size_t bytes;
+
+ if (unlikely(check_mul_overflow(n, size, &bytes)))
+ return NULL;
+ return kmalloc(bytes, flags);
+}
#define kvmalloc_array(n, size, flags) \
((size) != 0 && (n) > SIZE_MAX / (size) \