All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] ASoC: mediatek: mt8186: support tdm in platform driver
@ 2022-07-25  7:28 Dan Carpenter
  2022-07-25 13:24 ` Jiaxin Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-07-25  7:28 UTC (permalink / raw)
  To: jiaxin.yu; +Cc: alsa-devel

Hello Jiaxin Yu,

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;

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] ASoC: mediatek: mt8186: support tdm in platform driver
  2022-07-25  7:28 [bug report] ASoC: mediatek: mt8186: support tdm in platform driver Dan Carpenter
@ 2022-07-25 13:24 ` Jiaxin Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Jiaxin Yu @ 2022-07-25 13:24 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: alsa-devel

On Mon, 2022-07-25 at 10:28 +0300, Dan Carpenter wrote:
> Hello Jiaxin Yu,
> 
> 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;
> 
> regards,
> dan carpenter

Yes, it's a mistake.
In fact, the judgment here is really unnecessary. Because when
registering, if tdm_priv is NULL, registration will fail. So I will
remove this code, and check other DAI drivers, then remove judgments
link this.

Thanks,
Jiaxin.Yu



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-25 13:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-25  7:28 [bug report] ASoC: mediatek: mt8186: support tdm in platform driver Dan Carpenter
2022-07-25 13:24 ` Jiaxin Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.