From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753450Ab2JUMS5 (ORCPT ); Sun, 21 Oct 2012 08:18:57 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58652 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752477Ab2JUMS4 (ORCPT ); Sun, 21 Oct 2012 08:18:56 -0400 Date: Sun, 21 Oct 2012 14:18:54 +0200 Message-ID: From: Takashi Iwai To: Julia Lawall Cc: Jaroslav Kysela , kernel-janitors@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] sound/isa/opti9xx/miro.c: eliminate possible double free In-Reply-To: <1350816727-1381-2-git-send-email-Julia.Lawall@lip6.fr> References: <1350816727-1381-1-git-send-email-Julia.Lawall@lip6.fr> <1350816727-1381-2-git-send-email-Julia.Lawall@lip6.fr> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.2 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At Sun, 21 Oct 2012 12:52:03 +0200, Julia Lawall wrote: > > From: Julia Lawall > > snd_miro_probe is a static function that is only called twice in the file > that defines it. At each call site, its argument is freed using > snd_card_free. Thus, there is no need for snd_miro_probe to call > snd_card_free on its argument on any of its error exit paths. > > Because snd_card_free both reads the fields of its argument and kfrees its > argments, the results of the second snd_card_free should be unpredictable. > > A simplified version of the semantic match that finds this problem is as > follows: (http://coccinelle.lip6.fr/) > > // > @r@ > identifier f,free,a; > parameter list[n] ps; > type T; > expression e; > @@ > > f(ps,T a,...) { > ... when any > when != a = e > if(...) { ... free(a); ... return ...; } > ... when any > } > > @@ > identifier r.f,r.free; > expression x,a; > expression list[r.n] xs; > @@ > > * x = f(xs,a,...); > if (...) { ... free(a); ... return ...; } > // > > Signed-off-by: Julia Lawall Thanks, applied. Takashi > > --- > Not tested. > > sound/isa/opti9xx/miro.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c > index 3d1afb6..4a7ff4e 100644 > --- a/sound/isa/opti9xx/miro.c > +++ b/sound/isa/opti9xx/miro.c > @@ -1286,7 +1286,6 @@ static int __devinit snd_miro_probe(struct snd_card *card) > > error = snd_card_miro_aci_detect(card, miro); > if (error < 0) { > - snd_card_free(card); > snd_printk(KERN_ERR "unable to detect aci chip\n"); > return -ENODEV; > } >