Linux Sound subsystem development
 help / color / mirror / Atom feed
From: xiaopeitux@foxmail.com
To: ivan.orlov0322@gmail.com, perex@perex.cz, tiwai@suse.com,
	linux-sound@vger.kernel.org
Cc: Pei Xiao <xiaopei01@kylinos.cn>, kernel test robot <lkp@intel.com>
Subject: [PATCH] ALSA: kunit: fix build warning in test_card_set_id
Date: Mon,  7 Apr 2025 17:21:36 +0800	[thread overview]
Message-ID: <tencent_7F01F2D14BF724692ECBF5346283DB9BCA05@qq.com> (raw)

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


             reply	other threads:[~2025-04-07  9:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07  9:21 xiaopeitux [this message]
2025-04-07 15:40 ` [PATCH] ALSA: kunit: fix build warning in test_card_set_id Takashi Iwai
2025-04-08  9:48   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_7F01F2D14BF724692ECBF5346283DB9BCA05@qq.com \
    --to=xiaopeitux@foxmail.com \
    --cc=ivan.orlov0322@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=xiaopei01@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox