public inbox for linux-sparse@vger.kernel.org
 help / color / mirror / Atom feed
* Sparse not supporting kzalloc_obj() and friends
@ 2026-02-23 10:51 Ricardo Ribalda
  2026-02-23 16:19 ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Ricardo Ribalda @ 2026-02-23 10:51 UTC (permalink / raw)
  To: linux-sparse, Chris Li; +Cc: Hans Verkuil

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-25  3:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 10:51 Sparse not supporting kzalloc_obj() and friends Ricardo Ribalda
2026-02-23 16:19 ` Linus Torvalds
2026-02-23 16:35   ` Linus Torvalds
2026-02-23 17:20     ` Ricardo Ribalda
2026-02-23 18:02       ` Linus Torvalds
2026-02-25  3:51     ` Al Viro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox