Skip to contentSkip to conversation

ALSA: kunit: fix build warning in test_card_set_id

PATCH Applied [email protected] 2 participants 3 messages Apr 7, 2025 – Apr 8, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: kunit: fix build warning in test_card_set_id

From: Pei Xiao <[email protected]>

build W=1 warning:
sound/core/sound_kunit.c: In function 'test_card_set_id':
include/linux/printk.h:455:44: warning: '%s' directive argument is null [-Wformat-overflow=]

Fix -Wformat-overflow warning when card->id could be NULL. The kunit_info() call with "%s" format specifier may receive a NULL pointer from card->id. Add a ternary conditional to safely handle potential NULL values by substituting "(null)" when card->id is NULL.

---
 sound/core/sound_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/sound_kunit.c +1 -1
index 84e337ecbddd..56c463f43592 100644
@@ -268,7 +268,7 @@ static void test_card_set_id(struct kunit *test)
 
 	card->id[0] = '\0';
 	snd_card_set_id(card, NAME_W_SPACE);
-	kunit_info(test, "%s", card->id);
+	kunit_info(test, "%s", card->id ? card->id : "(null)");
 	KUNIT_EXPECT_STREQ(test, card->id, NAME_W_SPACE_REMOVED);
 }
 
Signature · 1 line
2.25.1
Applied
#1 lore raw
Quoted 7 lines · On Mon, 07 Apr 2025 11:21:36 +0200, [email protected] wrote:

From: Pei Xiao <[email protected]>

build W=1 warning:
sound/core/sound_kunit.c: In function 'test_card_set_id':
include/linux/printk.h:455:44: warning: '%s' directive argument is null [-Wformat-overflow=]

Quoted 8 lines

Fix -Wformat-overflow warning when card->id could be NULL. The kunit_info() call with "%s" format specifier may receive a NULL pointer from card->id. Add a ternary conditional to safely handle potential NULL values by substituting "(null)" when card->id is NULL.

Thanks, applied now. I added Fixes tag manually (Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test"))

But at the next time, please try to put the proper Fixes tag.

Takashi

#2 lore raw
Quoted 15 lines · Takashi Iwai
Quoted 12 lines · On Mon, 07 Apr 2025 11:21:36 +0200, [email protected] wrote:

From: Pei Xiao <[email protected]>

build W=1 warning:
sound/core/sound_kunit.c: In function 'test_card_set_id':
include/linux/printk.h:455:44: warning: '%s' directive argument is null [-Wformat-overflow=]

Fix -Wformat-overflow warning when card->id could be NULL. The kunit_info() call with "%s" format specifier may receive a NULL pointer from card->id. Add a ternary conditional to safely handle potential NULL values by substituting "(null)" when card->id is NULL.

Quoted 8 lines
Quoted 3 lines

Thanks, applied now. I added Fixes tag manually (Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test"))

But at the next time, please try to put the proper Fixes tag.

... and as 0day bot spotted out, this fix is bogus. snd_card.id is an embedded array, and can be never NULL.

I drop the patch now.

Takashi