Skip to content

Commit 4a778bd

Browse files
morimotobroonie
authored andcommitted
ASoC: expand snd_soc_dapm_mutex_lock/unlock()
soc.h has snd_soc_dapm_mutex_lock/unlock() definition and many drivers are using it, but soc-dapm.c is not. 1st reason is snd_soc_dapm_mutex_lock/unlock() requests snd_soc_dapm_context pointer as parameter (A), but sometimes soc-dapm.c needs to use snd_soc_card (B). (A) static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm) { mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); } ^^^^^^^^^^ (B) mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); ^^^^ 2nd reason is it want to use SND_SOC_DAPM_CLASS_INIT for mutex_lock_nested(), but helper is using _RUNTIME (A). The conclusion is we want to use "dapm vs card" and "_RUNTIME vs _INIT" for dapm lock/unlock. To enable this selfish request, this patch uses _Generic macro. We can use snd_soc_dapm_mutex_lock/unlock() for both dapm and card case. snd_soc_dapm_mutex_lock(dapm); snd_soc_dapm_mutex_unlock(dapm); snd_soc_dapm_mutex_lock(card); snd_soc_dapm_mutex_unlock(card); Current soc-dapm.c is using both mutex_lock() and mutex_lock_nested(). This patch handles mutex_lock() as mutex_lock_nested(..., 0), in other words, handles below as same. mutex_lock(&card->dapm_mutex); mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); Because people might misunderstand that _init() is mutex initialization, this patch renames _INIT to _ROOT and adds new snd_soc_dapm_mutex_lock_root() for it. This patch also moves snd_soc_dapm_subclass definition from soc-dapm.h to soc.h to keep related code together. Because very complex soc.h vs soc-dapm.h relationship, it is difficult/impossible to define these helper into soc-dapm.h. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/87cz4hx3v0.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent fc0b096 commit 4a778bd

3 files changed

Lines changed: 113 additions & 71 deletions

File tree

include/sound/soc-dapm.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,6 @@ enum snd_soc_dapm_type {
527527
SND_SOC_DAPM_TYPE_COUNT
528528
};
529529

530-
enum snd_soc_dapm_subclass {
531-
SND_SOC_DAPM_CLASS_INIT = 0,
532-
SND_SOC_DAPM_CLASS_RUNTIME = 1,
533-
};
534-
535530
/*
536531
* DAPM audio route definition.
537532
*

include/sound/soc.h

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,17 +1364,67 @@ extern struct dentry *snd_soc_debugfs_root;
13641364

13651365
extern const struct dev_pm_ops snd_soc_pm_ops;
13661366

1367-
/* Helper functions */
1368-
static inline void snd_soc_dapm_mutex_lock(struct snd_soc_dapm_context *dapm)
1367+
/*
1368+
* DAPM helper functions
1369+
*/
1370+
enum snd_soc_dapm_subclass {
1371+
SND_SOC_DAPM_CLASS_ROOT = 0,
1372+
SND_SOC_DAPM_CLASS_RUNTIME = 1,
1373+
};
1374+
1375+
static inline void _snd_soc_dapm_mutex_lock_root_c(struct snd_soc_card *card)
1376+
{
1377+
mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_ROOT);
1378+
}
1379+
1380+
static inline void _snd_soc_dapm_mutex_lock_c(struct snd_soc_card *card)
1381+
{
1382+
mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1383+
}
1384+
1385+
static inline void _snd_soc_dapm_mutex_unlock_c(struct snd_soc_card *card)
13691386
{
1370-
mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1387+
mutex_unlock(&card->dapm_mutex);
13711388
}
13721389

1373-
static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
1390+
static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
13741391
{
1375-
mutex_unlock(&dapm->card->dapm_mutex);
1392+
lockdep_assert_held(&card->dapm_mutex);
13761393
}
13771394

1395+
static inline void _snd_soc_dapm_mutex_lock_root_d(struct snd_soc_dapm_context *dapm)
1396+
{
1397+
_snd_soc_dapm_mutex_lock_root_c(dapm->card);
1398+
}
1399+
1400+
static inline void _snd_soc_dapm_mutex_lock_d(struct snd_soc_dapm_context *dapm)
1401+
{
1402+
_snd_soc_dapm_mutex_lock_c(dapm->card);
1403+
}
1404+
1405+
static inline void _snd_soc_dapm_mutex_unlock_d(struct snd_soc_dapm_context *dapm)
1406+
{
1407+
_snd_soc_dapm_mutex_unlock_c(dapm->card);
1408+
}
1409+
1410+
static inline void _snd_soc_dapm_mutex_assert_held_d(struct snd_soc_dapm_context *dapm)
1411+
{
1412+
_snd_soc_dapm_mutex_assert_held_c(dapm->card);
1413+
}
1414+
1415+
#define snd_soc_dapm_mutex_lock_root(x) _Generic((x), \
1416+
struct snd_soc_card * : _snd_soc_dapm_mutex_lock_root_c, \
1417+
struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_root_d)(x)
1418+
#define snd_soc_dapm_mutex_lock(x) _Generic((x), \
1419+
struct snd_soc_card * : _snd_soc_dapm_mutex_lock_c, \
1420+
struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_lock_d)(x)
1421+
#define snd_soc_dapm_mutex_unlock(x) _Generic((x), \
1422+
struct snd_soc_card * : _snd_soc_dapm_mutex_unlock_c, \
1423+
struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_unlock_d)(x)
1424+
#define snd_soc_dapm_mutex_assert_held(x) _Generic((x), \
1425+
struct snd_soc_card * : _snd_soc_dapm_mutex_assert_held_c, \
1426+
struct snd_soc_dapm_context * : _snd_soc_dapm_mutex_assert_held_d)(x)
1427+
13781428
#include <sound/soc-component.h>
13791429
#include <sound/soc-card.h>
13801430
#include <sound/soc-jack.h>

0 commit comments

Comments
 (0)