Skip to contentSkip to conversation

ALSA: snd-usb-caiaq: use snd_pcm_rate_to_rate_bit

PATCH Applied Jerome Brunet 3 participants 3 messages Aug 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: snd-usb-caiaq: use snd_pcm_rate_to_rate_bit

Use snd_pcm_rate_to_rate_bit() helper provided by Alsa instead re-implementing it. This reduce code duplication and helps when changing some Alsa definition is necessary.

---
 sound/usb/caiaq/audio.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
sound/usb/caiaq/audio.c +1 -12
index 4981753652a7..e62a4ea1d19c 100644
@@ -174,14 +174,6 @@ static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
 	return 0;
 }
 
-/* this should probably go upstream */
-#if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12
-#error "Change this table"
-#endif
-
-static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100,
-				48000, 64000, 88200, 96000, 176400, 192000 };
-
 static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
 {
 	int bytes_per_sample, bpp, ret, i;
@@ -233,10 +225,7 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
 
 	/* the first client that opens a stream defines the sample rate
 	 * setting for all subsequent calls, until the last client closed. */
-	for (i=0; i < ARRAY_SIZE(rates); i++)
-		if (runtime->rate == rates[i])
-			cdev->pcm_info.rates = 1 << i;
-
+	cdev->pcm_info.rates = snd_pcm_rate_to_rate_bit(runtime->rate);
 	snd_pcm_limit_hw_rates(runtime);
 
 	bytes_per_sample = BYTES_PER_SAMPLE;
Signature · 1 line
2.43.0
Applied
#1 lore raw
Quoted 6 lines · Jerome Brunet

Use snd_pcm_rate_to_rate_bit() helper provided by Alsa instead re-implementing it. This reduce code duplication and helps when changing some Alsa definition is necessary.

Thanks, applied now.

Takashi

#2 lore raw
In reply to Jerome Brunet
kernel test robot noticed the following build warnings:

Hi Jerome,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tiwai-sound/for-next]
[also build test WARNING on tiwai-sound/for-linus linus/master v6.11-rc2 next-20240808] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jerome-Brunet/ALSA-snd-usb-caiaq-use-snd_pcm_rate_to_rate_bit/20240808-215111
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
patch link:    https://lore.kernel.org/r/20240808134857.86749-1-jbrunet%40baylibre.com
patch subject: [PATCH] ALSA: snd-usb-caiaq: use snd_pcm_rate_to_rate_bit
config: arc-randconfig-001-20240809 (https://download.01.org/0day-ci/archive/20240809/[email protected]/config)
compiler: arceb-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240809/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

sound/usb/caiaq/audio.c: In function 'snd_usb_caiaq_pcm_prepare':

>> sound/usb/caiaq/audio.c:179:41: warning: unused variable 'i' [-Wunused-variable]
     179 |         int bytes_per_sample, bpp, ret, i;
         |                                         ^

vim +/i +179 sound/usb/caiaq/audio.c

523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  176  
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  177  static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  178  {
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26 @179  	int bytes_per_sample, bpp, ret, i;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  180  	int index = substream->number;
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  181  	struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  182  	struct snd_pcm_runtime *runtime = substream->runtime;
f1f6b8f65ff08a sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  183  	struct device *dev = caiaqdev_to_dev(cdev);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  184  
f1f6b8f65ff08a sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  185  	dev_dbg(dev, "%s(%p)\n", __func__, substream);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  186  
a9b487fa1e00b4 sound/usb/caiaq/audio.c       Daniel Mack   2009-04-27  187  	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  188  		int out_pos;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  189  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  190  		switch (cdev->spec.data_alignment) {
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  191  		case 0:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  192  		case 2:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  193  			out_pos = BYTES_PER_SAMPLE + 1;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  194  			break;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  195  		case 3:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  196  		default:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  197  			out_pos = 0;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  198  			break;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  199  		}
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  200  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  201  		cdev->period_out_count[index] = out_pos;
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  202  		cdev->audio_out_buf_pos[index] = out_pos;
a9b487fa1e00b4 sound/usb/caiaq/audio.c       Daniel Mack   2009-04-27  203  	} else {
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  204  		int in_pos;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  205  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  206  		switch (cdev->spec.data_alignment) {
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  207  		case 0:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  208  			in_pos = BYTES_PER_SAMPLE + 2;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  209  			break;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  210  		case 2:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  211  			in_pos = BYTES_PER_SAMPLE;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  212  			break;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  213  		case 3:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  214  		default:
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  215  			in_pos = 0;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  216  			break;
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  217  		}
15c5ab607045e2 sound/usb/caiaq/audio.c       Daniel Mack   2010-09-10  218  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  219  		cdev->period_in_count[index] = in_pos;
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  220  		cdev->audio_in_buf_pos[index] = in_pos;
a9b487fa1e00b4 sound/usb/caiaq/audio.c       Daniel Mack   2009-04-27  221  	}
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  222  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  223  	if (cdev->streaming)
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  224  		return 0;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  225  
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  226  	/* the first client that opens a stream defines the sample rate
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  227  	 * setting for all subsequent calls, until the last client closed. */
fcb26c77ddb6a1 sound/usb/caiaq/audio.c       Jerome Brunet 2024-08-08  228  	cdev->pcm_info.rates = snd_pcm_rate_to_rate_bit(runtime->rate);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  229  	snd_pcm_limit_hw_rates(runtime);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  230  
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  231  	bytes_per_sample = BYTES_PER_SAMPLE;
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  232  	if (cdev->spec.data_alignment >= 2)
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  233  		bytes_per_sample++;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  234  
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  235  	bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  236  		* bytes_per_sample * CHANNELS_PER_STREAM * cdev->n_streams;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  237  
6e9fc6bd5db34a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2008-04-14  238  	if (bpp > MAX_ENDPOINT_SIZE)
6e9fc6bd5db34a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2008-04-14  239  		bpp = MAX_ENDPOINT_SIZE;
6e9fc6bd5db34a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2008-04-14  240  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  241  	ret = snd_usb_caiaq_set_audio_params(cdev, runtime->rate,
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  242  					     runtime->sample_bits, bpp);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  243  	if (ret)
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  244  		return ret;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  245  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  246  	ret = stream_start(cdev);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  247  	if (ret)
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  248  		return ret;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  249  
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  250  	cdev->output_running = 0;
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  251  	wait_event_timeout(cdev->prepare_wait_queue, cdev->output_running, HZ);
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  252  	if (!cdev->output_running) {
1c8470ce311c6b sound/usb/caiaq/audio.c       Daniel Mack   2013-03-03  253  		stream_stop(cdev);
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  254  		return -EPIPE;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  255  	}
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  256  
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  257  	return 0;
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  258  }
523f1dce37434a sound/usb/caiaq/caiaq-audio.c Daniel Mack   2007-03-26  259  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki