From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757186AbZJ3LCU (ORCPT ); Fri, 30 Oct 2009 07:02:20 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757177AbZJ3LCT (ORCPT ); Fri, 30 Oct 2009 07:02:19 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58038 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757174AbZJ3LCR (ORCPT ); Fri, 30 Oct 2009 07:02:17 -0400 Date: Fri, 30 Oct 2009 12:02:22 +0100 Message-ID: From: Takashi Iwai To: Julia Lawall Cc: Kyle McMartin , Jaroslav Kysela , linux-parisc@vger.kernel.org, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH 3/14] sound/parisc: Move dereference after NULL test In-Reply-To: References: User-Agent: Wanderlust/2.15.6 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.1 (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 Sat, 17 Oct 2009 08:33:47 +0200 (CEST), Julia Lawall wrote: > > From: Julia Lawall > > If the NULL test on h is needed in snd_harmony_mixer_init, then the > dereference should be after the NULL test. > > Actually, there is a sequence of calls: snd_harmony_create, then > snd_harmony_pcm_init, and then snd_harmony_mixer_init. snd_harmony_create > initializes h, but may indeed leave it as NULL. There was no NULL test at > the beginning of snd_harmony_pcm_init, so I have added one. The NULL test > in snd_harmony_mixer_init is then not necessary, but in case the ordering > of the calls changes, I have left it, and moved the dereference after it. > > A simplified version of the semantic match that detects this problem is as > follows (http://coccinelle.lip6.fr/): > > // > @match exists@ > expression x, E; > identifier fld; > @@ > > * x->fld > ... when != \(x = E\|&x\) > * x == NULL > // > > Signed-off-by: Julia Lawall Applied this one, too. Thanks. Takashi > --- > sound/parisc/harmony.c | 6 +++++- > 1 files changed, 5 insertions(+), 1 deletions(-) > > diff --git a/sound/parisc/harmony.c b/sound/parisc/harmony.c > index e924492..f47f9e2 100644 > --- a/sound/parisc/harmony.c > +++ b/sound/parisc/harmony.c > @@ -624,6 +624,9 @@ snd_harmony_pcm_init(struct snd_harmony *h) > struct snd_pcm *pcm; > int err; > > + if (snd_BUG_ON(!h)) > + return -EINVAL; > + > harmony_disable_interrupts(h); > > err = snd_pcm_new(h->card, "harmony", 0, 1, 1, &pcm); > @@ -865,11 +868,12 @@ snd_harmony_mixer_reset(struct snd_harmony *h) > static int __devinit > snd_harmony_mixer_init(struct snd_harmony *h) > { > - struct snd_card *card = h->card; > + struct snd_card *card; > int idx, err; > > if (snd_BUG_ON(!h)) > return -EINVAL; > + card = h->card; > strcpy(card->mixername, "Harmony Gain control interface"); > > for (idx = 0; idx < HARMONY_CONTROLS; idx++) { >