From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756162AbcH1Vys (ORCPT ); Sun, 28 Aug 2016 17:54:48 -0400 Received: from smtprelay0105.hostedemail.com ([216.40.44.105]:43640 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756060AbcH1Vyr (ORCPT ); Sun, 28 Aug 2016 17:54:47 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:541:599:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3873:3874:4321:5007:7903:7904:8603:10004:10400:10848:11026:11232:11658:11783:11914:12438:12740:13069:13255:13311:13357:13439:13894:14180:14659:14721:14777:21060:21080:21212:21324:21433:30012:30041:30054:30055:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: war02_297e66732e037 X-Filterd-Recvd-Size: 3115 Message-ID: <1472421284.26978.132.camel@perches.com> Subject: Re: Misuses of ** ? (was Re: [PATCH 1/1] ASoC: Intel: Atom: add a missing star in a memcpy call) From: Joe Perches To: Julia Lawall Cc: Nicolas Iooss , alsa-devel@alsa-project.org, Dan Capenter , Liam Girdwood , Mark Brown , linux-kernel@vger.kernel.org Date: Sun, 28 Aug 2016 14:54:44 -0700 In-Reply-To: References: <20160828173945.27721-1-nicolas.iooss_linux@m4x.org> <1472406636.26978.95.camel@perches.com> <1472416453.26978.115.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.