Skip to contentSkip to conversation

lib/interval_tree: fix allocation warning messages

PATCH Applied Karl Mehltretter 3 participants 4 messages Aug 8 – Aug 9 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/interval_tree: fix allocation warning messages

WARN_ON_ONCE() takes a condition, not a message. The string literals are always true, so the warnings still trigger but the messages are never printed.

Use WARN_ONCE(1, ...) instead to print the messages and keep the once-only behavior.

Found with a Coccinelle script. Clang's -Wstring-conversion also flags such calls but is not enabled in kernel builds.

Fixes 82114e45131f ("lib/interval_tree: add test case for interval_tree_iter_xxx() helpers")
Assisted-by Claude:claude-fable-5 coccinelle
---
 lib/interval_tree_test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/interval_tree_test.c +2 -2
index eba2d3e28980..b0b07270ce7c 100644
@@ -140,13 +140,13 @@ static int intersection_range_check(void)
 
 	intxn1 = bitmap_alloc(nnodes, GFP_KERNEL);
 	if (!intxn1) {
-		WARN_ON_ONCE("Failed to allocate intxn1\n");
+		WARN_ONCE(1, "Failed to allocate intxn1\n");
 		return -ENOMEM;
 	}
 
 	intxn2 = bitmap_alloc(nnodes, GFP_KERNEL);
 	if (!intxn2) {
-		WARN_ON_ONCE("Failed to allocate intxn2\n");
+		WARN_ONCE(1, "Failed to allocate intxn2\n");
 		bitmap_free(intxn1);
 		return -ENOMEM;
 	}
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer
#1 lore raw
Quoted 6 lines · On Sat, 8 Aug 2026 14:36:08 +0200 Karl Mehltretter <[email protected]>…

WARN_ON_ONCE() takes a condition, not a message. The string literals are always true, so the warnings still trigger but the messages are never printed.

Use WARN_ONCE(1, ...) instead to print the messages and keep the once-only behavior.

lol, OK, thanks.

	fgrep -r 'WARN_ON_ONCE("' .

finds more.

#2 lore raw
Quoted 6 lines · Andrew Morton

lol, OK, thanks.

	fgrep -r 'WARN_ON_ONCE("' .

finds more.

Indeed! I already sent patches for the other instances to their respective maintainers.

Thanks,
Karl

Reviewed-by on v1 1/1
#3 lore raw
In reply to Karl Mehltretter
Quoted 7 lines · Karl Mehltretter

WARN_ON_ONCE() takes a condition, not a message. The string literals are always true, so the warnings still trigger but the messages are never printed.

Use WARN_ONCE(1, ...) instead to print the messages and keep the once-only behavior.

Quoted 6 lines

Found with a Coccinelle script. Clang's -Wstring-conversion also flags such calls but is not enabled in kernel builds.

Fixes 82114e45131f ("lib/interval_tree: add test case for interval_tree_iter_xxx() helpers")
Assisted-by Claude:claude-fable-5 coccinelle

Oops, thanks for fixing it.

Quoted 26 lines

---
lib/interval_tree_test.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
lib/interval_tree_test.c +2 -2
index eba2d3e28980..b0b07270ce7c 100644
@@ -140,13 +140,13 @@ static int intersection_range_check(void)
 
 	intxn1 = bitmap_alloc(nnodes, GFP_KERNEL);
 	if (!intxn1) {
-		WARN_ON_ONCE("Failed to allocate intxn1\n");
+		WARN_ONCE(1, "Failed to allocate intxn1\n");
 		return -ENOMEM;
 	}
 
 	intxn2 = bitmap_alloc(nnodes, GFP_KERNEL);
 	if (!intxn2) {
-		WARN_ON_ONCE("Failed to allocate intxn2\n");
+		WARN_ONCE(1, "Failed to allocate intxn2\n");
 		bitmap_free(intxn1);
 		return -ENOMEM;
 	}
Signature · 1 line
2.39.5 (Apple Git-154)
Signature · 2 lines
Wei Yang
Help you, Help me