All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/1] compiler_types.h: introduce ASSUME_NONNULL macro for static analysis
@ 2025-07-23 14:01 Raka Gunarto
  2025-07-23 14:03 ` [RFC PATCH 1/1] " Raka Gunarto
  2025-07-25 10:34 ` Fwd: [RFC PATCH 0/1] " Raka Gunarto
  0 siblings, 2 replies; 10+ messages in thread
From: Raka Gunarto @ 2025-07-23 14:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: Raka Gunarto

This proposed patch introduces a new macro ASSUME_NONNULL to suppress false
positives of null pointer dereference warnings during static analysis.

The patch only includes the macro definition for Clang so far, as I could
not silence GCC's static analyzer false positives without ensuring that
it wouldn't affect the emitted code.

I tested this patch and use of the macro successfully eliminates false
positives when used properly and does not affect final code generation.

I am new to contributing to the kernel, so I apologise in advance for
any mistakes. I welcome all feedback or suggestions for improvement.

Rationale:
- Use of this optional macro can silence false positives which may reduce
  patches that fix false positives (such as AI generated patches).
- Clear documentation of a non null assumption for other developers
- Signal to reviewers to subject patches that use this macro to
  additional scrutiny, and require justification on why
  there isn't a null check in the code instead.

Motivation:
While running Clang's static analyzer on the Linux kernel, I encountered
hundreds of false positives related to null pointer dereferences.
One such example is in mm/slub.c, where the static analyzer
incorrectly reports a potential null pointer dereference on line 3169.

n is non-null at that point, but it is non obvious to the static analyzer
(and to humans) that get_node() will always return a non-null pointer.
Since it is in a performance crtical context, adding a null check
would be undesirable (I think). A macro like this can be used to
signal the pointer is invariably non-null, without adding a runtime
check.

Raka Gunarto (1):
  compiler_types.h: introduce ASSUME_NONNULL macro for static analysis

 include/linux/compiler-clang.h | 10 ++++++++++
 include/linux/compiler_types.h |  5 +++++
 2 files changed, 15 insertions(+)

--
2.43.0


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

end of thread, other threads:[~2025-07-25 17:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-23 14:01 [RFC PATCH 0/1] compiler_types.h: introduce ASSUME_NONNULL macro for static analysis Raka Gunarto
2025-07-23 14:03 ` [RFC PATCH 1/1] " Raka Gunarto
2025-07-25 10:34 ` Fwd: [RFC PATCH 0/1] " Raka Gunarto
2025-07-25 12:06   ` Greg KH
2025-07-25 12:18   ` Mulyadi Santosa
2025-07-25 12:42     ` Raka Gunarto
2025-07-25 13:28       ` Siddh Raman Pant
2025-07-25 13:56       ` Greg KH
2025-07-25 15:07         ` Raka Gunarto
2025-07-25 17:04           ` Tom Mitchell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.