The afe_priv->dai_priv[] is allocated when platform driver probe(), if it
failed, the ASoC platform driver probe() will return fail first.
Therefore, this is excessive judgment, and the condition will never be
established.
Bug report: https://www.spinics.net/lists/alsa-devel/msg145609.html
This is a semi-automatic email about new static checker warnings.
The patch
ae92dcbee8b6: "ASoC: mediatek: mt8186: support tdm in
platform driver" from May 23, 2022, leads to the following Smatch
complaint:
sound/soc/mediatek/mt8186/mt8186-dai-tdm.c:424 mtk_dai_tdm_hw_params()
warn: variable dereferenced before check 'tdm_priv' (see line 406)
sound/soc/mediatek/mt8186/mt8186-dai-tdm.c
405 struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[tdm_id];
406 unsigned int tdm_mode = tdm_priv->tdm_mode;
^^^^^^^^^^^^^^^^^^^
Lot's of dereferences
407 unsigned int data_mode = tdm_priv->data_mode;
408 unsigned int rate = params_rate(params);
409 unsigned int channels = params_channels(params);
410 snd_pcm_format_t format = params_format(params);
411 unsigned int bit_width =
412 snd_pcm_format_physical_width(format);
413 unsigned int tdm_channels = (data_mode == TDM_DATA_ONE_PIN) ?
414 get_tdm_ch_per_sdata(tdm_mode, channels) : 2;
415 unsigned int lrck_width =
416 get_tdm_lrck_width(format, tdm_mode);
417 unsigned int tdm_con = 0;
418 bool slave_mode = tdm_priv->slave_mode;
419 bool lrck_inv = tdm_priv->lck_invert;
420 bool bck_inv = tdm_priv->bck_invert;
421 unsigned int tran_rate;
422 unsigned int tran_relatch_rate;
423
424 if (!tdm_priv) {
^^^^^^^^^
Checked too late
425 dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
426 return -EINVAL;
Fixes:
ae92dcbee8b6 ("ASoC: mediatek: mt8186: support tdm in platform driver")
Signed-off-by: Jiaxin Yu <jiaxin.yu@mediatek.com>
Link: https://lore.kernel.org/r/20220726154220.28141-1-jiaxin.yu@mediatek.com
Signed-off-by: Mark Brown <broonie@kernel.org>
dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n",
__func__, id, substream->stream, rate);
- if (!adda_priv) {
- dev_err(afe->dev, "%s(), adda_priv == NULL", __func__);
- return -EINVAL;
- }
-
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
unsigned int dl_src2_con0;
unsigned int dl_src2_con1;
struct mtk_afe_i2s_priv *i2s_priv;
i2s_priv = get_i2s_priv_by_name(afe, kcontrol->id.name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return -EINVAL;
- }
-
ucontrol->value.integer.value[0] = i2s_priv->low_jitter_en;
return 0;
__func__, kcontrol->id.name, hd_en);
i2s_priv = get_i2s_priv_by_name(afe, kcontrol->id.name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return -EINVAL;
- }
-
if (i2s_priv->low_jitter_en == hd_en)
return 0;
i2s_priv = get_i2s_priv_by_name(afe, w->name);
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return -EINVAL;
- }
-
dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
__func__, w->name, event);
i2s_priv = get_i2s_priv_by_name(afe, w->name);
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return -EINVAL;
- }
-
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
mt8186_mck_enable(afe, i2s_priv->mclk_id, i2s_priv->mclk_rate);
struct mtk_afe_i2s_priv *i2s_priv;
i2s_priv = get_i2s_priv_by_name(afe, sink->name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return 0;
- }
-
if (i2s_priv->share_i2s_id < 0)
return 0;
struct mtk_afe_i2s_priv *i2s_priv;
i2s_priv = get_i2s_priv_by_name(afe, sink->name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return 0;
- }
-
if (get_i2s_id_by_name(afe, sink->name) ==
get_i2s_id_by_name(afe, source->name))
return i2s_priv->low_jitter_en;
int i2s_need_apll;
i2s_priv = get_i2s_priv_by_name(afe, w->name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return 0;
- }
-
/* which apll */
cur_apll = mt8186_get_apll_by_name(afe, source->name);
-
/* choose APLL from i2s rate */
i2s_need_apll = mt8186_get_apll_by_rate(afe, i2s_priv->rate);
struct mtk_afe_i2s_priv *i2s_priv;
i2s_priv = get_i2s_priv_by_name(afe, sink->name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return 0;
- }
-
if (get_i2s_id_by_name(afe, sink->name) ==
get_i2s_id_by_name(afe, source->name))
return (i2s_priv->mclk_rate > 0) ? 1 : 0;
int cur_apll;
i2s_priv = get_i2s_priv_by_name(afe, w->name);
-
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return 0;
- }
-
/* which apll */
cur_apll = mt8186_get_apll_by_name(afe, source->name);
dev_dbg(afe->dev, "%s(), id %d, rate %d, format %d\n",
__func__, i2s_id, rate, format);
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return -EINVAL;
- }
-
i2s_priv->rate = rate;
switch (i2s_id) {
int apll;
int apll_rate;
- if (!i2s_priv) {
- dev_err(afe->dev, "%s(), i2s_priv == NULL", __func__);
- return -EINVAL;
- }
-
if (dir != SND_SOC_CLOCK_OUT) {
dev_err(afe->dev, "%s(), dir != SND_SOC_CLOCK_OUT", __func__);
return -EINVAL;
struct mt8186_afe_private *afe_priv = afe->platform_priv;
struct mtk_afe_pcm_priv *pcm_priv = afe_priv->dai_priv[dai->id];
- if (!pcm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
/* DAI mode*/
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
int dai_id = get_tdm_id_by_name(w->name);
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x\n",
__func__, w->name, event);
int dai_id = get_tdm_id_by_name(w->name);
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
dev_dbg(cmpnt->dev, "%s(), name %s, event 0x%x, dai_id %d\n",
__func__, w->name, event, dai_id);
int dai_id = get_tdm_id_by_name(w->name);
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return 0;
- }
-
return (tdm_priv->mclk_rate > 0) ? 1 : 0;
}
int dai_id = get_tdm_id_by_name(w->name);
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return 0;
- }
-
return tdm_priv->low_jitter_en;
}
int cur_apll;
int tdm_need_apll;
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return 0;
- }
-
/* which apll */
cur_apll = mt8186_get_apll_by_name(afe, source->name);
int dai_id = get_tdm_id_by_name(kcontrol->id.name);
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai_id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
ucontrol->value.integer.value[0] = tdm_priv->low_jitter_en;
return 0;
dev_dbg(afe->dev, "%s(), kcontrol name %s, hd_en %d\n",
__func__, kcontrol->id.name, hd_en);
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
if (tdm_priv->low_jitter_en == hd_en)
return 0;
unsigned int tran_rate;
unsigned int tran_relatch_rate;
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
tdm_priv->rate = rate;
-
tran_rate = mt8186_rate_transform(afe->dev, rate, dai->id);
tran_relatch_rate = mt8186_tdm_relatch_rate_transform(afe->dev, rate);
/* calculate mclk_rate, if not set explicitly */
if (!tdm_priv->mclk_rate) {
tdm_priv->mclk_rate = rate * tdm_priv->mclk_multiple;
- mtk_dai_tdm_cal_mclk(afe,
- tdm_priv,
- tdm_priv->mclk_rate);
+ mtk_dai_tdm_cal_mclk(afe, tdm_priv, tdm_priv->mclk_rate);
}
/* ETDM_IN1_CON0 */
struct mt8186_afe_private *afe_priv = afe->platform_priv;
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai->id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
if (dir != SND_SOC_CLOCK_IN) {
dev_err(afe->dev, "%s(), dir != SND_SOC_CLOCK_OUT", __func__);
return -EINVAL;
struct mt8186_afe_private *afe_priv = afe->platform_priv;
struct mtk_afe_tdm_priv *tdm_priv = afe_priv->dai_priv[dai->id];
- if (!tdm_priv) {
- dev_err(afe->dev, "%s(), tdm_priv == NULL", __func__);
- return -EINVAL;
- }
-
/* DAI mode*/
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S: