aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorRyan Mallon <rmallon@gmail.com>2011-10-03 18:55:41 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-10-04 07:03:47 -0400
commitc855a1a7ff49a43e1e35571d504e89b4c670693d (patch)
treebe6c0b28f833e829c5fd4e0021577867aa7a4a61 /sound
parent8754f2263fb0961c6dd26b4b4cbe73a4e632aa62 (diff)
ASoC: max98095 codec: Catch driver bugs for biquad channel name
Move the biquad channel names to a separate array and iterate over it in max98095_get_bq_channel rather than duplicating the hardcoded channel names. Add an error message if an invalid channel is passed and check the error in the callers. Also added a BUILD_BUG_ON to ensure that the bq_mode_name and controls arrays are the same size. Signed-off-by: Ryan Mallon <rmallon@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/max98095.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 8f8e2555cbed..6982f743c891 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -1991,12 +1991,19 @@ static void max98095_handle_eq_pdata(struct snd_soc_codec *codec)
1991 dev_err(codec->dev, "Failed to add EQ control: %d\n", ret); 1991 dev_err(codec->dev, "Failed to add EQ control: %d\n", ret);
1992} 1992}
1993 1993
1994static int max98095_get_bq_channel(const char *name) 1994static const char *bq_mode_name[] = {"Biquad1 Mode", "Biquad2 Mode"};
1995
1996static int max98095_get_bq_channel(struct snd_soc_codec *codec,
1997 const char *name)
1995{ 1998{
1996 if (strcmp(name, "Biquad1 Mode") == 0) 1999 int i;
1997 return 0; 2000
1998 if (strcmp(name, "Biquad2 Mode") == 0) 2001 for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
1999 return 1; 2002 if (strcmp(name, bq_mode_name[i]) == 0)
2003 return i;
2004
2005 /* Shouldn't happen */
2006 dev_err(codec->dev, "Bad biquad channel name '%s'\n", name);
2000 return -EINVAL; 2007 return -EINVAL;
2001} 2008}
2002 2009
@@ -2006,14 +2013,15 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
2006 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2013 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2007 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 2014 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2008 struct max98095_pdata *pdata = max98095->pdata; 2015 struct max98095_pdata *pdata = max98095->pdata;
2009 int channel = max98095_get_bq_channel(kcontrol->id.name); 2016 int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
2010 struct max98095_cdata *cdata; 2017 struct max98095_cdata *cdata;
2011 int sel = ucontrol->value.integer.value[0]; 2018 int sel = ucontrol->value.integer.value[0];
2012 struct max98095_biquad_cfg *coef_set; 2019 struct max98095_biquad_cfg *coef_set;
2013 int fs, best, best_val, i; 2020 int fs, best, best_val, i;
2014 int regmask, regsave; 2021 int regmask, regsave;
2015 2022
2016 BUG_ON(channel > 1); 2023 if (channel < 0)
2024 return channel;
2017 2025
2018 if (!pdata || !max98095->bq_textcnt) 2026 if (!pdata || !max98095->bq_textcnt)
2019 return 0; 2027 return 0;
@@ -2065,9 +2073,12 @@ static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol,
2065{ 2073{
2066 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 2074 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
2067 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec); 2075 struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
2068 int channel = max98095_get_bq_channel(kcontrol->id.name); 2076 int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
2069 struct max98095_cdata *cdata; 2077 struct max98095_cdata *cdata;
2070 2078
2079 if (channel < 0)
2080 return channel;
2081
2071 cdata = &max98095->dai[channel]; 2082 cdata = &max98095->dai[channel];
2072 ucontrol->value.enumerated.item[0] = cdata->bq_sel; 2083 ucontrol->value.enumerated.item[0] = cdata->bq_sel;
2073 2084
@@ -2085,15 +2096,16 @@ static void max98095_handle_bq_pdata(struct snd_soc_codec *codec)
2085 int ret; 2096 int ret;
2086 2097
2087 struct snd_kcontrol_new controls[] = { 2098 struct snd_kcontrol_new controls[] = {
2088 SOC_ENUM_EXT("Biquad1 Mode", 2099 SOC_ENUM_EXT((char *)bq_mode_name[0],
2089 max98095->bq_enum, 2100 max98095->bq_enum,
2090 max98095_get_bq_enum, 2101 max98095_get_bq_enum,
2091 max98095_put_bq_enum), 2102 max98095_put_bq_enum),
2092 SOC_ENUM_EXT("Biquad2 Mode", 2103 SOC_ENUM_EXT((char *)bq_mode_name[1],
2093 max98095->bq_enum, 2104 max98095->bq_enum,
2094 max98095_get_bq_enum, 2105 max98095_get_bq_enum,
2095 max98095_put_bq_enum), 2106 max98095_put_bq_enum),
2096 }; 2107 };
2108 BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(bq_mode_name));
2097 2109
2098 cfg = pdata->bq_cfg; 2110 cfg = pdata->bq_cfg;
2099 cfgcnt = pdata->bq_cfgcnt; 2111 cfgcnt = pdata->bq_cfgcnt;