]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools/testing: fix testing/vma and testing/radix-tree build
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Wed, 25 Feb 2026 23:31:11 +0000 (01:31 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 4 Mar 2026 17:44:22 +0000 (09:44 -0800)
Build of VMA and radix-tree tests is unhappy after the conversion of
kzalloc() to kzalloc_obj() in lib/idr.c:

  cc -I../shared -I. -I../../include -I../../arch/x86/include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined  -DNUM_VMA_FLAG_BITS=128 -DNUM_MM_FLAG_BITS=128   -c -o idr.o idr.c
  idr.c: In function `ida_alloc_range':
  idr.c:420:34: error: implicit declaration of function `kzalloc_obj'; did you mean `kzalloc_node'? [-Wimplicit-function-declaration]
    420 |                         bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT);
        |                                  ^~~~~~~~~~~
        |                                  kzalloc_node
  idr.c:420:32: error: assignment to `struct ida_bitmap *' from `int' makes pointer from integer without a cast [-Wint-conversion]
    420 |                         bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT);
        |                                ^
  idr.c:447:40: error: assignment to `struct ida_bitmap *' from `int' makes pointer from integer without a cast [-Wint-conversion]
    447 |                                 bitmap = kzalloc_obj(*bitmap, GFP_NOWAIT);
        |                                        ^
  idr.c:468:15: error: assignment to `struct ida_bitmap *' from `int' makes pointer from integer without a cast [-Wint-conversion]
    468 |         alloc = kzalloc_obj(*bitmap, gfp);
        |               ^
  make: *** [<builtin>: idr.o] Error 1

Import necessary macros from include/linux to tools/include/linux to fix
the compilation.

Link: https://lkml.kernel.org/r/20260225233111.2760752-1-rppt@kernel.org
Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Tested-by: SeongJae Park <sj@kernel.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
tools/include/linux/gfp.h
tools/include/linux/overflow.h
tools/include/linux/slab.h

index 6a10ff5f5be9070cce7130e62f723e4ecb0a1994..9e957b57b694511ee5c6177362167c6b1f9d56f6 100644 (file)
@@ -5,6 +5,10 @@
 #include <linux/types.h>
 #include <linux/gfp_types.h>
 
+/* Helper macro to avoid gfp flags if they are the default one */
+#define __default_gfp(a,...) a
+#define default_gfp(...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL)
+
 static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
 {
        return !!(gfp_flags & __GFP_DIRECT_RECLAIM);
index dcb0c1bf686605ea68ab4701340d537b111a746b..3427d788032641cd2af3cedcbbf9cd8316c9f301 100644 (file)
        __builtin_mul_overflow(__a, __b, __d);  \
 })
 
+/**
+ * size_mul() - Calculate size_t multiplication with saturation at SIZE_MAX
+ * @factor1: first factor
+ * @factor2: second factor
+ *
+ * Returns: calculate @factor1 * @factor2, both promoted to size_t,
+ * with any overflow causing the return value to be SIZE_MAX. The
+ * lvalue must be size_t to avoid implicit type conversion.
+ */
+static inline size_t __must_check size_mul(size_t factor1, size_t factor2)
+{
+       size_t bytes;
+
+       if (check_mul_overflow(factor1, factor2, &bytes))
+               return SIZE_MAX;
+
+       return bytes;
+}
+
 /**
  * array_size() - Calculate size of 2-dimensional array.
  *
index 94937a699402bd1f31887dfb52b6fd0a3c986f43..6d8e9413d5a4d73b3d4d381cdd543556ce70071d 100644 (file)
@@ -202,4 +202,13 @@ static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf)
        return sheaf->size;
 }
 
+#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT)                                \
+({                                                                     \
+       const size_t __obj_size = size_mul(sizeof(TYPE), COUNT);        \
+       (TYPE *)KMALLOC(__obj_size, GFP);                               \
+})
+
+#define kzalloc_obj(P, ...) \
+       __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
+
 #endif         /* _TOOLS_SLAB_H */