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

ASoC: expand snd_soc_dpcm_mutex_lock/unlock()

soc-pcm.c has snd_soc_dpcm_mutex_lock/unlock(),
but other files can't use it because it is static function.

It requests snd_soc_pcm_runtime as parameter (A), but sometimes we
want to use it by snd_soc_card (B).

(A) static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd)
{
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
} ^^^^^^^^^

(B) mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass);
^^^^

We want to use it with both "rtd" and "card" for dapm lock/unlock.
To enable it, this patch uses _Generic macro.

This patch makes snd_soc_dpcm_mutex_{un}lock() global function, and use it on
each files.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87bkk1x3ud.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kuninori Morimoto and committed by
Mark Brown
38e42f6d 4a778bdc

+76 -44
+45
include/sound/soc.h
··· 1425 1425 struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \ 1426 1426 struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x) 1427 1427 1428 + /* 1429 + * PCM helper functions 1430 + */ 1431 + static inline void _snd_soc_dpcm_mutex_lock_c(struct snd_soc_card *card) 1432 + { 1433 + mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass); 1434 + } 1435 + 1436 + static inline void _snd_soc_dpcm_mutex_unlock_c(struct snd_soc_card *card) 1437 + { 1438 + mutex_unlock(&card->pcm_mutex); 1439 + } 1440 + 1441 + static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card) 1442 + { 1443 + lockdep_assert_held(&card->pcm_mutex); 1444 + } 1445 + 1446 + static inline void _snd_soc_dpcm_mutex_lock_r(struct snd_soc_pcm_runtime *rtd) 1447 + { 1448 + _snd_soc_dpcm_mutex_lock_c(rtd->card); 1449 + } 1450 + 1451 + static inline void _snd_soc_dpcm_mutex_unlock_r(struct snd_soc_pcm_runtime *rtd) 1452 + { 1453 + _snd_soc_dpcm_mutex_unlock_c(rtd->card); 1454 + } 1455 + 1456 + static inline void _snd_soc_dpcm_mutex_assert_held_r(struct snd_soc_pcm_runtime *rtd) 1457 + { 1458 + _snd_soc_dpcm_mutex_assert_held_c(rtd->card); 1459 + } 1460 + 1461 + #define snd_soc_dpcm_mutex_lock(x) _Generic((x), \ 1462 + struct snd_soc_card * : _snd_soc_dpcm_mutex_lock_c, \ 1463 + struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_lock_r)(x) 1464 + 1465 + #define snd_soc_dpcm_mutex_unlock(x) _Generic((x), \ 1466 + struct snd_soc_card * : _snd_soc_dpcm_mutex_unlock_c, \ 1467 + struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_unlock_r)(x) 1468 + 1469 + #define snd_soc_dpcm_mutex_assert_held(x) _Generic((x), \ 1470 + struct snd_soc_card * : _snd_soc_dpcm_mutex_assert_held_c, \ 1471 + struct snd_soc_pcm_runtime * : _snd_soc_dpcm_mutex_assert_held_r)(x) 1472 + 1428 1473 #include <sound/soc-component.h> 1429 1474 #include <sound/soc-card.h> 1430 1475 #include <sound/soc-jack.h>
+6 -6
sound/soc/soc-component.c
··· 550 550 struct snd_soc_component *component; 551 551 int i, ret = 0; 552 552 553 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 553 + snd_soc_dpcm_mutex_lock(rtd); 554 554 555 555 for_each_rtd_components(rtd, i, component) { 556 556 if (component->driver->compress_ops && ··· 561 561 } 562 562 } 563 563 564 - mutex_unlock(&rtd->card->pcm_mutex); 564 + snd_soc_dpcm_mutex_unlock(rtd); 565 565 566 566 return soc_component_ret(component, ret); 567 567 } ··· 574 574 struct snd_soc_component *component; 575 575 int i, ret = 0; 576 576 577 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 577 + snd_soc_dpcm_mutex_lock(rtd); 578 578 579 579 for_each_rtd_components(rtd, i, component) { 580 580 if (component->driver->compress_ops && ··· 585 585 } 586 586 } 587 587 588 - mutex_unlock(&rtd->card->pcm_mutex); 588 + snd_soc_dpcm_mutex_unlock(rtd); 589 589 590 590 return soc_component_ret(component, ret); 591 591 } ··· 638 638 struct snd_soc_component *component; 639 639 int i, ret = 0; 640 640 641 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 641 + snd_soc_dpcm_mutex_lock(rtd); 642 642 643 643 for_each_rtd_components(rtd, i, component) { 644 644 if (component->driver->compress_ops && ··· 649 649 } 650 650 } 651 651 652 - mutex_unlock(&rtd->card->pcm_mutex); 652 + snd_soc_dpcm_mutex_unlock(rtd); 653 653 654 654 return soc_component_ret(component, ret); 655 655 }
+21 -21
sound/soc/soc-compress.c
··· 62 62 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 63 63 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ 64 64 65 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 65 + snd_soc_dpcm_mutex_lock(rtd); 66 66 67 67 if (!rollback) 68 68 snd_soc_runtime_deactivate(rtd, stream); ··· 84 84 if (!rollback) 85 85 snd_soc_dapm_stream_stop(rtd, stream); 86 86 87 - mutex_unlock(&rtd->card->pcm_mutex); 87 + snd_soc_dpcm_mutex_unlock(rtd); 88 88 89 89 snd_soc_pcm_component_pm_runtime_put(rtd, cstream, rollback); 90 90 ··· 107 107 if (ret < 0) 108 108 goto err_no_lock; 109 109 110 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 110 + snd_soc_dpcm_mutex_lock(rtd); 111 111 112 112 ret = snd_soc_dai_compr_startup(cpu_dai, cstream); 113 113 if (ret < 0) ··· 123 123 124 124 snd_soc_runtime_activate(rtd, stream); 125 125 err: 126 - mutex_unlock(&rtd->card->pcm_mutex); 126 + snd_soc_dpcm_mutex_unlock(rtd); 127 127 err_no_lock: 128 128 if (ret < 0) 129 129 soc_compr_clean(cstream, 1); ··· 146 146 if (ret < 0) 147 147 goto be_err; 148 148 149 - mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass); 149 + snd_soc_dpcm_mutex_lock(fe); 150 150 151 151 /* calculate valid and active FE <-> BE dpcms */ 152 152 dpcm_process_paths(fe, stream, &list, 1); ··· 182 182 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 183 183 184 184 snd_soc_runtime_activate(fe, stream); 185 - mutex_unlock(&fe->card->pcm_mutex); 185 + snd_soc_dpcm_mutex_unlock(fe); 186 186 187 187 mutex_unlock(&fe->card->mutex); 188 188 ··· 209 209 210 210 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); 211 211 212 - mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass); 212 + snd_soc_dpcm_mutex_lock(fe); 213 213 snd_soc_runtime_deactivate(fe, stream); 214 214 215 215 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; ··· 229 229 230 230 dpcm_be_disconnect(fe, stream); 231 231 232 - mutex_unlock(&fe->card->pcm_mutex); 232 + snd_soc_dpcm_mutex_unlock(fe); 233 233 234 234 snd_soc_link_compr_shutdown(cstream, 0); 235 235 ··· 249 249 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ 250 250 int ret; 251 251 252 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 252 + snd_soc_dpcm_mutex_lock(rtd); 253 253 254 254 ret = snd_soc_component_compr_trigger(cstream, cmd); 255 255 if (ret < 0) ··· 269 269 } 270 270 271 271 out: 272 - mutex_unlock(&rtd->card->pcm_mutex); 272 + snd_soc_dpcm_mutex_unlock(rtd); 273 273 return ret; 274 274 } 275 275 ··· 327 327 int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */ 328 328 int ret; 329 329 330 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 330 + snd_soc_dpcm_mutex_lock(rtd); 331 331 332 332 /* 333 333 * First we call set_params for the CPU DAI, then the component ··· 352 352 353 353 /* cancel any delayed stream shutdown that is pending */ 354 354 rtd->pop_wait = 0; 355 - mutex_unlock(&rtd->card->pcm_mutex); 355 + snd_soc_dpcm_mutex_unlock(rtd); 356 356 357 357 cancel_delayed_work_sync(&rtd->delayed_work); 358 358 359 359 return 0; 360 360 361 361 err: 362 - mutex_unlock(&rtd->card->pcm_mutex); 362 + snd_soc_dpcm_mutex_unlock(rtd); 363 363 return ret; 364 364 } 365 365 ··· 404 404 ret = snd_soc_link_compr_set_params(cstream); 405 405 if (ret < 0) 406 406 goto out; 407 - mutex_lock_nested(&fe->card->pcm_mutex, fe->card->pcm_subclass); 407 + snd_soc_dpcm_mutex_lock(fe); 408 408 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_START); 409 - mutex_unlock(&fe->card->pcm_mutex); 409 + snd_soc_dpcm_mutex_unlock(fe); 410 410 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; 411 411 412 412 out: ··· 422 422 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 423 423 int ret = 0; 424 424 425 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 425 + snd_soc_dpcm_mutex_lock(rtd); 426 426 427 427 ret = snd_soc_dai_compr_get_params(cpu_dai, cstream, params); 428 428 if (ret < 0) ··· 430 430 431 431 ret = snd_soc_component_compr_get_params(cstream, params); 432 432 err: 433 - mutex_unlock(&rtd->card->pcm_mutex); 433 + snd_soc_dpcm_mutex_unlock(rtd); 434 434 return ret; 435 435 } 436 436 ··· 440 440 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 441 441 int ret; 442 442 443 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 443 + snd_soc_dpcm_mutex_lock(rtd); 444 444 445 445 ret = snd_soc_dai_compr_ack(cpu_dai, cstream, bytes); 446 446 if (ret < 0) ··· 448 448 449 449 ret = snd_soc_component_compr_ack(cstream, bytes); 450 450 err: 451 - mutex_unlock(&rtd->card->pcm_mutex); 451 + snd_soc_dpcm_mutex_unlock(rtd); 452 452 return ret; 453 453 } 454 454 ··· 459 459 int ret; 460 460 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); 461 461 462 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 462 + snd_soc_dpcm_mutex_lock(rtd); 463 463 464 464 ret = snd_soc_dai_compr_pointer(cpu_dai, cstream, tstamp); 465 465 if (ret < 0) ··· 467 467 468 468 ret = snd_soc_component_compr_pointer(cstream, tstamp); 469 469 out: 470 - mutex_unlock(&rtd->card->pcm_mutex); 470 + snd_soc_dpcm_mutex_unlock(rtd); 471 471 return ret; 472 472 } 473 473
+2 -2
sound/soc/soc-core.c
··· 348 348 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 349 349 int playback = SNDRV_PCM_STREAM_PLAYBACK; 350 350 351 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 351 + snd_soc_dpcm_mutex_lock(rtd); 352 352 353 353 dev_dbg(rtd->dev, 354 354 "ASoC: pop wq checking: %s status: %s waiting: %s\n", ··· 364 364 SND_SOC_DAPM_STREAM_STOP); 365 365 } 366 366 367 - mutex_unlock(&rtd->card->pcm_mutex); 367 + snd_soc_dpcm_mutex_unlock(rtd); 368 368 } 369 369 EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work); 370 370
+2 -15
sound/soc/soc-pcm.c
··· 49 49 return ret; 50 50 } 51 51 52 - static inline void snd_soc_dpcm_mutex_lock(struct snd_soc_pcm_runtime *rtd) 53 - { 54 - mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); 55 - } 56 - 57 - static inline void snd_soc_dpcm_mutex_unlock(struct snd_soc_pcm_runtime *rtd) 58 - { 59 - mutex_unlock(&rtd->card->pcm_mutex); 60 - } 61 - 62 - #define snd_soc_dpcm_mutex_assert_held(rtd) \ 63 - lockdep_assert_held(&(rtd)->card->pcm_mutex) 64 - 65 52 static inline void snd_soc_dpcm_stream_lock_irq(struct snd_soc_pcm_runtime *rtd, 66 53 int stream) 67 54 { ··· 2651 2664 struct snd_soc_pcm_runtime *fe; 2652 2665 int ret = 0; 2653 2666 2654 - mutex_lock_nested(&card->pcm_mutex, card->pcm_subclass); 2667 + snd_soc_dpcm_mutex_lock(card); 2655 2668 /* shutdown all old paths first */ 2656 2669 for_each_card_rtds(card, fe) { 2657 2670 ret = soc_dpcm_fe_runtime_update(fe, 0); ··· 2667 2680 } 2668 2681 2669 2682 out: 2670 - mutex_unlock(&card->pcm_mutex); 2683 + snd_soc_dpcm_mutex_unlock(card); 2671 2684 return ret; 2672 2685 } 2673 2686 EXPORT_SYMBOL_GPL(snd_soc_dpcm_runtime_update);