| .. | .. |
|---|
| 42 | 42 | /* we do lots of calculations on snd_pcm_format_t; shut up sparse */ |
|---|
| 43 | 43 | #define INT __force int |
|---|
| 44 | 44 | |
|---|
| 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] = { |
|---|
| 46 | 51 | [SNDRV_PCM_FORMAT_S8] = { |
|---|
| 47 | 52 | .width = 8, .phys = 8, .le = -1, .signd = 1, |
|---|
| 48 | 53 | .silence = {}, |
|---|
| .. | .. |
|---|
| 259 | 264 | int snd_pcm_format_signed(snd_pcm_format_t format) |
|---|
| 260 | 265 | { |
|---|
| 261 | 266 | int val; |
|---|
| 262 | | - if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST) |
|---|
| 267 | + if (!valid_format(format)) |
|---|
| 263 | 268 | return -EINVAL; |
|---|
| 264 | 269 | if ((val = pcm_formats[(INT)format].signd) < 0) |
|---|
| 265 | 270 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 307 | 312 | int snd_pcm_format_little_endian(snd_pcm_format_t format) |
|---|
| 308 | 313 | { |
|---|
| 309 | 314 | int val; |
|---|
| 310 | | - if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST) |
|---|
| 315 | + if (!valid_format(format)) |
|---|
| 311 | 316 | return -EINVAL; |
|---|
| 312 | 317 | if ((val = pcm_formats[(INT)format].le) < 0) |
|---|
| 313 | 318 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 343 | 348 | int snd_pcm_format_width(snd_pcm_format_t format) |
|---|
| 344 | 349 | { |
|---|
| 345 | 350 | int val; |
|---|
| 346 | | - if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST) |
|---|
| 351 | + if (!valid_format(format)) |
|---|
| 347 | 352 | return -EINVAL; |
|---|
| 348 | 353 | if ((val = pcm_formats[(INT)format].width) == 0) |
|---|
| 349 | 354 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 361 | 366 | int snd_pcm_format_physical_width(snd_pcm_format_t format) |
|---|
| 362 | 367 | { |
|---|
| 363 | 368 | int val; |
|---|
| 364 | | - if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST) |
|---|
| 369 | + if (!valid_format(format)) |
|---|
| 365 | 370 | return -EINVAL; |
|---|
| 366 | 371 | if ((val = pcm_formats[(INT)format].phys) == 0) |
|---|
| 367 | 372 | return -EINVAL; |
|---|
| .. | .. |
|---|
| 394 | 399 | */ |
|---|
| 395 | 400 | const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format) |
|---|
| 396 | 401 | { |
|---|
| 397 | | - if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST) |
|---|
| 402 | + if (!valid_format(format)) |
|---|
| 398 | 403 | return NULL; |
|---|
| 399 | 404 | if (! pcm_formats[(INT)format].phys) |
|---|
| 400 | 405 | return NULL; |
|---|
| .. | .. |
|---|
| 415 | 420 | int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int samples) |
|---|
| 416 | 421 | { |
|---|
| 417 | 422 | int width; |
|---|
| 418 | | - unsigned char *dst, *pat; |
|---|
| 423 | + unsigned char *dst; |
|---|
| 424 | + const unsigned char *pat; |
|---|
| 419 | 425 | |
|---|
| 420 | | - if ((INT)format < 0 || (INT)format > (INT)SNDRV_PCM_FORMAT_LAST) |
|---|
| 426 | + if (!valid_format(format)) |
|---|
| 421 | 427 | return -EINVAL; |
|---|
| 422 | 428 | if (samples == 0) |
|---|
| 423 | 429 | return 0; |
|---|
| 424 | 430 | width = pcm_formats[(INT)format].phys; /* physical width */ |
|---|
| 425 | 431 | pat = pcm_formats[(INT)format].silence; |
|---|
| 426 | | - if (! width) |
|---|
| 432 | + if (!width || !pat) |
|---|
| 427 | 433 | return -EINVAL; |
|---|
| 428 | 434 | /* signed or 1 byte data */ |
|---|
| 429 | 435 | if (pcm_formats[(INT)format].signd == 1 || width <= 8) { |
|---|
| .. | .. |
|---|
| 473 | 479 | EXPORT_SYMBOL(snd_pcm_format_set_silence); |
|---|
| 474 | 480 | |
|---|
| 475 | 481 | /** |
|---|
| 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 |
|---|
| 478 | 484 | * |
|---|
| 479 | 485 | * Determines the rate_min and rate_max fields from the rates bits of |
|---|
| 480 | | - * the given runtime->hw. |
|---|
| 486 | + * the given hw. |
|---|
| 481 | 487 | * |
|---|
| 482 | 488 | * Return: Zero if successful. |
|---|
| 483 | 489 | */ |
|---|
| 484 | | -int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime) |
|---|
| 490 | +int snd_pcm_hw_limit_rates(struct snd_pcm_hardware *hw) |
|---|
| 485 | 491 | { |
|---|
| 486 | 492 | int i; |
|---|
| 487 | 493 | 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]; |
|---|
| 490 | 496 | break; |
|---|
| 491 | 497 | } |
|---|
| 492 | 498 | } |
|---|
| 493 | 499 | 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]; |
|---|
| 496 | 502 | break; |
|---|
| 497 | 503 | } |
|---|
| 498 | 504 | } |
|---|
| 499 | 505 | return 0; |
|---|
| 500 | 506 | } |
|---|
| 501 | | -EXPORT_SYMBOL(snd_pcm_limit_hw_rates); |
|---|
| 507 | +EXPORT_SYMBOL(snd_pcm_hw_limit_rates); |
|---|
| 502 | 508 | |
|---|
| 503 | 509 | /** |
|---|
| 504 | 510 | * snd_pcm_rate_to_rate_bit - converts sample rate to SNDRV_PCM_RATE_xxx bit |
|---|