All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: simple-card: Dereference pointer for memcpy sizeof in asoc_simple_card_probe
@ 2018-12-13  4:35 Nathan Chancellor
  2018-12-13  5:07 ` Kuninori Morimoto
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2018-12-13  4:35 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Kuninori Morimoto, alsa-devel, linux-kernel, Nathan Chancellor

Clang warns:

sound/soc/generic/simple-card.c:462:6: warning: argument to 'sizeof' in
'memcpy' call is the same pointer type 'struct asoc_simple_dai *' as the
source; expected 'struct asoc_simple_dai' or an explicit length
[-Wsizeof-pointer-memaccess]
                                        sizeof(priv->dai_props->cpu_dai));
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sound/soc/generic/simple-card.c:464:6: warning: argument to 'sizeof' in
'memcpy' call is the same pointer type 'struct asoc_simple_dai *' as the
source; expected 'struct asoc_simple_dai' or an explicit length
[-Wsizeof-pointer-memaccess]
                                        sizeof(priv->dai_props->codec_dai));
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

Commit 4fb7f4df49d3 ("ASoC: simple-card: use cpu/codec pointer on
simple_dai_props") updated {cpu,codec}_dai to be pointers in struct
simple_dai_props but didn't update these locations to dereference the
pointers to get the proper size of their contents.

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 sound/soc/generic/simple-card.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 766123485d7c..d4738d3eb2f1 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -459,9 +459,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
 		dai_link->dai_fmt	= cinfo->daifmt;
 		dai_link->init		= asoc_simple_card_dai_init;
 		memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai,
-					sizeof(priv->dai_props->cpu_dai));
+					sizeof(*priv->dai_props->cpu_dai));
 		memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai,
-					sizeof(priv->dai_props->codec_dai));
+					sizeof(*priv->dai_props->codec_dai));
 	}
 
 	snd_soc_card_set_drvdata(card, priv);
-- 
2.20.0


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

* Re: [PATCH] ASoC: simple-card: Dereference pointer for memcpy sizeof in asoc_simple_card_probe
  2018-12-13  4:35 [PATCH] ASoC: simple-card: Dereference pointer for memcpy sizeof in asoc_simple_card_probe Nathan Chancellor
@ 2018-12-13  5:07 ` Kuninori Morimoto
  2018-12-13  5:09   ` Nathan Chancellor
  0 siblings, 1 reply; 3+ messages in thread
From: Kuninori Morimoto @ 2018-12-13  5:07 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: Mark Brown, Liam Girdwood, alsa-devel, linux-kernel


Hi Nathan

> sound/soc/generic/simple-card.c:462:6: warning: argument to 'sizeof' in
> 'memcpy' call is the same pointer type 'struct asoc_simple_dai *' as the
> source; expected 'struct asoc_simple_dai' or an explicit length
> [-Wsizeof-pointer-memaccess]
>                                         sizeof(priv->dai_props->cpu_dai));
>                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> sound/soc/generic/simple-card.c:464:6: warning: argument to 'sizeof' in
> 'memcpy' call is the same pointer type 'struct asoc_simple_dai *' as the
> source; expected 'struct asoc_simple_dai' or an explicit length
> [-Wsizeof-pointer-memaccess]
>                                         sizeof(priv->dai_props->codec_dai));
>                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 2 warnings generated.
> 
> Commit 4fb7f4df49d3 ("ASoC: simple-card: use cpu/codec pointer on
> simple_dai_props") updated {cpu,codec}_dai to be pointers in struct
> simple_dai_props but didn't update these locations to dereference the
> pointers to get the proper size of their contents.
> 
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  sound/soc/generic/simple-card.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> index 766123485d7c..d4738d3eb2f1 100644
> --- a/sound/soc/generic/simple-card.c
> +++ b/sound/soc/generic/simple-card.c
> @@ -459,9 +459,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
>  		dai_link->dai_fmt	= cinfo->daifmt;
>  		dai_link->init		= asoc_simple_card_dai_init;
>  		memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai,
> -					sizeof(priv->dai_props->cpu_dai));
> +					sizeof(*priv->dai_props->cpu_dai));
>  		memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai,
> -					sizeof(priv->dai_props->codec_dai));
> +					sizeof(*priv->dai_props->codec_dai));
>  	}

Ahh.. yes, simple-card is supporting non DT case, too.
Thank you for your patch.
But, I think "&priv->dai_props->codec_dai" need to fix, too.
And it needs to point cpu_dai/codec_dai.
Thank you for pointing it. I will fixup and post with your name.

Best regards
---
Kuninori Morimoto

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

* Re: [PATCH] ASoC: simple-card: Dereference pointer for memcpy sizeof in asoc_simple_card_probe
  2018-12-13  5:07 ` Kuninori Morimoto
@ 2018-12-13  5:09   ` Nathan Chancellor
  0 siblings, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2018-12-13  5:09 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Mark Brown, Liam Girdwood, alsa-devel, linux-kernel

On Thu, Dec 13, 2018 at 02:07:42PM +0900, Kuninori Morimoto wrote:
> 
> Hi Nathan
> 
> > sound/soc/generic/simple-card.c:462:6: warning: argument to 'sizeof' in
> > 'memcpy' call is the same pointer type 'struct asoc_simple_dai *' as the
> > source; expected 'struct asoc_simple_dai' or an explicit length
> > [-Wsizeof-pointer-memaccess]
> >                                         sizeof(priv->dai_props->cpu_dai));
> >                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > sound/soc/generic/simple-card.c:464:6: warning: argument to 'sizeof' in
> > 'memcpy' call is the same pointer type 'struct asoc_simple_dai *' as the
> > source; expected 'struct asoc_simple_dai' or an explicit length
> > [-Wsizeof-pointer-memaccess]
> >                                         sizeof(priv->dai_props->codec_dai));
> >                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > 2 warnings generated.
> > 
> > Commit 4fb7f4df49d3 ("ASoC: simple-card: use cpu/codec pointer on
> > simple_dai_props") updated {cpu,codec}_dai to be pointers in struct
> > simple_dai_props but didn't update these locations to dereference the
> > pointers to get the proper size of their contents.
> > 
> > Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> > ---
> >  sound/soc/generic/simple-card.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
> > index 766123485d7c..d4738d3eb2f1 100644
> > --- a/sound/soc/generic/simple-card.c
> > +++ b/sound/soc/generic/simple-card.c
> > @@ -459,9 +459,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
> >  		dai_link->dai_fmt	= cinfo->daifmt;
> >  		dai_link->init		= asoc_simple_card_dai_init;
> >  		memcpy(&priv->dai_props->cpu_dai, &cinfo->cpu_dai,
> > -					sizeof(priv->dai_props->cpu_dai));
> > +					sizeof(*priv->dai_props->cpu_dai));
> >  		memcpy(&priv->dai_props->codec_dai, &cinfo->codec_dai,
> > -					sizeof(priv->dai_props->codec_dai));
> > +					sizeof(*priv->dai_props->codec_dai));
> >  	}
> 
> Ahh.. yes, simple-card is supporting non DT case, too.
> Thank you for your patch.
> But, I think "&priv->dai_props->codec_dai" need to fix, too.
> And it needs to point cpu_dai/codec_dai.
> Thank you for pointing it. I will fixup and post with your name.
> 
> Best regards
> ---
> Kuninori Morimoto

Sure, whatever you think is best, thank you for the quick response!

Nathan

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

end of thread, other threads:[~2018-12-13  5:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-13  4:35 [PATCH] ASoC: simple-card: Dereference pointer for memcpy sizeof in asoc_simple_card_probe Nathan Chancellor
2018-12-13  5:07 ` Kuninori Morimoto
2018-12-13  5:09   ` Nathan Chancellor

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.