hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/core/pcm_misc.c
....@@ -42,7 +42,12 @@
4242 /* we do lots of calculations on snd_pcm_format_t; shut up sparse */
4343 #define INT __force int
4444
45
-static struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
45
+static bool valid_format(snd_pcm_format_t format)
46
+{
47
+ return (INT)format >= 0 && (INT)format <= (INT)SNDRV_PCM_FORMAT_LAST;
48
+}
49
+
50
+static const struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
4651 [SNDRV_PCM_FORMAT_S8] = {
4752 .width = 8, .phys = 8, .le = -1, .signd = 1,
4853 .silence = {},
....@@ -259,7 +264,7 @@
259264 int snd_pcm_format_signed(snd_pcm_format_t format)
260265 {
261266 int val;
262
- if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
267
+ if (!valid_format(format))
263268 return -EINVAL;
264269 if ((val = pcm_formats[(INT)format].signd) < 0)
265270 return -EINVAL;
....@@ -307,7 +312,7 @@
307312 int snd_pcm_format_little_endian(snd_pcm_format_t format)
308313 {
309314 int val;
310
- if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
315
+ if (!valid_format(format))
311316 return -EINVAL;
312317 if ((val = pcm_formats[(INT)format].le) < 0)
313318 return -EINVAL;
....@@ -343,7 +348,7 @@
343348 int snd_pcm_format_width(snd_pcm_format_t format)
344349 {
345350 int val;
346
- if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
351
+ if (!valid_format(format))
347352 return -EINVAL;
348353 if ((val = pcm_formats[(INT)format].width) == 0)
349354 return -EINVAL;
....@@ -361,7 +366,7 @@
361366 int snd_pcm_format_physical_width(snd_pcm_format_t format)
362367 {
363368 int val;
364
- if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
369
+ if (!valid_format(format))
365370 return -EINVAL;
366371 if ((val = pcm_formats[(INT)format].phys) == 0)
367372 return -EINVAL;
....@@ -394,7 +399,7 @@
394399 */
395400 const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format)
396401 {
397
- if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
402
+ if (!valid_format(format))
398403 return NULL;
399404 if (! pcm_formats[(INT)format].phys)
400405 return NULL;
....@@ -415,15 +420,16 @@
415420 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples)
416421 {
417422 int width;
418
- unsigned char *dst, *pat;
423
+ unsigned char *dst;
424
+ const unsigned char *pat;
419425
420
- if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST)
426
+ if (!valid_format(format))
421427 return -EINVAL;
422428 if (samples == 0)
423429 return 0;
424430 width = pcm_formats[(INT)format].phys; /* physical width */
425431 pat = pcm_formats[(INT)format].silence;
426
- if (! width)
432
+ if (!width || !pat)
427433 return -EINVAL;
428434 /* signed or 1 byte data */
429435 if (pcm_formats[(INT)format].signd == 1 || width <= 8) {
....@@ -473,32 +479,32 @@
473479 EXPORT_SYMBOL(snd_pcm_format_set_silence);
474480
475481 /**
476
- * snd_pcm_limit_hw_rates - determine rate_min/rate_max fields
477
- * @runtime: the runtime instance
482
+ * snd_pcm_hw_limit_rates - determine rate_min/rate_max fields
483
+ * @hw: the pcm hw instance
478484 *
479485 * Determines the rate_min and rate_max fields from the rates bits of
480
- * the given runtime->hw.
486
+ * the given hw.
481487 *
482488 * Return: Zero if successful.
483489 */
484
-int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime)
490
+int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw)
485491 {
486492 int i;
487493 for (i = 0; i < (int)snd_pcm_known_rates.count; i++) {
488
- if (runtime->hw.rates & (1 << i)) {
489
- runtime->hw.rate_min = snd_pcm_known_rates.list[i];
494
+ if (hw->rates & (1 << i)) {
495
+ hw->rate_min = snd_pcm_known_rates.list[i];
490496 break;
491497 }
492498 }
493499 for (i = (int)snd_pcm_known_rates.count - 1; i >= 0; i--) {
494
- if (runtime->hw.rates & (1 << i)) {
495
- runtime->hw.rate_max = snd_pcm_known_rates.list[i];
500
+ if (hw->rates & (1 << i)) {
501
+ hw->rate_max = snd_pcm_known_rates.list[i];
496502 break;
497503 }
498504 }
499505 return 0;
500506 }
501
-EXPORT_SYMBOL(snd_pcm_limit_hw_rates);
507
+EXPORT_SYMBOL(snd_pcm_hw_limit_rates);
502508
503509 /**
504510 * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit