[PATCH] x86/boot: fix boot decompressor malloc() prototype for GCC builtins Signed-off-by: redacherkaoui <redacherkaoui67@gmail.com>

redacherkaoui posted 1 patch 1 month, 1 week ago
arch/x86/boot/compressed/misc.h | 11 ++++++++++-
include/linux/decompress/mm.h   | 10 +++++++---
2 files changed, 17 insertions(+), 4 deletions(-)
[PATCH] x86/boot: fix boot decompressor malloc() prototype for GCC builtins Signed-off-by: redacherkaoui <redacherkaoui67@gmail.com>
Posted by redacherkaoui 1 month, 1 week ago
---
 arch/x86/boot/compressed/misc.h | 11 ++++++++++-
 include/linux/decompress/mm.h   | 10 +++++++---
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index 4f86c5903e03..de36a2dbd096 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -61,7 +61,16 @@ extern char _head[], _end[];
 extern memptr free_mem_ptr;
 extern memptr free_mem_end_ptr;
 extern int spurious_nmi_count;
-void *malloc(int size);
+
+/*
+ * boot/compressed uses the tiny allocator from include/linux/decompress/mm.h.
+ * Name is "malloc" but it is *not* libc malloc().
+ *
+ * Keep this prototype in sync with mm.h. Use unsigned long to match the
+ * compiler builtin signature on x86_64 (size_t == unsigned long).
+ */
+void *malloc(unsigned long size);
+
 void free(void *where);
 void __putstr(const char *s);
 void __puthex(unsigned long value);
diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
index ac862422df15..af506c40032e 100644
--- a/include/linux/decompress/mm.h
+++ b/include/linux/decompress/mm.h
@@ -39,12 +39,16 @@
 STATIC_RW_DATA unsigned long malloc_ptr;
 STATIC_RW_DATA int malloc_count;
 
-MALLOC_VISIBLE void *malloc(int size)
+MALLOC_VISIBLE void *malloc(unsigned long size)
 {
 	void *p;
 
-	if (size < 0)
-		return NULL;
+	/*
+	 * This is a tiny pre-boot allocator; callers should never pass a
+	 * negative size. Use an unsigned type to match compiler builtin
+	 * expectations (size_t on x86_64 is unsigned long) and avoid
+	 * -Wbuiltin-declaration-mismatch under -Werror.
+	 */
 	if (!malloc_ptr)
 		malloc_ptr = free_mem_ptr;
 
-- 
2.43.0