From: Takashi Iwai Subject: Re: [PATCH] ALSA: asihpi - Clarify adapter index validity check. Date: Thu, 28 Jul 2011 07:43:16 +0200 Message-ID: References: <1311803417-10328-1-git-send-email-linux@audioscience.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id D6597103810 for ; Thu, 28 Jul 2011 07:43:17 +0200 (CEST) In-Reply-To: <1311803417-10328-1-git-send-email-linux@audioscience.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: linux@audioscience.com Cc: Eliot Blennerhassett , alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Thu, 28 Jul 2011 09:50:17 +1200, linux@audioscience.com wrote: > > From: Eliot Blennerhassett > > Avoids assigning possibly invalid address to pa, even if it > is never dereferenced. > > Signed-off-by: Eliot Blennerhassett > --- > sound/pci/asihpi/hpioctl.c | 19 ++++++++++++------- > 1 files changed, 12 insertions(+), 7 deletions(-) > > diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c > index 9683f84..a32502e 100644 > --- a/sound/pci/asihpi/hpioctl.c > +++ b/sound/pci/asihpi/hpioctl.c > @@ -177,16 +177,21 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > } else { > u16 __user *ptr = NULL; > u32 size = 0; > - > + u32 adapter_present; > /* -1=no data 0=read from user mem, 1=write to user mem */ > int wrflag = -1; > - u32 adapter = hm->h.adapter_index; > - struct hpi_adapter *pa = &adapters[adapter]; > + struct hpi_adapter *pa; > + > + if (hm->h.adapter_index < HPI_MAX_ADAPTERS) { > + pa = &adapters[hm->h.adapter_index]; > + adapter_present = pa->type; > + } else { > + adapter_present = 0; > + } > > - if ((adapter >= HPI_MAX_ADAPTERS) || (!pa->type)) { > - hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER, > - HPI_ADAPTER_OPEN, > - HPI_ERROR_BAD_ADAPTER_NUMBER); > + if (!adapter_present) { > + hpi_init_response(&hr->r0, hm->h.object, > + hm->h.function, HPI_ERROR_BAD_ADAPTER_NUMBER); Here you are initializing to different values (from HPI_OBJ_ADAPTER to hm->h.object, etc). Is it intentional? thanks, Takashi