Skip to content

Commit 0f3b818

Browse files
morimotobroonie
authored andcommitted
ASoC: add snd_soc_card_mutex_lock/unlock()
ASoC need to use card->mutex with _INIT or _RUNTIME, but there is no helper function for it. This patch adds its helper function and use it. Because people might misunderstand that _init() is mutex initialization, this patch renames _INIT to _ROOT and adds new snd_soc_card_mutex_lock_root() for it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/87a5zlx3tw.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 38e42f6 commit 0f3b818

3 files changed

Lines changed: 27 additions & 12 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,

sound/soc/soc-compress.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
140140
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
141141
int ret;
142142

143-
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
143+
snd_soc_card_mutex_lock(fe->card);
144144

145145
ret = dpcm_path_get(fe, stream, &list);
146146
if (ret < 0)
@@ -184,7 +184,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
184184
snd_soc_runtime_activate(fe, stream);
185185
snd_soc_dpcm_mutex_unlock(fe);
186186

187-
mutex_unlock(&fe->card->mutex);
187+
snd_soc_card_mutex_unlock(fe->card);
188188

189189
return 0;
190190

@@ -196,7 +196,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
196196
dpcm_path_put(&list);
197197
be_err:
198198
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
199-
mutex_unlock(&fe->card->mutex);
199+
snd_soc_card_mutex_unlock(fe->card);
200200
return ret;
201201
}
202202

@@ -207,7 +207,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
207207
struct snd_soc_dpcm *dpcm;
208208
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
209209

210-
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
210+
snd_soc_card_mutex_lock(fe->card);
211211

212212
snd_soc_dpcm_mutex_lock(fe);
213213
snd_soc_runtime_deactivate(fe, stream);
@@ -237,7 +237,7 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
237237

238238
snd_soc_dai_compr_shutdown(cpu_dai, cstream, 0);
239239

240-
mutex_unlock(&fe->card->mutex);
240+
snd_soc_card_mutex_unlock(fe->card);
241241
return 0;
242242
}
243243

@@ -284,7 +284,7 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
284284
cmd == SND_COMPR_TRIGGER_DRAIN)
285285
return snd_soc_component_compr_trigger(cstream, cmd);
286286

287-
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
287+
snd_soc_card_mutex_lock(fe->card);
288288

289289
ret = snd_soc_dai_compr_trigger(cpu_dai, cstream, cmd);
290290
if (ret < 0)
@@ -315,7 +315,7 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
315315

316316
out:
317317
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
318-
mutex_unlock(&fe->card->mutex);
318+
snd_soc_card_mutex_unlock(fe->card);
319319
return ret;
320320
}
321321

@@ -373,7 +373,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
373373
int stream = cstream->direction; /* SND_COMPRESS_xxx is same as SNDRV_PCM_STREAM_xxx */
374374
int ret;
375375

376-
mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
376+
snd_soc_card_mutex_lock(fe->card);
377377

378378
/*
379379
* Create an empty hw_params for the BE as the machine driver must
@@ -411,7 +411,7 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
411411

412412
out:
413413
fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO;
414-
mutex_unlock(&fe->card->mutex);
414+
snd_soc_card_mutex_unlock(fe->card);
415415
return ret;
416416
}
417417

sound/soc/soc-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
19381938
int ret;
19391939

19401940
mutex_lock(&client_mutex);
1941-
mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1941+
snd_soc_card_mutex_lock_root(card);
19421942

19431943
snd_soc_dapm_init(&card->dapm, card, NULL);
19441944

@@ -2093,7 +2093,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
20932093
if (ret < 0)
20942094
soc_cleanup_card_resources(card);
20952095

2096-
mutex_unlock(&card->mutex);
2096+
snd_soc_card_mutex_unlock(card);
20972097
mutex_unlock(&client_mutex);
20982098

20992099
return ret;

0 commit comments

Comments
 (0)