[PATCH v2 2/2] ASoC: fsl: imx-card: initialize playback_only and capture_only

Shengjiu Wang posted 2 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCH v2 2/2] ASoC: fsl: imx-card: initialize playback_only and capture_only
Posted by Shengjiu Wang 3 weeks, 2 days ago
Fix uninitialized variable playback_only and capture_only because
graph_util_parse_link_direction() may not write them.

Fixes: 1877c3e7937f ("ASoC: imx-card: Add playback_only or capture_only support")
Suggested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
---
 sound/soc/fsl/imx-card.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
index 05b4e971a366..4dba52ecc602 100644
--- a/sound/soc/fsl/imx-card.c
+++ b/sound/soc/fsl/imx-card.c
@@ -544,7 +544,7 @@ static int imx_card_parse_of(struct imx_card_data *data)
 	struct snd_soc_dai_link *link;
 	struct dai_link_data *link_data;
 	struct of_phandle_args args;
-	bool playback_only, capture_only;
+	bool playback_only = false, capture_only = false;
 	int ret, num_links;
 	u32 asrc_fmt = 0;
 	u32 width;
-- 
2.34.1
Re: [PATCH v2 2/2] ASoC: fsl: imx-card: initialize playback_only and capture_only
Posted by Mark Brown 3 weeks, 1 day ago
On Tue, Mar 17, 2026 at 11:39:52AM +0800, Shengjiu Wang wrote:
> Fix uninitialized variable playback_only and capture_only because
> graph_util_parse_link_direction() may not write them.

> @@ -544,7 +544,7 @@ static int imx_card_parse_of(struct imx_card_data *data)
>  	struct snd_soc_dai_link *link;
>  	struct dai_link_data *link_data;
>  	struct of_phandle_args args;
> -	bool playback_only, capture_only;
> +	bool playback_only = false, capture_only = false;

Don't we need to initalise these once per link rather than once for the
whole function, otherwise if they are initialised one time then any
subsequent links will inherit the new value?
Re: [PATCH v2 2/2] ASoC: fsl: imx-card: initialize playback_only and capture_only
Posted by Kuninori Morimoto 3 weeks, 1 day ago
Hi

> > Fix uninitialized variable playback_only and capture_only because
> > graph_util_parse_link_direction() may not write them.
> 
> > @@ -544,7 +544,7 @@ static int imx_card_parse_of(struct imx_card_data *data)
> >  	struct snd_soc_dai_link *link;
> >  	struct dai_link_data *link_data;
> >  	struct of_phandle_args args;
> > -	bool playback_only, capture_only;
> > +	bool playback_only = false, capture_only = false;
> 
> Don't we need to initalise these once per link rather than once for the
> whole function, otherwise if they are initialised one time then any
> subsequent links will inherit the new value?

Ah, yes indeed. It is called under for_each loop.
So we need is...

------- 8< ------- 8< ------- 8< ------- 8< ------- 8< ------- 8< -------
diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
index 05b4e971a3661..a4518fefad690 100644
--- a/sound/soc/fsl/imx-card.c
+++ b/sound/soc/fsl/imx-card.c
@@ -710,6 +710,8 @@ static int imx_card_parse_of(struct imx_card_data *data)
 			link->ops = &imx_aif_ops;
 		}
 
+		playback_only = false;
+		capture_only  = false;
 		graph_util_parse_link_direction(np, &playback_only, &capture_only);
 		link->playback_only = playback_only;
 		link->capture_only = capture_only;





Thank you for your help !!

Best regards
---
Kuninori Morimoto
Re: [PATCH v2 2/2] ASoC: fsl: imx-card: initialize playback_only and capture_only
Posted by Shengjiu Wang 3 weeks, 1 day ago
On Wed, Mar 18, 2026 at 7:18 AM Kuninori Morimoto
<kuninori.morimoto.gx@renesas.com> wrote:
>
>
> Hi
>
> > > Fix uninitialized variable playback_only and capture_only because
> > > graph_util_parse_link_direction() may not write them.
> >
> > > @@ -544,7 +544,7 @@ static int imx_card_parse_of(struct imx_card_data *data)
> > >     struct snd_soc_dai_link *link;
> > >     struct dai_link_data *link_data;
> > >     struct of_phandle_args args;
> > > -   bool playback_only, capture_only;
> > > +   bool playback_only = false, capture_only = false;
> >
> > Don't we need to initalise these once per link rather than once for the
> > whole function, otherwise if they are initialised one time then any
> > subsequent links will inherit the new value?
>
> Ah, yes indeed. It is called under for_each loop.
> So we need is...
>
> ------- 8< ------- 8< ------- 8< ------- 8< ------- 8< ------- 8< -------
> diff --git a/sound/soc/fsl/imx-card.c b/sound/soc/fsl/imx-card.c
> index 05b4e971a3661..a4518fefad690 100644
> --- a/sound/soc/fsl/imx-card.c
> +++ b/sound/soc/fsl/imx-card.c
> @@ -710,6 +710,8 @@ static int imx_card_parse_of(struct imx_card_data *data)
>                         link->ops = &imx_aif_ops;
>                 }
>
> +               playback_only = false;
> +               capture_only  = false;
>                 graph_util_parse_link_direction(np, &playback_only, &capture_only);
>                 link->playback_only = playback_only;
>                 link->capture_only = capture_only;

This one may be better.  thanks.
I will update it.

best regards
shengjiu wang
>
>
>
>
>
> Thank you for your help !!
>
> Best regards
> ---
> Kuninori Morimoto
>