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

ASoC: fsl: fsl_qmc_audio: Fix snd_pcm_format_t values handling

Running sparse on fsl_qmc_audio (make C=1) raises the following warnings:
fsl_qmc_audio.c:387:26: warning: restricted snd_pcm_format_t degrades to integer
fsl_qmc_audio.c:389:59: warning: incorrect type in argument 1 (different base types)
fsl_qmc_audio.c:389:59: expected restricted snd_pcm_format_t [usertype] format
fsl_qmc_audio.c:389:59: got unsigned int [assigned] i
fsl_qmc_audio.c:564:26: warning: restricted snd_pcm_format_t degrades to integer
fsl_qmc_audio.c:569:50: warning: incorrect type in argument 1 (different base types)
fsl_qmc_audio.c:569:50: expected restricted snd_pcm_format_t [usertype] format
fsl_qmc_audio.c:569:50: got int [assigned] i
fsl_qmc_audio.c:573:62: warning: incorrect type in argument 1 (different base types)
fsl_qmc_audio.c:573:62: expected restricted snd_pcm_format_t [usertype] format
fsl_qmc_audio.c:573:62: got int [assigned] i

These warnings are due to snd_pcm_format_t values handling done in the
driver. Some macros and functions exist to handle safely these values.

Use dedicated macros and functions to remove these warnings.

Fixes: 075c7125b11c ("ASoC: fsl: Add support for QMC audio")
Signed-off-by: Herve Codina <herve.codina@bootlin.com>
Link: https://lore.kernel.org/r/20230726161620.495298-1-herve.codina@bootlin.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Herve Codina and committed by
Mark Brown
5befe22b c17bd30d

+14 -14
+14 -14
sound/soc/fsl/fsl_qmc_audio.c
··· 372 372 struct snd_mask *f_old = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 373 373 unsigned int channels = params_channels(params); 374 374 unsigned int slot_width; 375 + snd_pcm_format_t format; 375 376 struct snd_mask f_new; 376 - unsigned int i; 377 377 378 378 if (!channels || channels > nb_ts) { 379 379 dev_err(qmc_dai->dev, "channels %u not supported\n", ··· 384 384 slot_width = (nb_ts / channels) * 8; 385 385 386 386 snd_mask_none(&f_new); 387 - for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) { 388 - if (snd_mask_test(f_old, i)) { 389 - if (snd_pcm_format_physical_width(i) <= slot_width) 390 - snd_mask_set(&f_new, i); 387 + pcm_for_each_format(format) { 388 + if (snd_mask_test_format(f_old, format)) { 389 + if (snd_pcm_format_physical_width(format) <= slot_width) 390 + snd_mask_set_format(&f_new, format); 391 391 } 392 392 } 393 393 ··· 551 551 552 552 static u64 qmc_audio_formats(u8 nb_ts) 553 553 { 554 - u64 formats; 555 - unsigned int chan_width; 556 554 unsigned int format_width; 557 - int i; 555 + unsigned int chan_width; 556 + snd_pcm_format_t format; 557 + u64 formats_mask; 558 558 559 559 if (!nb_ts) 560 560 return 0; 561 561 562 - formats = 0; 562 + formats_mask = 0; 563 563 chan_width = nb_ts * 8; 564 - for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) { 564 + pcm_for_each_format(format) { 565 565 /* 566 566 * Support format other than little-endian (ie big-endian or 567 567 * without endianness such as 8bit formats) 568 568 */ 569 - if (snd_pcm_format_little_endian(i) == 1) 569 + if (snd_pcm_format_little_endian(format) == 1) 570 570 continue; 571 571 572 572 /* Support physical width multiple of 8bit */ 573 - format_width = snd_pcm_format_physical_width(i); 573 + format_width = snd_pcm_format_physical_width(format); 574 574 if (format_width == 0 || format_width % 8) 575 575 continue; 576 576 ··· 581 581 if (format_width > chan_width || chan_width % format_width) 582 582 continue; 583 583 584 - formats |= (1ULL << i); 584 + formats_mask |= pcm_format_to_bits(format); 585 585 } 586 - return formats; 586 + return formats_mask; 587 587 } 588 588 589 589 static int qmc_audio_dai_parse(struct qmc_audio *qmc_audio, struct device_node *np,