Commit cadab0ae authored by Dan Murphy's avatar Dan Murphy Committed by Mark Brown

ASoC: tas2770: Fix error handling with update_bits

snd_soc_update_bits returns a 1 when the bit was successfully updated,
returns a 0 is no update was needed and a negative if the call failed.
The code is currently failing the case of a successful update by just
checking for a non-zero number. Modify these checks and return the error
code only if there is a negative.

Fixes: 1a476abc ("tas2770: add tas2770 smart PA kernel driver")
Signed-off-by: default avatarDan Murphy <dmurphy@ti.com>
Link: https://lore.kernel.org/r/20200918190548.12598-7-dmurphy@ti.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4b8ab8a7
...@@ -140,23 +140,18 @@ static int tas2770_dac_event(struct snd_soc_dapm_widget *w, ...@@ -140,23 +140,18 @@ static int tas2770_dac_event(struct snd_soc_dapm_widget *w,
TAS2770_PWR_CTRL, TAS2770_PWR_CTRL,
TAS2770_PWR_CTRL_MASK, TAS2770_PWR_CTRL_MASK,
TAS2770_PWR_CTRL_MUTE); TAS2770_PWR_CTRL_MUTE);
if (ret)
goto end;
break; break;
case SND_SOC_DAPM_PRE_PMD: case SND_SOC_DAPM_PRE_PMD:
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_PWR_CTRL, TAS2770_PWR_CTRL,
TAS2770_PWR_CTRL_MASK, TAS2770_PWR_CTRL_MASK,
TAS2770_PWR_CTRL_SHUTDOWN); TAS2770_PWR_CTRL_SHUTDOWN);
if (ret)
goto end;
break; break;
default: default:
dev_err(tas2770->dev, "Not supported evevt\n"); dev_err(tas2770->dev, "Not supported evevt\n");
return -EINVAL; return -EINVAL;
} }
end:
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -248,6 +243,9 @@ static int tas2770_set_bitwidth(struct tas2770_priv *tas2770, int bitwidth) ...@@ -248,6 +243,9 @@ static int tas2770_set_bitwidth(struct tas2770_priv *tas2770, int bitwidth)
return -EINVAL; return -EINVAL;
} }
if (ret < 0)
return ret;
tas2770->channel_size = bitwidth; tas2770->channel_size = bitwidth;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
...@@ -256,16 +254,15 @@ static int tas2770_set_bitwidth(struct tas2770_priv *tas2770, int bitwidth) ...@@ -256,16 +254,15 @@ static int tas2770_set_bitwidth(struct tas2770_priv *tas2770, int bitwidth)
TAS2770_TDM_CFG_REG5_50_MASK, TAS2770_TDM_CFG_REG5_50_MASK,
TAS2770_TDM_CFG_REG5_VSNS_ENABLE | TAS2770_TDM_CFG_REG5_VSNS_ENABLE |
tas2770->v_sense_slot); tas2770->v_sense_slot);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG6, TAS2770_TDM_CFG_REG6,
TAS2770_TDM_CFG_REG6_ISNS_MASK | TAS2770_TDM_CFG_REG6_ISNS_MASK |
TAS2770_TDM_CFG_REG6_50_MASK, TAS2770_TDM_CFG_REG6_50_MASK,
TAS2770_TDM_CFG_REG6_ISNS_ENABLE | TAS2770_TDM_CFG_REG6_ISNS_ENABLE |
tas2770->i_sense_slot); tas2770->i_sense_slot);
end:
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -283,36 +280,35 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate) ...@@ -283,36 +280,35 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate)
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_SMP_MASK, TAS2770_TDM_CFG_REG0_SMP_MASK,
TAS2770_TDM_CFG_REG0_SMP_48KHZ); TAS2770_TDM_CFG_REG0_SMP_48KHZ);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_31_MASK, TAS2770_TDM_CFG_REG0_31_MASK,
TAS2770_TDM_CFG_REG0_31_44_1_48KHZ); TAS2770_TDM_CFG_REG0_31_44_1_48KHZ);
if (ret)
goto end;
break; break;
case 44100: case 44100:
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_SMP_MASK, TAS2770_TDM_CFG_REG0_SMP_MASK,
TAS2770_TDM_CFG_REG0_SMP_44_1KHZ); TAS2770_TDM_CFG_REG0_SMP_44_1KHZ);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_31_MASK, TAS2770_TDM_CFG_REG0_31_MASK,
TAS2770_TDM_CFG_REG0_31_44_1_48KHZ); TAS2770_TDM_CFG_REG0_31_44_1_48KHZ);
if (ret)
goto end;
break; break;
case 96000: case 96000:
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_SMP_MASK, TAS2770_TDM_CFG_REG0_SMP_MASK,
TAS2770_TDM_CFG_REG0_SMP_48KHZ); TAS2770_TDM_CFG_REG0_SMP_48KHZ);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_31_MASK, TAS2770_TDM_CFG_REG0_31_MASK,
...@@ -323,8 +319,9 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate) ...@@ -323,8 +319,9 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate)
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_SMP_MASK, TAS2770_TDM_CFG_REG0_SMP_MASK,
TAS2770_TDM_CFG_REG0_SMP_44_1KHZ); TAS2770_TDM_CFG_REG0_SMP_44_1KHZ);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_31_MASK, TAS2770_TDM_CFG_REG0_31_MASK,
...@@ -335,22 +332,22 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate) ...@@ -335,22 +332,22 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate)
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_SMP_MASK, TAS2770_TDM_CFG_REG0_SMP_MASK,
TAS2770_TDM_CFG_REG0_SMP_48KHZ); TAS2770_TDM_CFG_REG0_SMP_48KHZ);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_31_MASK, TAS2770_TDM_CFG_REG0_31_MASK,
TAS2770_TDM_CFG_REG0_31_176_4_192KHZ); TAS2770_TDM_CFG_REG0_31_176_4_192KHZ);
if (ret)
goto end;
break; break;
case 17640: case 17640:
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_SMP_MASK, TAS2770_TDM_CFG_REG0_SMP_MASK,
TAS2770_TDM_CFG_REG0_SMP_44_1KHZ); TAS2770_TDM_CFG_REG0_SMP_44_1KHZ);
if (ret) if (ret < 0)
goto end; return ret;
ret = snd_soc_component_update_bits(component, ret = snd_soc_component_update_bits(component,
TAS2770_TDM_CFG_REG0, TAS2770_TDM_CFG_REG0,
TAS2770_TDM_CFG_REG0_31_MASK, TAS2770_TDM_CFG_REG0_31_MASK,
...@@ -360,7 +357,6 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate) ...@@ -360,7 +357,6 @@ static int tas2770_set_samplerate(struct tas2770_priv *tas2770, int samplerate)
ret = -EINVAL; ret = -EINVAL;
} }
end:
if (ret < 0) if (ret < 0)
return ret; return ret;
......
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