Commit 576ce407 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Mark Brown

ASoC: wm97xx: fix uninitialized regmap pointer problem

gcc notices that without either the ac97 bus or the pdata, we never
initialize the regmap pointer, which leads to an uninitialized variable
access:

sound/soc/codecs/wm9712.c: In function 'wm9712_soc_probe':
sound/soc/codecs/wm9712.c:666:2: error: 'regmap' may be used uninitialized in this function [-Werror=maybe-uninitialized]

Since that configuration is invalid, it's better to return an error
here. I tried to avoid adding complexity to the conditions, and turned
the #ifdef into a regular if(IS_ENABLED()) check for readability.
This in turn requires moving some header file declarations out of
an #ifdef.

The same code is used in three drivers, all of which I'm changing
the same way.

Fixes: 2ed1a8e0 ("ASoC: wm9712: add ac97 new bus support")
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent ff60005e
...@@ -553,12 +553,12 @@ static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count, ...@@ -553,12 +553,12 @@ static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
} }
#endif #endif
#ifdef CONFIG_SND_SOC_AC97_BUS
struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component); struct snd_ac97 *snd_soc_alloc_ac97_component(struct snd_soc_component *component);
struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component, struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component,
unsigned int id, unsigned int id_mask); unsigned int id, unsigned int id_mask);
void snd_soc_free_ac97_component(struct snd_ac97 *ac97); void snd_soc_free_ac97_component(struct snd_ac97 *ac97);
#ifdef CONFIG_SND_SOC_AC97_BUS
int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops); int snd_soc_set_ac97_ops(struct snd_ac97_bus_ops *ops);
int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops, int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
struct platform_device *pdev); struct platform_device *pdev);
......
...@@ -325,8 +325,7 @@ static int wm9705_soc_probe(struct snd_soc_component *component) ...@@ -325,8 +325,7 @@ static int wm9705_soc_probe(struct snd_soc_component *component)
if (wm9705->mfd_pdata) { if (wm9705->mfd_pdata) {
wm9705->ac97 = wm9705->mfd_pdata->ac97; wm9705->ac97 = wm9705->mfd_pdata->ac97;
regmap = wm9705->mfd_pdata->regmap; regmap = wm9705->mfd_pdata->regmap;
} else { } else if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS)) {
#ifdef CONFIG_SND_SOC_AC97_BUS
wm9705->ac97 = snd_soc_new_ac97_component(component, WM9705_VENDOR_ID, wm9705->ac97 = snd_soc_new_ac97_component(component, WM9705_VENDOR_ID,
WM9705_VENDOR_ID_MASK); WM9705_VENDOR_ID_MASK);
if (IS_ERR(wm9705->ac97)) { if (IS_ERR(wm9705->ac97)) {
...@@ -339,7 +338,8 @@ static int wm9705_soc_probe(struct snd_soc_component *component) ...@@ -339,7 +338,8 @@ static int wm9705_soc_probe(struct snd_soc_component *component)
snd_soc_free_ac97_component(wm9705->ac97); snd_soc_free_ac97_component(wm9705->ac97);
return PTR_ERR(regmap); return PTR_ERR(regmap);
} }
#endif } else {
return -ENXIO;
} }
snd_soc_component_set_drvdata(component, wm9705->ac97); snd_soc_component_set_drvdata(component, wm9705->ac97);
...@@ -350,14 +350,12 @@ static int wm9705_soc_probe(struct snd_soc_component *component) ...@@ -350,14 +350,12 @@ static int wm9705_soc_probe(struct snd_soc_component *component)
static void wm9705_soc_remove(struct snd_soc_component *component) static void wm9705_soc_remove(struct snd_soc_component *component)
{ {
#ifdef CONFIG_SND_SOC_AC97_BUS
struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component); struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
if (!wm9705->mfd_pdata) { if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS) && !wm9705->mfd_pdata) {
snd_soc_component_exit_regmap(component); snd_soc_component_exit_regmap(component);
snd_soc_free_ac97_component(wm9705->ac97); snd_soc_free_ac97_component(wm9705->ac97);
} }
#endif
} }
static const struct snd_soc_component_driver soc_component_dev_wm9705 = { static const struct snd_soc_component_driver soc_component_dev_wm9705 = {
......
...@@ -642,8 +642,7 @@ static int wm9712_soc_probe(struct snd_soc_component *component) ...@@ -642,8 +642,7 @@ static int wm9712_soc_probe(struct snd_soc_component *component)
if (wm9712->mfd_pdata) { if (wm9712->mfd_pdata) {
wm9712->ac97 = wm9712->mfd_pdata->ac97; wm9712->ac97 = wm9712->mfd_pdata->ac97;
regmap = wm9712->mfd_pdata->regmap; regmap = wm9712->mfd_pdata->regmap;
} else { } else if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS)) {
#ifdef CONFIG_SND_SOC_AC97_BUS
int ret; int ret;
wm9712->ac97 = snd_soc_new_ac97_component(component, WM9712_VENDOR_ID, wm9712->ac97 = snd_soc_new_ac97_component(component, WM9712_VENDOR_ID,
...@@ -660,7 +659,8 @@ static int wm9712_soc_probe(struct snd_soc_component *component) ...@@ -660,7 +659,8 @@ static int wm9712_soc_probe(struct snd_soc_component *component)
snd_soc_free_ac97_component(wm9712->ac97); snd_soc_free_ac97_component(wm9712->ac97);
return PTR_ERR(regmap); return PTR_ERR(regmap);
} }
#endif } else {
return -ENXIO;
} }
snd_soc_component_init_regmap(component, regmap); snd_soc_component_init_regmap(component, regmap);
...@@ -673,14 +673,12 @@ static int wm9712_soc_probe(struct snd_soc_component *component) ...@@ -673,14 +673,12 @@ static int wm9712_soc_probe(struct snd_soc_component *component)
static void wm9712_soc_remove(struct snd_soc_component *component) static void wm9712_soc_remove(struct snd_soc_component *component)
{ {
#ifdef CONFIG_SND_SOC_AC97_BUS
struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component); struct wm9712_priv *wm9712 = snd_soc_component_get_drvdata(component);
if (!wm9712->mfd_pdata) { if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS) && !wm9712->mfd_pdata) {
snd_soc_component_exit_regmap(component); snd_soc_component_exit_regmap(component);
snd_soc_free_ac97_component(wm9712->ac97); snd_soc_free_ac97_component(wm9712->ac97);
} }
#endif
} }
static const struct snd_soc_component_driver soc_component_dev_wm9712 = { static const struct snd_soc_component_driver soc_component_dev_wm9712 = {
......
...@@ -1214,8 +1214,7 @@ static int wm9713_soc_probe(struct snd_soc_component *component) ...@@ -1214,8 +1214,7 @@ static int wm9713_soc_probe(struct snd_soc_component *component)
if (wm9713->mfd_pdata) { if (wm9713->mfd_pdata) {
wm9713->ac97 = wm9713->mfd_pdata->ac97; wm9713->ac97 = wm9713->mfd_pdata->ac97;
regmap = wm9713->mfd_pdata->regmap; regmap = wm9713->mfd_pdata->regmap;
} else { } else if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS)) {
#ifdef CONFIG_SND_SOC_AC97_BUS
wm9713->ac97 = snd_soc_new_ac97_component(component, WM9713_VENDOR_ID, wm9713->ac97 = snd_soc_new_ac97_component(component, WM9713_VENDOR_ID,
WM9713_VENDOR_ID_MASK); WM9713_VENDOR_ID_MASK);
if (IS_ERR(wm9713->ac97)) if (IS_ERR(wm9713->ac97))
...@@ -1225,7 +1224,8 @@ static int wm9713_soc_probe(struct snd_soc_component *component) ...@@ -1225,7 +1224,8 @@ static int wm9713_soc_probe(struct snd_soc_component *component)
snd_soc_free_ac97_component(wm9713->ac97); snd_soc_free_ac97_component(wm9713->ac97);
return PTR_ERR(regmap); return PTR_ERR(regmap);
} }
#endif } else {
return -ENXIO;
} }
snd_soc_component_init_regmap(component, regmap); snd_soc_component_init_regmap(component, regmap);
...@@ -1238,14 +1238,12 @@ static int wm9713_soc_probe(struct snd_soc_component *component) ...@@ -1238,14 +1238,12 @@ static int wm9713_soc_probe(struct snd_soc_component *component)
static void wm9713_soc_remove(struct snd_soc_component *component) static void wm9713_soc_remove(struct snd_soc_component *component)
{ {
#ifdef CONFIG_SND_SOC_AC97_BUS
struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component);
if (!wm9713->mfd_pdata) { if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS) && !wm9713->mfd_pdata) {
snd_soc_component_exit_regmap(component); snd_soc_component_exit_regmap(component);
snd_soc_free_ac97_component(wm9713->ac97); snd_soc_free_ac97_component(wm9713->ac97);
} }
#endif
} }
static const struct snd_soc_component_driver soc_component_dev_wm9713 = { static const struct snd_soc_component_driver soc_component_dev_wm9713 = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment