diff mbox series

ASoC: mt8365: Fix using uninitialized value "i2s_data" issue

Message ID 20240911001516.47268-1-qianqiang.liu@163.com (mailing list archive)
State New
Headers show
Series ASoC: mt8365: Fix using uninitialized value "i2s_data" issue | expand

Commit Message

Qianqiang Liu Sept. 11, 2024, 12:15 a.m. UTC
The "i2s_data" might not be initialized before using it.
Set it to NULL by default and also check if it is valid.

Signed-off-by: Qianqiang Liu <qianqiang.liu@163.com>
---
 sound/soc/mediatek/mt8365/mt8365-dai-i2s.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Mark Brown Sept. 11, 2024, 10:52 a.m. UTC | #1
On Wed, Sep 11, 2024 at 08:15:17AM +0800, Qianqiang Liu wrote:

>  
>  	spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags);
>  
> +	if (!i2s_data) {
> +		spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags);
> +		return;
> +	}
> +

Why would we look up i2s_data without the lock, take the lock, then
check if we actually found it?  That doesn't seem right.
Qianqiang Liu Sept. 11, 2024, 11:36 a.m. UTC | #2
On Wed, Sep 11, 2024 at 11:52:58AM +0100, Mark Brown wrote:
> On Wed, Sep 11, 2024 at 08:15:17AM +0800, Qianqiang Liu wrote:
> 
> >  
> >  	spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags);
> >  
> > +	if (!i2s_data) {
> > +		spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags);
> > +		return;
> > +	}
> > +
> 
> Why would we look up i2s_data without the lock, take the lock, then
> check if we actually found it?  That doesn't seem right.

Just check the "i2s_data" is NULL or not.
Mark Brown Sept. 11, 2024, 11:41 a.m. UTC | #3
On Wed, Sep 11, 2024 at 07:36:33PM +0800, Qianqiang Liu wrote:
> On Wed, Sep 11, 2024 at 11:52:58AM +0100, Mark Brown wrote:
> > On Wed, Sep 11, 2024 at 08:15:17AM +0800, Qianqiang Liu wrote:

> > >  	spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags);

> > > +	if (!i2s_data) {
> > > +		spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags);
> > > +		return;
> > > +	}

> > Why would we look up i2s_data without the lock, take the lock, then
> > check if we actually found it?  That doesn't seem right.

> Just check the "i2s_data" is NULL or not.

That doesn't address my question at all.
Qianqiang Liu Sept. 11, 2024, 12:02 p.m. UTC | #4
On Wed, Sep 11, 2024 at 12:41:15PM +0100, Mark Brown wrote:
> On Wed, Sep 11, 2024 at 07:36:33PM +0800, Qianqiang Liu wrote:
> > On Wed, Sep 11, 2024 at 11:52:58AM +0100, Mark Brown wrote:
> > > On Wed, Sep 11, 2024 at 08:15:17AM +0800, Qianqiang Liu wrote:
> 
> > > >  	spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags);
> 
> > > > +	if (!i2s_data) {
> > > > +		spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags);
> > > > +		return;
> > > > +	}
> 
> > > Why would we look up i2s_data without the lock, take the lock, then
> > > check if we actually found it?  That doesn't seem right.
> 
> > Just check the "i2s_data" is NULL or not.
> 
> That doesn't address my question at all.

How about this new patch:

diff --git a/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c b/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c
index 3482d8f8b4e7..11b9a5bc7163 100644
--- a/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c
+++ b/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c
@@ -465,13 +465,16 @@ void mt8365_afe_set_i2s_out_enable(struct mtk_base_afe *afe, bool enable)
 	int i;
 	unsigned long flags;
 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
-	struct mtk_afe_i2s_priv *i2s_data;
+	struct mtk_afe_i2s_priv *i2s_data = NULL;
 
 	for (i = 0; i < DAI_I2S_NUM; i++) {
 		if (mt8365_i2s_priv[i].adda_link)
 			i2s_data = afe_priv->dai_priv[mt8365_i2s_priv[i].id];
 	}
 
+	if (!i2s_data)
+		return;
+
 	spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags);
 
 	if (enable) {
Mark Brown Sept. 11, 2024, 12:07 p.m. UTC | #5
On Wed, Sep 11, 2024 at 08:02:38PM +0800, Qianqiang Liu wrote:

> How about this new patch:

That looks good, thanks but an equivalent patch has already been sent
and is in my queue:

    https://lore.kernel.org/r/20240911111317.4072349-1-usama.anjum@collabora.com
Qianqiang Liu Sept. 11, 2024, 12:11 p.m. UTC | #6
On Wed, Sep 11, 2024 at 01:07:52PM +0100, Mark Brown wrote:
> On Wed, Sep 11, 2024 at 08:02:38PM +0800, Qianqiang Liu wrote:
> 
> > How about this new patch:
> 
> That looks good, thanks but an equivalent patch has already been sent
> and is in my queue:
> 
>     https://lore.kernel.org/r/20240911111317.4072349-1-usama.anjum@collabora.com

OK, got it, thanks!
diff mbox series

Patch

diff --git a/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c b/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c
index 3482d8f8b4e7..3a8a5d975a04 100644
--- a/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c
+++ b/sound/soc/mediatek/mt8365/mt8365-dai-i2s.c
@@ -465,7 +465,7 @@  void mt8365_afe_set_i2s_out_enable(struct mtk_base_afe *afe, bool enable)
 	int i;
 	unsigned long flags;
 	struct mt8365_afe_private *afe_priv = afe->platform_priv;
-	struct mtk_afe_i2s_priv *i2s_data;
+	struct mtk_afe_i2s_priv *i2s_data = NULL;
 
 	for (i = 0; i < DAI_I2S_NUM; i++) {
 		if (mt8365_i2s_priv[i].adda_link)
@@ -474,6 +474,11 @@  void mt8365_afe_set_i2s_out_enable(struct mtk_base_afe *afe, bool enable)
 
 	spin_lock_irqsave(&afe_priv->afe_ctrl_lock, flags);
 
+	if (!i2s_data) {
+		spin_unlock_irqrestore(&afe_priv->afe_ctrl_lock, flags);
+		return;
+	}
+
 	if (enable) {
 		i2s_data->i2s_out_on_ref_cnt++;
 		if (i2s_data->i2s_out_on_ref_cnt == 1)