* [PATCH 9/9] sound/soc/codecs: Correct code taking the size of a
@ 2009-12-13 11:43 Julia Lawall
2009-12-13 14:09 ` [PATCH 9/9] sound/soc/codecs: Correct code taking the size of walter harms
2009-12-14 11:38 ` Mark Brown
0 siblings, 2 replies; 4+ messages in thread
From: Julia Lawall @ 2009-12-13 11:43 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
alsa-devel, lin
From: Julia Lawall <julia@diku.dk>
sizeof(codec->reg_cache) is just the size of the pointer. Elsewhere in the
file, codec->reg_cache is used with sizeof(wm8900_reg_defaults), so the
code is changed to do the same here.
A simplified version of the semantic patch that finds this problem is as
follows: (http://coccinelle.lip6.fr/)
// <smpl>
@@
expression *x;
expression f;
type T;
@@
*f(...,(T)x,...)
// </smpl>
Signed-off-by: Julia Lawall <julia@diku.dk>
---
sound/soc/codecs/wm8900.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index c9438dd..dbc368c 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -199,7 +199,7 @@ static void wm8900_reset(struct snd_soc_codec *codec)
snd_soc_write(codec, WM8900_REG_RESET, 0);
memcpy(codec->reg_cache, wm8900_reg_defaults,
- sizeof(codec->reg_cache));
+ sizeof(wm8900_reg_defaults));
}
static int wm8900_hp_event(struct snd_soc_dapm_widget *w,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 9/9] sound/soc/codecs: Correct code taking the size of
2009-12-13 11:43 [PATCH 9/9] sound/soc/codecs: Correct code taking the size of a Julia Lawall
@ 2009-12-13 14:09 ` walter harms
2009-12-13 15:21 ` Julia Lawall
2009-12-14 11:38 ` Mark Brown
1 sibling, 1 reply; 4+ messages in thread
From: walter harms @ 2009-12-13 14:09 UTC (permalink / raw)
To: Julia Lawall
Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
alsa-devel, linux-kernel, kernel-janitors
Julia Lawall schrieb:
> From: Julia Lawall <julia@diku.dk>
>
> sizeof(codec->reg_cache) is just the size of the pointer. Elsewhere in the
> file, codec->reg_cache is used with sizeof(wm8900_reg_defaults), so the
> code is changed to do the same here.
>
> A simplified version of the semantic patch that finds this problem is as
> follows: (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression *x;
> expression f;
> type T;
> @@
>
> *f(...,(T)x,...)
> // </smpl>
>
> Signed-off-by: Julia Lawall <julia@diku.dk>
>
> ---
> sound/soc/codecs/wm8900.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
> index c9438dd..dbc368c 100644
> --- a/sound/soc/codecs/wm8900.c
> +++ b/sound/soc/codecs/wm8900.c
> @@ -199,7 +199,7 @@ static void wm8900_reset(struct snd_soc_codec *codec)
> snd_soc_write(codec, WM8900_REG_RESET, 0);
>
> memcpy(codec->reg_cache, wm8900_reg_defaults,
> - sizeof(codec->reg_cache));
> + sizeof(wm8900_reg_defaults));
> }
I do not think that this was the intention of the original author,
I guess the idea behind sizeof(*codec->reg_cache) was to protect
the area behind it (in case wm8900_reg_defaults are badly defined).
re,
wh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 9/9] sound/soc/codecs: Correct code taking the size of
2009-12-13 14:09 ` [PATCH 9/9] sound/soc/codecs: Correct code taking the size of walter harms
@ 2009-12-13 15:21 ` Julia Lawall
0 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2009-12-13 15:21 UTC (permalink / raw)
To: walter harms
Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
alsa-devel, linux-kernel, kernel-janitors
On Sun, 13 Dec 2009, walter harms wrote:
>
>
> Julia Lawall schrieb:
> > From: Julia Lawall <julia@diku.dk>
> >
> > sizeof(codec->reg_cache) is just the size of the pointer. Elsewhere in the
> > file, codec->reg_cache is used with sizeof(wm8900_reg_defaults), so the
> > code is changed to do the same here.
> >
> > A simplified version of the semantic patch that finds this problem is as
> > follows: (http://coccinelle.lip6.fr/)
> >
> > // <smpl>
> > @@
> > expression *x;
> > expression f;
> > type T;
> > @@
> >
> > *f(...,(T)x,...)
> > // </smpl>
> >
> > Signed-off-by: Julia Lawall <julia@diku.dk>
> >
> > ---
> > sound/soc/codecs/wm8900.c | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
> > index c9438dd..dbc368c 100644
> > --- a/sound/soc/codecs/wm8900.c
> > +++ b/sound/soc/codecs/wm8900.c
> > @@ -199,7 +199,7 @@ static void wm8900_reset(struct snd_soc_codec *codec)
> > snd_soc_write(codec, WM8900_REG_RESET, 0);
> >
> > memcpy(codec->reg_cache, wm8900_reg_defaults,
> > - sizeof(codec->reg_cache));
> > + sizeof(wm8900_reg_defaults));
> > }
>
> I do not think that this was the intention of the original author,
> I guess the idea behind sizeof(*codec->reg_cache) was to protect
> the area behind it (in case wm8900_reg_defaults are badly defined).
sizeof(codec->reg_cache) is the size of a pointer (void *).
sizeof(*codec->reg_cache) is then the size of void. wm8900_reg_defaults
is a static constant array defined a few lines before this code:
static const u16 wm8900_reg_defaults[WM8900_MAXREG] = { ... };
Later in the same file there is:
cache = kmemdup(codec->reg_cache, sizeof(wm8900_reg_defaults),
GFP_KERNEL);
and codec->reg_cache is initialized as follows:
codec->reg_cache = &wm8900->reg_cache[0];
The reg_cache field in wm8900 is declared as u16 reg_cache[WM8900_MAXREG];
julia
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 9/9] sound/soc/codecs: Correct code taking the size of
2009-12-13 11:43 [PATCH 9/9] sound/soc/codecs: Correct code taking the size of a Julia Lawall
2009-12-13 14:09 ` [PATCH 9/9] sound/soc/codecs: Correct code taking the size of walter harms
@ 2009-12-14 11:38 ` Mark Brown
1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2009-12-14 11:38 UTC (permalink / raw)
To: Julia Lawall
Cc: alsa-devel, Takashi Iwai, kernel-janitors, linux-kernel,
Liam Girdwood
On Sun, Dec 13, 2009 at 12:43:15PM +0100, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
>
> sizeof(codec->reg_cache) is just the size of the pointer. Elsewhere in the
> file, codec->reg_cache is used with sizeof(wm8900_reg_defaults), so the
> code is changed to do the same here.
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-12-14 11:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-13 11:43 [PATCH 9/9] sound/soc/codecs: Correct code taking the size of a Julia Lawall
2009-12-13 14:09 ` [PATCH 9/9] sound/soc/codecs: Correct code taking the size of walter harms
2009-12-13 15:21 ` Julia Lawall
2009-12-14 11:38 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox