lib/decompress_unxz.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Align to the commit bf4afc53b77a ("Convert 'alloc_obj' family to use the new default GFP_KERNEL argument")
update the 'kmalloc_obj' declaration for userspace to fix below comiple error:
In file included from arch/arm/boot/compressed/../../../../lib/decompress_unxz.c:241,
from arch/arm/boot/compressed/decompress.c:56:
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_stream.c: In function 'xz_dec_init':
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_stream.c:787:28: error: implicit declaration of function 'kmalloc_obj'; did you mean 'kmalloc'? [-Wimplicit-function-declaration]
787 | struct xz_dec *s = kmalloc_obj(*s);
| ^~~~~~~~~~~
| kmalloc
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_stream.c:787:28: error: initialization of 'struct xz_dec *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
arch/arm/boot/compressed/../../../../lib/decompress_unxz.c:242:
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_lzma2.c: In function 'xz_dec_lzma2_create':
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_lzma2.c:1141:34: error: initialization of 'struct xz_dec_lzma2 *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
1141 | struct xz_dec_lzma2 *s = kmalloc_obj(*s);
| ^~~~~~~~~~~
arch/arm/boot/compressed/../../../../lib/decompress_unxz.c:243:
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_bcj.c: In function 'xz_dec_bcj_create':
arch/arm/boot/compressed/../../../../lib/xz/xz_dec_bcj.c:594:32: error: initialization of 'struct xz_dec_bcj *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
594 | struct xz_dec_bcj *s = kmalloc_obj(*s);
| ^~~~~~~~~~~
CC arch/arm/boot/compressed/fdt.o
Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Signed-off-by: Haiyue Wang <haiyuewa@163.com>
---
lib/decompress_unxz.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c
index 32138bb8ef77..05d5cb490a44 100644
--- a/lib/decompress_unxz.c
+++ b/lib/decompress_unxz.c
@@ -157,11 +157,11 @@
* when XZ_DYNALLOC is used, but the pre-boot free() doesn't support it.
* Workaround it here because the other decompressors don't need it.
*/
-#undef kmalloc
+#undef kmalloc_obj
#undef kfree
#undef vmalloc
#undef vfree
-#define kmalloc(size, flags) malloc(size)
+#define kmalloc_obj(type) malloc(sizeof(type))
#define kfree(ptr) free(ptr)
#define vmalloc(size) malloc(size)
#define vfree(ptr) do { if (ptr != NULL) free(ptr); } while (0)
--
2.53.0
On Sun, Feb 22, 2026 at 08:11:00PM +0800, Haiyue Wang wrote:
> Align to the commit bf4afc53b77a ("Convert 'alloc_obj' family to use the new default GFP_KERNEL argument")
> update the 'kmalloc_obj' declaration for userspace to fix below comiple error:
>
> In file included from arch/arm/boot/compressed/../../../../lib/decompress_unxz.c:241,
> from arch/arm/boot/compressed/decompress.c:56:
> arch/arm/boot/compressed/../../../../lib/xz/xz_dec_stream.c: In function 'xz_dec_init':
> arch/arm/boot/compressed/../../../../lib/xz/xz_dec_stream.c:787:28: error: implicit declaration of function 'kmalloc_obj'; did you mean 'kmalloc'? [-Wimplicit-function-declaration]
> 787 | struct xz_dec *s = kmalloc_obj(*s);
> | ^~~~~~~~~~~
> | kmalloc
> [...]
> CC arch/arm/boot/compressed/fdt.o
Which config & build target was this exposed by? I don't see it with
either "all" nor "zImage" for defconfig (which includes CONFIG_RD_XZ)
nor allmodconfig, and I see arch/arm/boot/compressed/fdt.o getting built.
Okay, I traced down the includes now, it looks like it's tripped by
CONFIG_KERNEL_XZ=y, which isn't in defconfig nor allmodconfig. :(
> Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
Also:
Fixes: bf4afc53b77a ("Convert 'alloc_obj' family to use the new default GFP_KERNEL argument")
> Signed-off-by: Haiyue Wang <haiyuewa@163.com>
> ---
> lib/decompress_unxz.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/decompress_unxz.c b/lib/decompress_unxz.c
> index 32138bb8ef77..05d5cb490a44 100644
> --- a/lib/decompress_unxz.c
> +++ b/lib/decompress_unxz.c
> @@ -157,11 +157,11 @@
> * when XZ_DYNALLOC is used, but the pre-boot free() doesn't support it.
> * Workaround it here because the other decompressors don't need it.
> */
> -#undef kmalloc
> +#undef kmalloc_obj
> #undef kfree
> #undef vmalloc
> #undef vfree
> -#define kmalloc(size, flags) malloc(size)
> +#define kmalloc_obj(type) malloc(sizeof(type))
It may be worth defining this as:
#define kmalloc_obj(type, ...) malloc(sizeof(type))
In case some non-GFP_KERNEL ever end up in here.
Either way:
Reviewed-by: Kees Cook <kees@kernel.org>
--
Kees Cook
On 2026-02-22 Haiyue Wang wrote:
> Align to the commit bf4afc53b77a ("Convert 'alloc_obj' family to use
> the new default GFP_KERNEL argument") update the 'kmalloc_obj'
> declaration for userspace to fix below comiple error:
The patch looks good. Without it, XZ-compressed kernel wouldn't build
on a few archs. The commit message could be clearer about this.
Suggestion:
----
xz: Fix the preboot code to match the kmalloc_obj change
kmalloc was replaced with kmalloc_obj in lib/xz. Make the same change
also in the preboot code to fix building of XZ-compressed kernel on
a few archs. For example, on ARM:
<the error message here>
Fixes: 69050f8d6d07 ("treewide: Replace kmalloc with kmalloc_obj for non-scalar types")
----
Thanks!
Acked-by: Lasse Collin <lasse.collin@tukaani.org>
--
Lasse Collin
© 2016 - 2026 Red Hat, Inc.