Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: kunit: Fix sparse warnings

There were a few sparse warnings about the cast of strong-typed
snd_pcm_format_t. Fix them with cast with __force.

For spreading the ugly mess, put them in the definitions
WRONG_FORMAT_1 and WRONG_FORMAT_2 and use them in the callers.

Fixes: 3e39acf56ede ("ALSA: core: Add sound core KUnit test")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202402270303.PmvmQrJV-lkp@intel.com
Link: https://lore.kernel.org/r/20240227104912.18921-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+15 -14
+15 -14
sound/core/sound_kunit.c
··· 17 17 .name = #fmt, \ 18 18 } 19 19 20 - #define WRONG_FORMAT (SNDRV_PCM_FORMAT_LAST + 1) 20 + #define WRONG_FORMAT_1 (__force snd_pcm_format_t)((__force int)SNDRV_PCM_FORMAT_LAST + 1) 21 + #define WRONG_FORMAT_2 (__force snd_pcm_format_t)-1 21 22 22 23 #define VALID_NAME "ValidName" 23 24 #define NAME_W_SPEC_CHARS "In%v@1id name" ··· 105 104 valid_fmt[i].physical_bits); 106 105 } 107 106 108 - KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT), -EINVAL); 109 - KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(-1), -EINVAL); 107 + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_1), -EINVAL); 108 + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_2), -EINVAL); 110 109 } 111 110 112 111 static void test_format_width(struct kunit *test) ··· 118 117 valid_fmt[i].width); 119 118 } 120 119 121 - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT), -EINVAL); 122 - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(-1), -EINVAL); 120 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); 121 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); 123 122 } 124 123 125 124 static void test_format_signed(struct kunit *test) ··· 133 132 valid_fmt[i].sd < 0 ? -EINVAL : 1 - valid_fmt[i].sd); 134 133 } 135 134 136 - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT), -EINVAL); 137 - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(-1), -EINVAL); 135 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); 136 + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); 138 137 } 139 138 140 139 static void test_format_endianness(struct kunit *test) ··· 148 147 valid_fmt[i].le < 0 ? -EINVAL : 1 - valid_fmt[i].le); 149 148 } 150 149 151 - KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT), -EINVAL); 152 - KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(-1), -EINVAL); 153 - KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT), -EINVAL); 154 - KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(-1), -EINVAL); 150 + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_1), -EINVAL); 151 + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_2), -EINVAL); 152 + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_1), -EINVAL); 153 + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_2), -EINVAL); 155 154 } 156 155 157 156 static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *data, ··· 178 177 _test_fill_silence(test, &valid_fmt[j], buffer, buf_samples[i]); 179 178 } 180 179 181 - KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT, buffer, 20), -EINVAL); 180 + KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT_1, buffer, 20), -EINVAL); 182 181 KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(SNDRV_PCM_FORMAT_LAST, buffer, 0), 0); 183 182 } 184 183 ··· 273 272 KUNIT_EXPECT_STREQ(test, name, valid_fmt[i].name); 274 273 } 275 274 276 - KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT), "Unknown"); 277 - KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(-1), "Unknown"); 275 + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_1), "Unknown"); 276 + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_2), "Unknown"); 278 277 } 279 278 280 279 static void test_card_add_component(struct kunit *test)