Skip to content

Commit ffe3440

Browse files
author
Fox Snowpatch
committed
1 parent 88333f7 commit ffe3440

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

include/sound/soc-card.h

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static inline void snd_soc_card_mutex_unlock(struct snd_soc_card *card)
3030

3131
struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
3232
const char *name);
33+
struct snd_kcontrol *snd_soc_card_get_kcontrol_locked(struct snd_soc_card *soc_card,
34+
const char *name);
3335
int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
3436
struct snd_soc_jack *jack);
3537
int snd_soc_card_jack_new_pins(struct snd_soc_card *card, const char *id,

sound/soc/codecs/cs35l45.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static int cs35l45_activate_ctl(struct snd_soc_component *component,
184184
else
185185
snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "%s", ctl_name);
186186

187-
kcontrol = snd_soc_card_get_kcontrol(component->card, name);
187+
kcontrol = snd_soc_card_get_kcontrol_locked(component->card, name);
188188
if (!kcontrol) {
189189
dev_err(component->dev, "Can't find kcontrol %s\n", name);
190190
return -EINVAL;

sound/soc/codecs/cs35l56.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int cs35l56_sync_asp1_mixer_widgets_with_firmware(struct cs35l56_private
114114
name = full_name;
115115
}
116116

117-
kcontrol = snd_soc_card_get_kcontrol(dapm->card, name);
117+
kcontrol = snd_soc_card_get_kcontrol_locked(dapm->card, name);
118118
if (!kcontrol) {
119119
dev_warn(cs35l56->base.dev, "Could not find control %s\n", name);
120120
continue;

sound/soc/fsl/fsl_xcvr.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ static int fsl_xcvr_activate_ctl(struct snd_soc_dai *dai, const char *name,
174174
struct snd_kcontrol *kctl;
175175
bool enabled;
176176

177-
kctl = snd_soc_card_get_kcontrol(card, name);
177+
lockdep_assert_held(&card->snd_card->controls_rwsem);
178+
179+
kctl = snd_soc_card_get_kcontrol_locked(card, name);
178180
if (kctl == NULL)
179181
return -ENOENT;
180182

@@ -576,10 +578,14 @@ static int fsl_xcvr_startup(struct snd_pcm_substream *substream,
576578
xcvr->streams |= BIT(substream->stream);
577579

578580
if (!xcvr->soc_data->spdif_only) {
581+
struct snd_soc_card *card = dai->component->card;
582+
579583
/* Disable XCVR controls if there is stream started */
584+
down_read(&card->snd_card->controls_rwsem);
580585
fsl_xcvr_activate_ctl(dai, fsl_xcvr_mode_kctl.name, false);
581586
fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name, false);
582587
fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name, false);
588+
up_read(&card->snd_card->controls_rwsem);
583589
}
584590

585591
return 0;
@@ -598,11 +604,15 @@ static void fsl_xcvr_shutdown(struct snd_pcm_substream *substream,
598604
/* Enable XCVR controls if there is no stream started */
599605
if (!xcvr->streams) {
600606
if (!xcvr->soc_data->spdif_only) {
607+
struct snd_soc_card *card = dai->component->card;
608+
609+
down_read(&card->snd_card->controls_rwsem);
601610
fsl_xcvr_activate_ctl(dai, fsl_xcvr_mode_kctl.name, true);
602611
fsl_xcvr_activate_ctl(dai, fsl_xcvr_arc_mode_kctl.name,
603612
(xcvr->mode == FSL_XCVR_MODE_ARC));
604613
fsl_xcvr_activate_ctl(dai, fsl_xcvr_earc_capds_kctl.name,
605614
(xcvr->mode == FSL_XCVR_MODE_EARC));
615+
up_read(&card->snd_card->controls_rwsem);
606616
}
607617
ret = regmap_update_bits(xcvr->regmap, FSL_XCVR_EXT_IER0,
608618
FSL_XCVR_IRQ_EARC_ALL, 0);

sound/soc/soc-card.c

+22-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// Copyright (C) 2019 Renesas Electronics Corp.
66
// Kuninori Morimoto <[email protected]>
77
//
8+
9+
#include <linux/lockdep.h>
10+
#include <linux/rwsem.h>
811
#include <sound/soc.h>
912
#include <sound/jack.h>
1013

@@ -26,12 +29,15 @@ static inline int _soc_card_ret(struct snd_soc_card *card,
2629
return ret;
2730
}
2831

29-
struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
30-
const char *name)
32+
struct snd_kcontrol *snd_soc_card_get_kcontrol_locked(struct snd_soc_card *soc_card,
33+
const char *name)
3134
{
3235
struct snd_card *card = soc_card->snd_card;
3336
struct snd_kcontrol *kctl;
3437

38+
/* must be held read or write */
39+
lockdep_assert_held(&card->controls_rwsem);
40+
3541
if (unlikely(!name))
3642
return NULL;
3743

@@ -40,6 +46,20 @@ struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
4046
return kctl;
4147
return NULL;
4248
}
49+
EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol_locked);
50+
51+
struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
52+
const char *name)
53+
{
54+
struct snd_card *card = soc_card->snd_card;
55+
struct snd_kcontrol *kctl;
56+
57+
down_read(&card->controls_rwsem);
58+
kctl = snd_soc_card_get_kcontrol_locked(soc_card, name);
59+
up_read(&card->controls_rwsem);
60+
61+
return kctl;
62+
}
4363
EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
4464

4565
static int jack_new(struct snd_soc_card *card, const char *id, int type,

0 commit comments

Comments
 (0)