Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ALSA: kunit: fix build warning in test_card_set_id
@ 2025-04-07  9:21 xiaopeitux
  2025-04-07 15:40 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: xiaopeitux @ 2025-04-07  9:21 UTC (permalink / raw)
  To: ivan.orlov0322, perex, tiwai, linux-sound; +Cc: Pei Xiao, kernel test robot

From: Pei Xiao <xiaopei01@kylinos.cn>

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.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202504050922.ZzbkiojG-lkp@intel.com/
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 sound/core/sound_kunit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/core/sound_kunit.c b/sound/core/sound_kunit.c
index 84e337ecbddd..56c463f43592 100644
--- a/sound/core/sound_kunit.c
+++ b/sound/core/sound_kunit.c
@@ -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);
 }
 
-- 
2.25.1


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

end of thread, other threads:[~2025-04-08  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07  9:21 [PATCH] ALSA: kunit: fix build warning in test_card_set_id xiaopeitux
2025-04-07 15:40 ` Takashi Iwai
2025-04-08  9:48   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox