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>
This commit is contained in:
Родитель
8754f2263f
Коммит
c855a1a7ff
|
@ -1991,12 +1991,19 @@ static void max98095_handle_eq_pdata(struct snd_soc_codec *codec)
|
||||||
dev_err(codec->dev, "Failed to add EQ control: %d\n", ret);
|
dev_err(codec->dev, "Failed to add EQ control: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max98095_get_bq_channel(const char *name)
|
static const char *bq_mode_name[] = {"Biquad1 Mode", "Biquad2 Mode"};
|
||||||
|
|
||||||
|
static int max98095_get_bq_channel(struct snd_soc_codec *codec,
|
||||||
|
const char *name)
|
||||||
{
|
{
|
||||||
if (strcmp(name, "Biquad1 Mode") == 0)
|
int i;
|
||||||
return 0;
|
|
||||||
if (strcmp(name, "Biquad2 Mode") == 0)
|
for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
|
||||||
return 1;
|
if (strcmp(name, bq_mode_name[i]) == 0)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
/* Shouldn't happen */
|
||||||
|
dev_err(codec->dev, "Bad biquad channel name '%s'\n", name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2006,14 +2013,15 @@ static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
|
||||||
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
|
struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
|
||||||
struct max98095_pdata *pdata = max98095->pdata;
|
struct max98095_pdata *pdata = max98095->pdata;
|
||||||
int channel = max98095_get_bq_channel(kcontrol->id.name);
|
int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
|
||||||
struct max98095_cdata *cdata;
|
struct max98095_cdata *cdata;
|
||||||
int sel = ucontrol->value.integer.value[0];
|
int sel = ucontrol->value.integer.value[0];
|
||||||
struct max98095_biquad_cfg *coef_set;
|
struct max98095_biquad_cfg *coef_set;
|
||||||
int fs, best, best_val, i;
|
int fs, best, best_val, i;
|
||||||
int regmask, regsave;
|
int regmask, regsave;
|
||||||
|
|
||||||
BUG_ON(channel > 1);
|
if (channel < 0)
|
||||||
|
return channel;
|
||||||
|
|
||||||
if (!pdata || !max98095->bq_textcnt)
|
if (!pdata || !max98095->bq_textcnt)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2065,9 +2073,12 @@ static int max98095_get_bq_enum(struct snd_kcontrol *kcontrol,
|
||||||
{
|
{
|
||||||
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
||||||
struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
|
struct max98095_priv *max98095 = snd_soc_codec_get_drvdata(codec);
|
||||||
int channel = max98095_get_bq_channel(kcontrol->id.name);
|
int channel = max98095_get_bq_channel(codec, kcontrol->id.name);
|
||||||
struct max98095_cdata *cdata;
|
struct max98095_cdata *cdata;
|
||||||
|
|
||||||
|
if (channel < 0)
|
||||||
|
return channel;
|
||||||
|
|
||||||
cdata = &max98095->dai[channel];
|
cdata = &max98095->dai[channel];
|
||||||
ucontrol->value.enumerated.item[0] = cdata->bq_sel;
|
ucontrol->value.enumerated.item[0] = cdata->bq_sel;
|
||||||
|
|
||||||
|
@ -2085,15 +2096,16 @@ static void max98095_handle_bq_pdata(struct snd_soc_codec *codec)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
struct snd_kcontrol_new controls[] = {
|
struct snd_kcontrol_new controls[] = {
|
||||||
SOC_ENUM_EXT("Biquad1 Mode",
|
SOC_ENUM_EXT((char *)bq_mode_name[0],
|
||||||
max98095->bq_enum,
|
max98095->bq_enum,
|
||||||
max98095_get_bq_enum,
|
max98095_get_bq_enum,
|
||||||
max98095_put_bq_enum),
|
max98095_put_bq_enum),
|
||||||
SOC_ENUM_EXT("Biquad2 Mode",
|
SOC_ENUM_EXT((char *)bq_mode_name[1],
|
||||||
max98095->bq_enum,
|
max98095->bq_enum,
|
||||||
max98095_get_bq_enum,
|
max98095_get_bq_enum,
|
||||||
max98095_put_bq_enum),
|
max98095_put_bq_enum),
|
||||||
};
|
};
|
||||||
|
BUILD_BUG_ON(ARRAY_SIZE(controls) != ARRAY_SIZE(bq_mode_name));
|
||||||
|
|
||||||
cfg = pdata->bq_cfg;
|
cfg = pdata->bq_cfg;
|
||||||
cfgcnt = pdata->bq_cfgcnt;
|
cfgcnt = pdata->bq_cfgcnt;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче