Skip to content

Commit 5f22449

Browse files
Enric Balletbo i Serrabroonie
authored andcommitted
ASoC: rockchip-max98090: Fix NULL pointer dereference while accessing to jack.
Commit f2ed6b0 ("ASoC: Make aux_dev more like a generic component") caused a regression on this driver, since now a kernel oops is seen when rockchip-mac98090 driver is loaded. That commit changed the probing of aux_devs before checking new DAI links, so for this driver rk_98090_headset_init is called before rk_init and then the kernel oops due a NULL pointer dereference inside rk_98090_headset_init function since there is a call that tries to access the jack pointer which has not been allocated yet. This is the call chain that causes the crash: rk_98090_headset_init -> ts3a227e_enable_jack_detect -> snd_jack_set_key rk_init -> snd_soc_card_jack_new This patch moves the new jack object creation from rk_init to rk_98090_headset_init function making sure the jack is created before is accessed. Signed-off-by: Enric Balletbo i Serra <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 170abca commit 5f22449

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

sound/soc/rockchip/rockchip_max98090.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,43 +114,27 @@ static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
114114
return ret;
115115
}
116116

117-
static int rk_init(struct snd_soc_pcm_runtime *runtime)
118-
{
119-
/* Enable Headset and 4 Buttons Jack detection */
120-
return snd_soc_card_jack_new(runtime->card, "Headset Jack",
121-
SND_JACK_HEADSET |
122-
SND_JACK_BTN_0 | SND_JACK_BTN_1 |
123-
SND_JACK_BTN_2 | SND_JACK_BTN_3,
124-
&headset_jack,
125-
headset_jack_pins,
126-
ARRAY_SIZE(headset_jack_pins));
127-
}
128-
129-
static int rk_98090_headset_init(struct snd_soc_component *component)
130-
{
131-
return ts3a227e_enable_jack_detect(component, &headset_jack);
132-
}
133-
134117
static struct snd_soc_ops rk_aif1_ops = {
135118
.hw_params = rk_aif1_hw_params,
136119
};
137120

138-
static struct snd_soc_aux_dev rk_98090_headset_dev = {
139-
.name = "Headset Chip",
140-
.init = rk_98090_headset_init,
141-
};
142-
143121
static struct snd_soc_dai_link rk_dailink = {
144122
.name = "max98090",
145123
.stream_name = "Audio",
146124
.codec_dai_name = "HiFi",
147-
.init = rk_init,
148125
.ops = &rk_aif1_ops,
149126
/* set max98090 as slave */
150127
.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
151128
SND_SOC_DAIFMT_CBS_CFS,
152129
};
153130

131+
static int rk_98090_headset_init(struct snd_soc_component *component);
132+
133+
static struct snd_soc_aux_dev rk_98090_headset_dev = {
134+
.name = "Headset Chip",
135+
.init = rk_98090_headset_init,
136+
};
137+
154138
static struct snd_soc_card snd_soc_card_rk = {
155139
.name = "ROCKCHIP-I2S",
156140
.owner = THIS_MODULE,
@@ -166,6 +150,26 @@ static struct snd_soc_card snd_soc_card_rk = {
166150
.num_controls = ARRAY_SIZE(rk_mc_controls),
167151
};
168152

153+
static int rk_98090_headset_init(struct snd_soc_component *component)
154+
{
155+
int ret;
156+
157+
/* Enable Headset and 4 Buttons Jack detection */
158+
ret = snd_soc_card_jack_new(&snd_soc_card_rk, "Headset Jack",
159+
SND_JACK_HEADSET |
160+
SND_JACK_BTN_0 | SND_JACK_BTN_1 |
161+
SND_JACK_BTN_2 | SND_JACK_BTN_3,
162+
&headset_jack,
163+
headset_jack_pins,
164+
ARRAY_SIZE(headset_jack_pins));
165+
if (ret)
166+
return ret;
167+
168+
ret = ts3a227e_enable_jack_detect(component, &headset_jack);
169+
170+
return ret;
171+
}
172+
169173
static int snd_rk_mc_probe(struct platform_device *pdev)
170174
{
171175
int ret = 0;

0 commit comments

Comments
 (0)