Message ID | 20240227104912.18921-1-tiwai@suse.de (mailing list archive) |
---|---|
State | Accepted |
Commit | 9301a412303725ae511229c22ea0f326ad47ad07 |
Headers | show |
Series | ALSA: kunit: Fix sparse warnings | expand |
On 2/27/24 10:49, Takashi Iwai wrote: > 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 > Signed-off-by: Takashi Iwai <tiwai@suse.de> > --- > sound/core/sound_kunit.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) > > diff --git a/sound/core/sound_kunit.c b/sound/core/sound_kunit.c > index 4212c4a20697..eb90f62228c0 100644 > --- a/sound/core/sound_kunit.c > +++ b/sound/core/sound_kunit.c > @@ -17,7 +17,8 @@ > .name = #fmt, \ > } > > -#define WRONG_FORMAT (SNDRV_PCM_FORMAT_LAST + 1) > +#define WRONG_FORMAT_1 (__force snd_pcm_format_t)((__force int)SNDRV_PCM_FORMAT_LAST + 1) > +#define WRONG_FORMAT_2 (__force snd_pcm_format_t)-1 > > #define VALID_NAME "ValidName" > #define NAME_W_SPEC_CHARS "In%v@1id name" > @@ -104,8 +105,8 @@ static void test_phys_format_size(struct kunit *test) > valid_fmt[i].physical_bits); > } > > - KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT), -EINVAL); > - KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(-1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_2), -EINVAL); > } > > static void test_format_width(struct kunit *test) > @@ -117,8 +118,8 @@ static void test_format_width(struct kunit *test) > valid_fmt[i].width); > } > > - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT), -EINVAL); > - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(-1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); > } > > static void test_format_signed(struct kunit *test) > @@ -132,8 +133,8 @@ static void test_format_signed(struct kunit *test) > valid_fmt[i].sd < 0 ? -EINVAL : 1 - valid_fmt[i].sd); > } > > - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT), -EINVAL); > - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(-1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); > } > > static void test_format_endianness(struct kunit *test) > @@ -147,10 +148,10 @@ static void test_format_endianness(struct kunit *test) > valid_fmt[i].le < 0 ? -EINVAL : 1 - valid_fmt[i].le); > } > > - KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT), -EINVAL); > - KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(-1), -EINVAL); > - KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT), -EINVAL); > - KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(-1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_2), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_1), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_2), -EINVAL); > } > > static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *data, > @@ -177,7 +178,7 @@ static void test_format_fill_silence(struct kunit *test) > _test_fill_silence(test, &valid_fmt[j], buffer, buf_samples[i]); > } > > - KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT, buffer, 20), -EINVAL); > + KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT_1, buffer, 20), -EINVAL); > KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(SNDRV_PCM_FORMAT_LAST, buffer, 0), 0); > } > > @@ -272,8 +273,8 @@ static void test_pcm_format_name(struct kunit *test) > KUNIT_EXPECT_STREQ(test, name, valid_fmt[i].name); > } > > - KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT), "Unknown"); > - KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(-1), "Unknown"); > + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_1), "Unknown"); > + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_2), "Unknown"); > } > > static void test_card_add_component(struct kunit *test) Acked-by: Ivan Orlov <ivan.orlov0322@gmail.com>
diff --git a/sound/core/sound_kunit.c b/sound/core/sound_kunit.c index 4212c4a20697..eb90f62228c0 100644 --- a/sound/core/sound_kunit.c +++ b/sound/core/sound_kunit.c @@ -17,7 +17,8 @@ .name = #fmt, \ } -#define WRONG_FORMAT (SNDRV_PCM_FORMAT_LAST + 1) +#define WRONG_FORMAT_1 (__force snd_pcm_format_t)((__force int)SNDRV_PCM_FORMAT_LAST + 1) +#define WRONG_FORMAT_2 (__force snd_pcm_format_t)-1 #define VALID_NAME "ValidName" #define NAME_W_SPEC_CHARS "In%v@1id name" @@ -104,8 +105,8 @@ static void test_phys_format_size(struct kunit *test) valid_fmt[i].physical_bits); } - KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT), -EINVAL); - KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(-1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_physical_width(WRONG_FORMAT_2), -EINVAL); } static void test_format_width(struct kunit *test) @@ -117,8 +118,8 @@ static void test_format_width(struct kunit *test) valid_fmt[i].width); } - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT), -EINVAL); - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(-1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); } static void test_format_signed(struct kunit *test) @@ -132,8 +133,8 @@ static void test_format_signed(struct kunit *test) valid_fmt[i].sd < 0 ? -EINVAL : 1 - valid_fmt[i].sd); } - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT), -EINVAL); - KUNIT_EXPECT_EQ(test, snd_pcm_format_width(-1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_width(WRONG_FORMAT_2), -EINVAL); } static void test_format_endianness(struct kunit *test) @@ -147,10 +148,10 @@ static void test_format_endianness(struct kunit *test) valid_fmt[i].le < 0 ? -EINVAL : 1 - valid_fmt[i].le); } - KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT), -EINVAL); - KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(-1), -EINVAL); - KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT), -EINVAL); - KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(-1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_little_endian(WRONG_FORMAT_2), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_1), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_big_endian(WRONG_FORMAT_2), -EINVAL); } static void _test_fill_silence(struct kunit *test, struct snd_format_test_data *data, @@ -177,7 +178,7 @@ static void test_format_fill_silence(struct kunit *test) _test_fill_silence(test, &valid_fmt[j], buffer, buf_samples[i]); } - KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT, buffer, 20), -EINVAL); + KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(WRONG_FORMAT_1, buffer, 20), -EINVAL); KUNIT_EXPECT_EQ(test, snd_pcm_format_set_silence(SNDRV_PCM_FORMAT_LAST, buffer, 0), 0); } @@ -272,8 +273,8 @@ static void test_pcm_format_name(struct kunit *test) KUNIT_EXPECT_STREQ(test, name, valid_fmt[i].name); } - KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT), "Unknown"); - KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(-1), "Unknown"); + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_1), "Unknown"); + KUNIT_ASSERT_STREQ(test, snd_pcm_format_name(WRONG_FORMAT_2), "Unknown"); } static void test_card_add_component(struct kunit *test)
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 Signed-off-by: Takashi Iwai <tiwai@suse.de> --- sound/core/sound_kunit.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)