Sparse not supporting kzalloc_obj() and friends
Ricardo Ribalda <[email protected]> Mon, 23 Feb 2026 11:51:56 +0100
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <CANiDSCuKGUNdT4f9tOuohe2wZeP4MmooJAJn2Q=oyAWL4v9Lng@mail.gmail.com> |
Hi
In media-ci we use sparse for static analyzing the new changes in the
media subsystem.
Since 7.0rc1 sparse is failing with errors such as the one at the end
of this email.
The culprit seems to be the new kzalloc_obj and friends.
I have been trying to add this as a workaround:
$ git diff predefine.c
diff --git a/predefine.c b/predefine.c
index c6750831..821100a2 100644
--- a/predefine.c
+++ b/predefine.c
@@ -208,6 +208,16 @@ void predefined_macros(void)
predefine("__extension__", 0, NULL);
predefine("__pragma__", 0, NULL);
+ add_pre_buffer("#strong_define kzalloc_obj(type)
kzalloc(sizeof(type), GFP_KERNEL)\n");
+ add_pre_buffer("#strong_define kzalloc_objs(type, n)
kzalloc(sizeof(type) * (n), GFP_KERNEL)\n");
+ add_pre_buffer("#strong_define kmalloc_obj(type)
kmalloc(sizeof(type), GFP_KERNEL)\n");
+ add_pre_buffer("#strong_define kvmalloc_obj(type)
kvmalloc(sizeof(type), GFP_KERNEL)\n");
+ add_pre_buffer("#strong_define kmalloc_obj(type, flags)
kmalloc(sizeof(type), flags)\n");
+ add_pre_buffer("#strong_define kmalloc_objs(type, n)
kmalloc(sizeof(type) * (n), flags)\n");
+ add_pre_buffer("#strong_define kvzalloc_objs(type, n)
kvzalloc(sizeof(type) * (n), flags)\n");
+ add_pre_buffer("#strong_define kvzalloc(type)
kvzalloc(sizeof(type), flags)\n");
+ add_pre_buffer("#strong_define kzalloc_flex(type, pos, n,
flags) kzalloc(sizeof(type), flags)\n");
+
switch (arch_m64) {
case ARCH_LP32:
break;
But it is a dirty hack and the fact that the macros support
"polymorphisms" makes it even uglier...
I have been Googling a bit, and I cannot find anyone else complaining
about this... which I find a bit weird.
Am I holding it wrong?
Thanks!
$ make -i W=1 C=1 CHECK="../media-ci/third_party/sparse/sparse"
drivers/media/i2c/tda1997x.o
CC scripts/mod/empty.o
CHECK scripts/mod/empty.c
MKELF scripts/mod/elfconfig.h
HOSTCC scripts/mod/modpost.o
CC scripts/mod/devicetable-offsets.s
HOSTCC scripts/mod/file2alias.o
HOSTCC scripts/mod/sumversion.o
HOSTCC scripts/mod/symsearch.o
HOSTLD scripts/mod/modpost
CC kernel/bounds.s
CC arch/x86/kernel/asm-offsets.s
CC kernel/sched/rq-offsets.s
CALL scripts/checksyscalls.sh
DESCEND objtool
INSTALL libsubcmd_headers
CC drivers/media/i2c/tda1997x.o
CHECK drivers/media/i2c/tda1997x.c
drivers/media/i2c/tda1997x.c: note: in included file (through
include/linux/i2c.h):
./include/linux/acpi.h:69:18: error: Expected ) in function call
./include/linux/acpi.h:69:18: error: got ,
./include/linux/acpi.h:69:18: error: Expected ) in function call
./include/linux/acpi.h:69:18: error: got ,
./include/linux/acpi.h:69:18: error: Expected ) in function call
./include/linux/acpi.h:69:18: error: got ,
drivers/media/i2c/tda1997x.c: note: in included file (through
include/media/v4l2-common.h, include/media/v4l2-subdev.h,
include/media/v4l2-device.h):
./include/linux/spi/spi.h:1312:15: error: Expected ) in function call
./include/linux/spi/spi.h:1312:15: error: got __VA_OPT__
./include/linux/spi/spi.h:1312:15: error: Expected ) in function call
./include/linux/spi/spi.h:1312:15: error: got __VA_OPT__
./include/linux/spi/spi.h:1312:15: error: Expected ) in function call
./include/linux/spi/spi.h:1312:15: error: got __VA_OPT__
drivers/media/i2c/tda1997x.c:2541:17: error: Expected ) in function call
drivers/media/i2c/tda1997x.c:2541:17: error: got ,
drivers/media/i2c/tda1997x.c:2541:17: error: Expected ) in function call
drivers/media/i2c/tda1997x.c:2541:17: error: got ,
drivers/media/i2c/tda1997x.c:2541:17: error: Expected ) in function call
drivers/media/i2c/tda1997x.c:2541:17: error: got ,
drivers/media/i2c/tda1997x.c:2541:17: error: undefined identifier '_res'
drivers/media/i2c/tda1997x.c:2541:17: error: undefined identifier '__VA_OPT__'
drivers/media/i2c/tda1997x.c:2541:17: error: undefined identifier '_res'
drivers/media/i2c/tda1997x.c:2541:17: error: undefined identifier '__VA_OPT__'
drivers/media/i2c/tda1997x.c:2541:17: error: undefined identifier '_res'
--
Ricardo Ribalda