<div dir="auto"><div><br><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Jul 25, 2025, 17:47 Raka Gunarto <<a href="mailto:rakagunarto@gmail.com">rakagunarto@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone, I'm a really new contributor and I sent off this<br>
RFC to LKML <<a href="https://lore.kernel.org/lkml/20250723140129.276874-1-rakagunarto@gmail.com/T/#m1372eb992552491ac37f46f27e5ad09d9efa35ad" rel="noreferrer noreferrer" target="_blank">https://lore.kernel.org/lkml/20250723140129.276874-1-rakagunarto@gmail.com/T/#m1372eb992552491ac37f46f27e5ad09d9efa35ad</a>>,<br>
when I probably should have floated the idea<br>
here first. In any case, I've pasted my RFC patch below<br>
and I would really like any feedback / suggestions on the<br>
idea.<br>
<br>
Thanks,<br>
Raka<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Hello Raka</div><div dir="auto"><br></div><div dir="auto">Interesting idea. Other than silencing clang analyzer warning, what is exactly the advantage of using such macro?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
---------- Forwarded message ---------<br>
From: Raka Gunarto <<a href="mailto:rakagunarto@gmail.com" target="_blank" rel="noreferrer">rakagunarto@gmail.com</a>><br>
Date: Wed, Jul 23, 2025 at 3:01 PM<br>
Subject: [RFC PATCH 0/1] compiler_types.h: introduce ASSUME_NONNULL<br>
macro for static analysis<br>
To: <<a href="mailto:linux-kernel@vger.kernel.org" target="_blank" rel="noreferrer">linux-kernel@vger.kernel.org</a>><br>
Cc: Raka Gunarto <<a href="mailto:rakagunarto@gmail.com" target="_blank" rel="noreferrer">rakagunarto@gmail.com</a>><br>
<br>
<br>
This proposed patch introduces a new macro ASSUME_NONNULL to suppress false<br>
positives of null pointer dereference warnings during static analysis.<br>
<br>
The patch only includes the macro definition for Clang so far, as I could<br>
not silence GCC's static analyzer false positives without ensuring that<br>
it wouldn't affect the emitted code.<br>
<br>
I tested this patch and use of the macro successfully eliminates false<br>
positives when used properly and does not affect final code generation.<br>
<br>
I am new to contributing to the kernel, so I apologise in advance for<br>
any mistakes. I welcome all feedback or suggestions for improvement.<br>
<br>
Rationale:<br>
- Use of this optional macro can silence false positives which may reduce<br>
patches that fix false positives (such as AI generated patches).<br>
- Clear documentation of a non null assumption for other developers<br>
- Signal to reviewers to subject patches that use this macro to<br>
additional scrutiny, and require justification on why<br>
there isn't a null check in the code instead.<br>
<br>
Motivation:<br>
While running Clang's static analyzer on the Linux kernel, I encountered<br>
hundreds of false positives related to null pointer dereferences.<br>
One such example is in mm/slub.c, where the static analyzer<br>
incorrectly reports a potential null pointer dereference on line 3169.<br>
<br>
n is non-null at that point, but it is non obvious to the static analyzer<br>
(and to humans) that get_node() will always return a non-null pointer.<br>
Since it is in a performance crtical context, adding a null check<br>
would be undesirable (I think). A macro like this can be used to<br>
signal the pointer is invariably non-null, without adding a runtime<br>
check.<br>
<br>
Raka Gunarto (1):<br>
compiler_types.h: introduce ASSUME_NONNULL macro for static analysis<br>
<br>
include/linux/compiler-clang.h | 10 ++++++++++<br>
include/linux/compiler_types.h | 5 +++++<br>
2 files changed, 15 insertions(+)<br>
<br>
--<br>
2.43.0<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank" rel="noreferrer">Kernelnewbies@kernelnewbies.org</a><br>
<a href="https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer noreferrer" target="_blank">https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div></div></div>