ASoC: mediatek: fix coverity problems
Subsystems (3)
cover ASoC: mediatek: fix coverity problems
Coverity reports some UNINIT and CERT STR31-C problems, so we add initialization and dai id check to resolve problems.
Trevor Wu (4):
ASoC: mediatek: mt8195: add dai id check before accessing array
ASoC: mediatek: mt9195-mt6359: fix UNINIT problem
ASoC: mediatek: mt6358: fix UNINIT problem
ASoC: mediatek: mt6359: fix UNINIT problem
sound/soc/codecs/mt6358.c | 2 +- sound/soc/codecs/mt6359.c | 2 +- sound/soc/mediatek/mt8195/mt8195-dai-adda.c | 17 +- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 177 +++++++++++++++++--- sound/soc/mediatek/mt8195/mt8195-dai-pcm.c | 26 ++- sound/soc/mediatek/mt8195/mt8195-mt6359.c | 2 +- 6 files changed, 188 insertions(+), 38 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/4 ASoC: mediatek: mt8195: add dai id check before accessing array
Coverity shows "afe_priv->dai_priv[dai_id] evaluates to an address that could be at negative offset of an array.". Add dai id check before accessing the array element. This ensures that the offset of an array must be a valid index.
--- sound/soc/mediatek/mt8195/mt8195-dai-adda.c | 17 +- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 177 +++++++++++++++++--- sound/soc/mediatek/mt8195/mt8195-dai-pcm.c | 26 ++- 3 files changed, 185 insertions(+), 35 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-adda.c +11 -6
@@ -704,13 +704,18 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_adda_priv *adda_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_adda_priv *adda_priv;unsigned int rate =params_rate (params); -int id = dai->id; -int ret =0 ; +int ret; + +if (dai->id !=MT8195_AFE_IO_DL_SRC && + dai->id !=MT8195_AFE_IO_UL_SRC1 && + dai->id !=MT8195_AFE_IO_UL_SRC2 ) +return -EINVAL ; + adda_priv = afe_priv->dai_priv[dai->id];dev_dbg (afe->dev,"%s(), id %d, stream %d, rate %d\n" , - __func__, id, substream->stream, rate); + __func__, dai->id, substream->stream, rate);if (rate >ADDA_HIRES_THRES ) adda_priv->hires_required =1 ;
@@ -718,9 +723,9 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, adda_priv->hires_required =0 ;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) - ret =mtk_dai_da_configure (afe, rate, id); + ret =mtk_dai_da_configure (afe, rate, dai->id);else - ret =mtk_dai_ad_configure (afe, rate, id); + ret =mtk_dai_ad_configure (afe, rate, dai->id);return ret; }
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +154 -23
371 lines not on this page · raw message
sound/soc/mediatek/mt8195/mt8195-dai-pcm.c +20 -6
@@ -122,17 +122,26 @@ static int mtk_dai_pcm_configure(struct snd_pcm_substream *substream,struct snd_pcm_runtime *const runtime = substream->runtime;struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; -unsigned int slave_mode = pcmif_priv->slave_mode; -unsigned int lrck_inv = pcmif_priv->lrck_inv; -unsigned int bck_inv = pcmif_priv->bck_inv; -unsigned int fmt = pcmif_priv->format; +struct mtk_dai_pcmif_priv *pcmif_priv; +unsigned int slave_mode; +unsigned int lrck_inv; +unsigned int bck_inv; +unsigned int fmt;unsigned int bit_width = dai->sample_bits;unsigned int val =0 ;unsigned int mask =0 ;int fs =0 ;int mode =0 ; +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; + slave_mode = pcmif_priv->slave_mode; + lrck_inv = pcmif_priv->lrck_inv; + bck_inv = pcmif_priv->bck_inv; + fmt = pcmif_priv->format; +/* sync freq mode */ fs =mt8195_afe_fs_timing (runtime->rate);if (fs <0 )
@@ -230,10 +239,15 @@ static int mtk_dai_pcm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_pcmif_priv *pcmif_priv;dev_dbg (dai->dev,"%s fmt 0x%x\n" , __func__, fmt); +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : pcmif_priv->format =MTK_DAI_PCM_FMT_I2S ;
Signature · 1 line
2.18.0
PATCH 2/4 ASoC: mediatek: mt9195-mt6359: fix UNINIT problem
In reply to Trevor WuCoverity shows using uninitialized value monitor. When regmap_read returns an error, monitor keeps the value left from earlier computation. To prevent from the unexpected result in the case, assign 0 to monitor.
--- sound/soc/mediatek/mt8195/mt8195-mt6359.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/mediatek/mt8195/mt8195-mt6359.c +1 -1
@@ -158,7 +158,7 @@ static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM ];int mtkaif_calibration_num_phase;bool mtkaif_calibration_ok; -unsigned int monitor; +unsigned int monitor =0 ;int counter;int phase;int i;
Signature · 1 line
2.18.0
PATCH 3/4 ASoC: mediatek: mt6358: fix UNINIT problem
In reply to Trevor WuCoverity shows decaring variable reg without initializer. When regmap_read returns an error, reg keeps the value left from earlier computation. To prevent from the unexpected result in the case, assign 0 to reg.
--- sound/soc/codecs/mt6358.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/mt6358.c +1 -1
@@ -429,7 +429,7 @@ static int mt6358_put_volsw(struct snd_kcontrol *kcontrol,struct mt6358_priv *priv =snd_soc_component_get_drvdata (component);struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; -unsigned int reg; +unsigned int reg =0 ;int ret; ret =snd_soc_put_volsw (kcontrol, ucontrol);
Signature · 1 line
2.18.0
PATCH 4/4 ASoC: mediatek: mt6359: fix UNINIT problem
In reply to Trevor WuCoverity shows decaring variable reg without initializer. When regmap_read returns an error, reg keeps the value left from earlier computation. To prevent from the unexpected result in the case, assign 0 to reg.
--- sound/soc/codecs/mt6359.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/mt6359.c +1 -1
@@ -358,7 +358,7 @@ static int mt6359_put_volsw(struct snd_kcontrol *kcontrol,struct mt6359_priv *priv =snd_soc_component_get_drvdata (component);struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; -unsigned int reg; +unsigned int reg =0 ;int index = ucontrol->value.integer.value[0 ];int ret;
Signature · 1 line
2.18.0
PATCH 1/4 ASoC: mediatek: mt8195: add dai id check before accessing array
In reply to Trevor WuCoverity shows "afe_priv->dai_priv[dai_id] evaluates to an address that could be at negative offset of an array.". Add dai id check before accessing the array element. This ensures that the offset of an array must be a valid index.
--- sound/soc/mediatek/mt8195/mt8195-dai-adda.c | 17 +- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 177 +++++++++++++++++--- sound/soc/mediatek/mt8195/mt8195-dai-pcm.c | 26 ++- 3 files changed, 185 insertions(+), 35 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-adda.c +11 -6
@@ -704,13 +704,18 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_adda_priv *adda_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_adda_priv *adda_priv;unsigned int rate =params_rate (params); -int id = dai->id; -int ret =0 ; +int ret; + +if (dai->id !=MT8195_AFE_IO_DL_SRC && + dai->id !=MT8195_AFE_IO_UL_SRC1 && + dai->id !=MT8195_AFE_IO_UL_SRC2 ) +return -EINVAL ; + adda_priv = afe_priv->dai_priv[dai->id];dev_dbg (afe->dev,"%s(), id %d, stream %d, rate %d\n" , - __func__, id, substream->stream, rate); + __func__, dai->id, substream->stream, rate);if (rate >ADDA_HIRES_THRES ) adda_priv->hires_required =1 ;
@@ -718,9 +723,9 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, adda_priv->hires_required =0 ;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) - ret =mtk_dai_da_configure (afe, rate, id); + ret =mtk_dai_da_configure (afe, rate, dai->id);else - ret =mtk_dai_ad_configure (afe, rate, id); + ret =mtk_dai_ad_configure (afe, rate, dai->id);return ret; }
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +154 -23
371 lines not on this page · raw message
sound/soc/mediatek/mt8195/mt8195-dai-pcm.c +20 -6
@@ -122,17 +122,26 @@ static int mtk_dai_pcm_configure(struct snd_pcm_substream *substream,struct snd_pcm_runtime *const runtime = substream->runtime;struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; -unsigned int slave_mode = pcmif_priv->slave_mode; -unsigned int lrck_inv = pcmif_priv->lrck_inv; -unsigned int bck_inv = pcmif_priv->bck_inv; -unsigned int fmt = pcmif_priv->format; +struct mtk_dai_pcmif_priv *pcmif_priv; +unsigned int slave_mode; +unsigned int lrck_inv; +unsigned int bck_inv; +unsigned int fmt;unsigned int bit_width = dai->sample_bits;unsigned int val =0 ;unsigned int mask =0 ;int fs =0 ;int mode =0 ; +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; + slave_mode = pcmif_priv->slave_mode; + lrck_inv = pcmif_priv->lrck_inv; + bck_inv = pcmif_priv->bck_inv; + fmt = pcmif_priv->format; +/* sync freq mode */ fs =mt8195_afe_fs_timing (runtime->rate);if (fs <0 )
@@ -230,10 +239,15 @@ static int mtk_dai_pcm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_pcmif_priv *pcmif_priv;dev_dbg (dai->dev,"%s fmt 0x%x\n" , __func__, fmt); +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : pcmif_priv->format =MTK_DAI_PCM_FMT_I2S ;
Signature · 1 line
2.18.0
PATCH 1/4 ASoC: mediatek: mt8195: add dai id check before accessing array
In reply to Trevor WuCoverity shows "afe_priv->dai_priv[dai_id] evaluates to an address that could be at negative offset of an array.". Add dai id check before accessing the array element. This ensures that the offset of an array must be a valid index.
--- sound/soc/mediatek/mt8195/mt8195-dai-adda.c | 17 +- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 177 +++++++++++++++++--- sound/soc/mediatek/mt8195/mt8195-dai-pcm.c | 26 ++- 3 files changed, 185 insertions(+), 35 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-adda.c +11 -6
@@ -704,13 +704,18 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_adda_priv *adda_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_adda_priv *adda_priv;unsigned int rate =params_rate (params); -int id = dai->id; -int ret =0 ; +int ret; + +if (dai->id !=MT8195_AFE_IO_DL_SRC && + dai->id !=MT8195_AFE_IO_UL_SRC1 && + dai->id !=MT8195_AFE_IO_UL_SRC2 ) +return -EINVAL ; + adda_priv = afe_priv->dai_priv[dai->id];dev_dbg (afe->dev,"%s(), id %d, stream %d, rate %d\n" , - __func__, id, substream->stream, rate); + __func__, dai->id, substream->stream, rate);if (rate >ADDA_HIRES_THRES ) adda_priv->hires_required =1 ;
@@ -718,9 +723,9 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, adda_priv->hires_required =0 ;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) - ret =mtk_dai_da_configure (afe, rate, id); + ret =mtk_dai_da_configure (afe, rate, dai->id);else - ret =mtk_dai_ad_configure (afe, rate, id); + ret =mtk_dai_ad_configure (afe, rate, dai->id);return ret; }
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +154 -23
371 lines not on this page · raw message
sound/soc/mediatek/mt8195/mt8195-dai-pcm.c +20 -6
@@ -122,17 +122,26 @@ static int mtk_dai_pcm_configure(struct snd_pcm_substream *substream,struct snd_pcm_runtime *const runtime = substream->runtime;struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; -unsigned int slave_mode = pcmif_priv->slave_mode; -unsigned int lrck_inv = pcmif_priv->lrck_inv; -unsigned int bck_inv = pcmif_priv->bck_inv; -unsigned int fmt = pcmif_priv->format; +struct mtk_dai_pcmif_priv *pcmif_priv; +unsigned int slave_mode; +unsigned int lrck_inv; +unsigned int bck_inv; +unsigned int fmt;unsigned int bit_width = dai->sample_bits;unsigned int val =0 ;unsigned int mask =0 ;int fs =0 ;int mode =0 ; +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; + slave_mode = pcmif_priv->slave_mode; + lrck_inv = pcmif_priv->lrck_inv; + bck_inv = pcmif_priv->bck_inv; + fmt = pcmif_priv->format; +/* sync freq mode */ fs =mt8195_afe_fs_timing (runtime->rate);if (fs <0 )
@@ -230,10 +239,15 @@ static int mtk_dai_pcm_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) {struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv; -struct mtk_dai_pcmif_priv *pcmif_priv = afe_priv->dai_priv[dai->id]; +struct mtk_dai_pcmif_priv *pcmif_priv;dev_dbg (dai->dev,"%s fmt 0x%x\n" , __func__, fmt); +if (dai->id !=MT8195_AFE_IO_PCM ) +return -EINVAL ; + + pcmif_priv = afe_priv->dai_priv[dai->id]; +switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {case SND_SOC_DAIFMT_I2S : pcmif_priv->format =MTK_DAI_PCM_FMT_I2S ;
Signature · 1 line
2.18.0
PATCH 2/4 ASoC: mediatek: mt9195-mt6359: fix UNINIT problem
In reply to Trevor WuCoverity shows using uninitialized value monitor. When regmap_read returns an error, monitor keeps the value left from earlier computation. To prevent from the unexpected result in the case, assign 0 to monitor.
--- sound/soc/mediatek/mt8195/mt8195-mt6359.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/mediatek/mt8195/mt8195-mt6359.c +1 -1
@@ -158,7 +158,7 @@ static int mt8195_mt6359_mtkaif_calibration(struct snd_soc_pcm_runtime *rtd)int mtkaif_phase_cycle[MT8195_MTKAIF_MISO_NUM ];int mtkaif_calibration_num_phase;bool mtkaif_calibration_ok; -unsigned int monitor; +unsigned int monitor =0 ;int counter;int phase;int i;
Signature · 1 line
2.18.0
PATCH 3/4 ASoC: mediatek: mt6358: fix UNINIT problem
In reply to Trevor WuCoverity shows decaring variable reg without initializer. When regmap_read returns an error, reg keeps the value left from earlier computation. To prevent from the unexpected result in the case, assign 0 to reg.
--- sound/soc/codecs/mt6358.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/mt6358.c +1 -1
@@ -429,7 +429,7 @@ static int mt6358_put_volsw(struct snd_kcontrol *kcontrol,struct mt6358_priv *priv =snd_soc_component_get_drvdata (component);struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; -unsigned int reg; +unsigned int reg =0 ;int ret; ret =snd_soc_put_volsw (kcontrol, ucontrol);
Signature · 1 line
2.18.0
PATCH 4/4 ASoC: mediatek: mt6359: fix UNINIT problem
In reply to Trevor WuCoverity shows decaring variable reg without initializer. When regmap_read returns an error, reg keeps the value left from earlier computation. To prevent from the unexpected result in the case, assign 0 to reg.
--- sound/soc/codecs/mt6359.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/mt6359.c +1 -1
@@ -358,7 +358,7 @@ static int mt6359_put_volsw(struct snd_kcontrol *kcontrol,struct mt6359_priv *priv =snd_soc_component_get_drvdata (component);struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; -unsigned int reg; +unsigned int reg =0 ;int index = ucontrol->value.integer.value[0 ];int ret;
Signature · 1 line
2.18.0
Mark Brown
maintainerQuoted 10 lines · Trevor Wu
Coverity reports some UNINIT and CERT STR31-C problems, so we add initialization and dai id check to resolve problems.
Trevor Wu (4):
ASoC: mediatek: mt8195: add dai id check before accessing array
ASoC: mediatek: mt9195-mt6359: fix UNINIT problem
ASoC: mediatek: mt6358: fix UNINIT problem
ASoC: mediatek: mt6359: fix UNINIT problem[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/4] ASoC: mediatek: mt8195: add dai id check before accessing array
commit: ff728899065922534d80170685fb807194d6487b
[2/4] ASoC: mediatek: mt9195-mt6359: fix UNINIT problem
commit: 1a3f0116b74ba2f9477c28fcf9d66ac7126455fd
[3/4] ASoC: mediatek: mt6358: fix UNINIT problem
commit: 9760e01b3851dc51d1901876668168328d34a647
[4/4] ASoC: mediatek: mt6359: fix UNINIT problem
commit: 3a60fa4c063dacc5eb66660aa23107f3cb8a477eAll being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark