Skip to content

Commit 97c236e

Browse files
committed
ASoC: cleanup mutex lock
Merge series from Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>: ASoC is using many type of mutex lock, but some of them has helper function, but some doesn't. Or, it has helper function, but is static. This patch-set adds helper function and use it.
2 parents 59de6c3 + 0f3b818 commit 97c236e

8 files changed

Lines changed: 216 additions & 127 deletions

File tree

include/sound/soc-card.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,25 @@
99
#define __SOC_CARD_H
1010

1111
enum snd_soc_card_subclass {
12-
SND_SOC_CARD_CLASS_INIT = 0,
12+
SND_SOC_CARD_CLASS_ROOT = 0,
1313
SND_SOC_CARD_CLASS_RUNTIME = 1,
1414
};
1515

16+
static inline void snd_soc_card_mutex_lock_root(struct snd_soc_card *card)
17+
{
18+
mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_ROOT);
19+
}
20+
21+
static inline void snd_soc_card_mutex_lock(struct snd_soc_card *card)
22+
{
23+
mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
24+
}
25+
26+
static inline void snd_soc_card_mutex_unlock(struct snd_soc_card *card)
27+
{
28+
mutex_unlock(&card->mutex);
29+
}
30+
1631
struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
1732
const char *name);
1833
int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,

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: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,17 +1364,112 @@ 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)
1386+
{
1387+
mutex_unlock(&card->dapm_mutex);
1388+
}
1389+
1390+
static inline void _snd_soc_dapm_mutex_assert_held_c(struct snd_soc_card *card)
1391+
{
1392+
lockdep_assert_held(&card->dapm_mutex);
1393+
}
1394+
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+
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)
13691437
{
1370-
mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1438+
mutex_unlock(&card->pcm_mutex);
13711439
}
13721440

1373-
static inline void snd_soc_dapm_mutex_unlock(struct snd_soc_dapm_context *dapm)
1441+
static inline void _snd_soc_dpcm_mutex_assert_held_c(struct snd_soc_card *card)
13741442
{
1375-
mutex_unlock(&dapm->card->dapm_mutex);
1443+
lockdep_assert_held(&card->pcm_mutex);
13761444
}
13771445

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+
13781473
#include <sound/soc-component.h>
13791474
#include <sound/soc-card.h>
13801475
#include <sound/soc-jack.h>

sound/soc/soc-component.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
550550
struct snd_soc_component *component;
551551
int i, ret = 0;
552552

553-
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
553+
snd_soc_dpcm_mutex_lock(rtd);
554554

555555
for_each_rtd_components(rtd, i, component) {
556556
if (component->driver->compress_ops &&
@@ -561,7 +561,7 @@ int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
561561
}
562562
}
563563

564-
mutex_unlock(&rtd->card->pcm_mutex);
564+
snd_soc_dpcm_mutex_unlock(rtd);
565565

566566
return soc_component_ret(component, ret);
567567
}
@@ -574,7 +574,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
574574
struct snd_soc_component *component;
575575
int i, ret = 0;
576576

577-
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
577+
snd_soc_dpcm_mutex_lock(rtd);
578578

579579
for_each_rtd_components(rtd, i, component) {
580580
if (component->driver->compress_ops &&
@@ -585,7 +585,7 @@ int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
585585
}
586586
}
587587

588-
mutex_unlock(&rtd->card->pcm_mutex);
588+
snd_soc_dpcm_mutex_unlock(rtd);
589589

590590
return soc_component_ret(component, ret);
591591
}
@@ -638,7 +638,7 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
638638
struct snd_soc_component *component;
639639
int i, ret = 0;
640640

641-
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
641+
snd_soc_dpcm_mutex_lock(rtd);
642642

643643
for_each_rtd_components(rtd, i, component) {
644644
if (component->driver->compress_ops &&
@@ -649,7 +649,7 @@ int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
649649
}
650650
}
651651

652-
mutex_unlock(&rtd->card->pcm_mutex);
652+
snd_soc_dpcm_mutex_unlock(rtd);
653653

654654
return soc_component_ret(component, ret);
655655
}

0 commit comments

Comments
 (0)