ALSA: kunit: fix build warning in test_card_set_id
Subsystems (2)
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
@@ -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
Takashi Iwai
AppliedQuoted 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->idcould be NULL. Thekunit_info()call with "%s" format specifier may receive a NULL pointer fromcard->id. Add a ternary conditional to safely handle potential NULL values by substituting "(null)" whencard->idis NULL.Reported-by kernel test robot <[email protected]>Signed-off-by Pei Xiao <[email protected]>
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
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->idcould be NULL. Thekunit_info()call with "%s" format specifier may receive a NULL pointer fromcard->id. Add a ternary conditional to safely handle potential NULL values by substituting "(null)" whencard->idis NULL.
Quoted 8 lines
Quoted 3 lines
Reported-by kernel test robot <[email protected]>Signed-off-by Pei Xiao <[email protected]>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