diff mbox series

[1/2] ASoC: SOF: Prevent NULL dereference in sof_pcm_dai_link_fixup()

Message ID 20220318071233.GB29472@kili (mailing list archive)
State New, archived
Headers show
Series [1/2] ASoC: SOF: Prevent NULL dereference in sof_pcm_dai_link_fixup() | expand

Commit Message

Dan Carpenter March 18, 2022, 7:12 a.m. UTC
The "dia" pointer can be NULL, so handle that condition first before
storing "dia->private".

Fixes: 839e484f9e17 ("ASoC: SOF: make struct snd_sof_dai IPC agnostic")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 sound/soc/sof/pcm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Pierre-Louis Bossart March 18, 2022, 2:42 p.m. UTC | #1
On 3/18/22 02:12, Dan Carpenter wrote:
> The "dia" pointer can be NULL, so handle that condition first before
> storing "dia->private".
> 
> Fixes: 839e484f9e17 ("ASoC: SOF: make struct snd_sof_dai IPC agnostic")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks for the patch.

This part will be removed in follow-up patches, likely the reason why 
this problem was missed.

Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

> ---
>   sound/soc/sof/pcm.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
> index 1661b0bc6f12..71f5bce0c4c7 100644
> --- a/sound/soc/sof/pcm.c
> +++ b/sound/soc/sof/pcm.c
> @@ -702,7 +702,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
>   	struct snd_sof_dai *dai =
>   		snd_sof_find_dai(component, (char *)rtd->dai_link->name);
>   	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
> -	struct sof_dai_private_data *private = dai->private;
> +	struct sof_dai_private_data *private;
>   	struct snd_soc_dpcm *dpcm;
>   
>   	/* no topology exists for this BE, try a common configuration */
> @@ -727,6 +727,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
>   	/* read format from topology */
>   	snd_mask_none(fmt);
>   
> +	private = dai->private;
>   	switch (private->comp_dai->config.frame_fmt) {
>   	case SOF_IPC_FRAME_S16_LE:
>   		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
Ranjani Sridharan March 18, 2022, 4:14 p.m. UTC | #2
On Fri, 2022-03-18 at 09:42 -0500, Pierre-Louis Bossart wrote:
> 
> On 3/18/22 02:12, Dan Carpenter wrote:
> > The "dia" pointer can be NULL, so handle that condition first
> > before
> > storing "dia->private".
> > 
> > Fixes: 839e484f9e17 ("ASoC: SOF: make struct snd_sof_dai IPC
> > agnostic")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thanks for the patch.
> 
> This part will be removed in follow-up patches, likely the reason
> why 
> this problem was missed.

Hi Dan/Pierre,

Both these problems are address in the series I posted yesterday.
Particularly patches 16 and 18.

Thanks,
Ranjani
> 
> Acked-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
> 
> > ---
> >   sound/soc/sof/pcm.c | 3 ++-
> >   1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
> > index 1661b0bc6f12..71f5bce0c4c7 100644
> > --- a/sound/soc/sof/pcm.c
> > +++ b/sound/soc/sof/pcm.c
> > @@ -702,7 +702,7 @@ int sof_pcm_dai_link_fixup(struct
> > snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
> >   	struct snd_sof_dai *dai =
> >   		snd_sof_find_dai(component, (char *)rtd->dai_link-
> > >name);
> >   	struct snd_sof_dev *sdev =
> > snd_soc_component_get_drvdata(component);
> > -	struct sof_dai_private_data *private = dai->private;
> > +	struct sof_dai_private_data *private;
> >   	struct snd_soc_dpcm *dpcm;
> >   
> >   	/* no topology exists for this BE, try a common configuration
> > */
> > @@ -727,6 +727,7 @@ int sof_pcm_dai_link_fixup(struct
> > snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
> >   	/* read format from topology */
> >   	snd_mask_none(fmt);
> >   
> > +	private = dai->private;
> >   	switch (private->comp_dai->config.frame_fmt) {
> >   	case SOF_IPC_FRAME_S16_LE:
> >   		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
Mark Brown March 18, 2022, 5:49 p.m. UTC | #3
On Fri, Mar 18, 2022 at 09:14:55AM -0700, Ranjani Sridharan wrote:
> On Fri, 2022-03-18 at 09:42 -0500, Pierre-Louis Bossart wrote:

> > This part will be removed in follow-up patches, likely the reason
> > why 
> > this problem was missed.

> Both these problems are address in the series I posted yesterday.
> Particularly patches 16 and 18.

OK, I've got that patch series queued already so I'll skip these for
now.
Curtis Malainey March 20, 2022, 2:33 p.m. UTC | #4
On Sun, Mar 20, 2022, 12:10 AM Dan Carpenter <dan.carpenter@oracle.com>
wrote:

> The "dia" pointer can be NULL, so handle that condition first before
> storing "dia->private".
>

Typo in commit message, it is DAI in code, not dia.


> Fixes: 839e484f9e17 ("ASoC: SOF: make struct snd_sof_dai IPC agnostic")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  sound/soc/sof/pcm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
> index 1661b0bc6f12..71f5bce0c4c7 100644
> --- a/sound/soc/sof/pcm.c
> +++ b/sound/soc/sof/pcm.c
> @@ -702,7 +702,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime
> *rtd, struct snd_pcm_hw_pa
>         struct snd_sof_dai *dai =
>                 snd_sof_find_dai(component, (char *)rtd->dai_link->name);
>         struct snd_sof_dev *sdev =
> snd_soc_component_get_drvdata(component);
> -       struct sof_dai_private_data *private = dai->private;
> +       struct sof_dai_private_data *private;
>         struct snd_soc_dpcm *dpcm;
>
>         /* no topology exists for this BE, try a common configuration */
> @@ -727,6 +727,7 @@ int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime
> *rtd, struct snd_pcm_hw_pa
>         /* read format from topology */
>         snd_mask_none(fmt);
>
> +       private = dai->private;
>         switch (private->comp_dai->config.frame_fmt) {
>         case SOF_IPC_FRAME_S16_LE:
>                 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);
> --
> 2.20.1
>
> _______________________________________________
> Sound-open-firmware mailing list
> Sound-open-firmware@alsa-project.org
> https://mailman.alsa-project.org/mailman/listinfo/sound-open-firmware
>
diff mbox series

Patch

diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c
index 1661b0bc6f12..71f5bce0c4c7 100644
--- a/sound/soc/sof/pcm.c
+++ b/sound/soc/sof/pcm.c
@@ -702,7 +702,7 @@  int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
 	struct snd_sof_dai *dai =
 		snd_sof_find_dai(component, (char *)rtd->dai_link->name);
 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
-	struct sof_dai_private_data *private = dai->private;
+	struct sof_dai_private_data *private;
 	struct snd_soc_dpcm *dpcm;
 
 	/* no topology exists for this BE, try a common configuration */
@@ -727,6 +727,7 @@  int sof_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_pa
 	/* read format from topology */
 	snd_mask_none(fmt);
 
+	private = dai->private;
 	switch (private->comp_dai->config.frame_fmt) {
 	case SOF_IPC_FRAME_S16_LE:
 		snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S16_LE);