From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Nicolas Iooss <nicolas.iooss_linux@m4x.org>,
alsa-devel@alsa-project.org, Dan Capenter <error27@gmail.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: Misuses of ** ? (was Re: [PATCH 1/1] ASoC: Intel: Atom: add a missing star in a memcpy call)
Date: Sun, 28 Aug 2016 14:54:44 -0700 [thread overview]
Message-ID: <1472421284.26978.132.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1608282338290.3419@hadrien>
On Sun, 2016-08-28 at 23:40 +0200, Julia Lawall wrote:
> On Sun, 28 Aug 2016, Joe Perches wrote:
> > On Sun, 2016-08-28 at 21:38 +0200, Julia Lawall wrote:
> > > On Sun, 28 Aug 2016, Nicolas Iooss wrote:
> > > > On 28/08/16 19:50, Joe Perches wrote:
> > > > > On Sun, 2016-08-28 at 19:39 +0200, Nicolas Iooss wrote:
> > > > >> In sst_prepare_and_post_msg(), when a response is received in "block",
> > > > >> the following code gets executed:
> > > > >>
> > > > >> *data = kzalloc(block->size, GFP_KERNEL);
> > > > >> memcpy(data, (void *) block->data, block->size);
> > > > >
> > > > > Yuck, thanks.
> > > > >
> > > > > Julia, Dan, could cocci or smatch help find any other
> > > > > similar misuses here?
> > []
> > > I tried the following semantic patch, that is quite general, and the fixed
> > > issue was the only report.
> > >
> > > @@
> > > expression x,y,sz;
> > > identifier f,g;
> > > @@
> > >
> > > * *x = f(sz,...);
> > > ...
> > > * g(x,y,sz);
> >
> > Hi Julia,
> >
> > This would find exactly the same form, but I think
> > the question is are there assignments of a **pp
> > that should have been *pp
> >
> > Something like:
> >
> > @@
> > type P;
> > P **pp;
> > @@
> >
> > * pp = \|\|(..., sizeof(P), ...)
> I didn't get anything for this. Did you mean for the left hand side of
> the assignment to be pp or *pp? Is the issue that the type is wrong?
Yes, the issue here is the type may be wrong.
A function passed a ** and assigned like:
type function foo(type **bar)
{
...
bar = baz();
...
}
bar is rarely correct and *bar is generally correct.
I suppose the example would have been clearer with something
- pp = foo;
+ *pp = foo;
Also, any function that calls another function with
implicit casts to void * from a specific type **pp
after an assignment to *pp could be suspect.
next prev parent reply other threads:[~2016-08-28 21:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-28 17:39 [PATCH 1/1] ASoC: Intel: Atom: add a missing star in a memcpy call Nicolas Iooss
2016-08-28 17:50 ` Misuses of ** ? (was Re: [PATCH 1/1] ASoC: Intel: Atom: add a missing star in a memcpy call) Joe Perches
2016-08-28 18:52 ` Nicolas Iooss
2016-08-28 19:38 ` Julia Lawall
2016-08-28 20:34 ` Joe Perches
2016-08-28 21:40 ` Julia Lawall
2016-08-28 21:54 ` Joe Perches [this message]
2016-08-28 18:17 ` [PATCH 1/1] ASoC: Intel: Atom: add a missing star in a memcpy call Joe Perches
2016-08-28 18:31 ` Nicolas Iooss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1472421284.26978.132.camel@perches.com \
--to=joe@perches.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=error27@gmail.com \
--cc=julia.lawall@lip6.fr \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.iooss_linux@m4x.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.