From: Takashi Iwai Subject: Re: [PATCH] riptide: postfix increment and off by one Date: Thu, 14 May 2009 08:42:48 +0200 Message-ID: References: <4A0B14F7.20905@gmail.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 0938A244D2 for ; Thu, 14 May 2009 08:42:52 +0200 (CEST) In-Reply-To: <4A0B14F7.20905@gmail.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: Roel Kluin Cc: alsa-devel@alsa-project.org, andrew Morton List-Id: alsa-devel@alsa-project.org At Wed, 13 May 2009 20:44:07 +0200, Roel Kluin wrote: > > With a postfix increment these variables are incremented beyond > CMDIF_TIMEOUT / MAX_WRITE_RETRY. > > Signed-off-by: Roel Kluin Applied now to sound git tree. Thanks. Takashi > --- > diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c > index 6f10344..e51a5ef 100644 > --- a/sound/pci/riptide/riptide.c > +++ b/sound/pci/riptide/riptide.c > @@ -889,7 +889,7 @@ static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm, > spin_lock_irqsave(&cif->lock, irqflags); > while (i++ < CMDIF_TIMEOUT && !IS_READY(cif->hwport)) > udelay(10); > - if (i >= CMDIF_TIMEOUT) { > + if (i > CMDIF_TIMEOUT) { > err = -EBUSY; > goto errout; > } > @@ -907,8 +907,10 @@ static int sendcmd(struct cmdif *cif, u32 flags, u32 cmd, u32 parm, > WRITE_PORT_ULONG(cmdport->data1, cmd); /* write cmd */ > if ((flags & RESP) && ret) { > while (!IS_DATF(cmdport) && > - time++ < CMDIF_TIMEOUT) > + time < CMDIF_TIMEOUT) { > udelay(10); > + time++; > + } > if (time < CMDIF_TIMEOUT) { /* read response */ > ret->retlongs[0] = > READ_PORT_ULONG(cmdport->data1); > @@ -1454,7 +1456,7 @@ static int snd_riptide_trigger(struct snd_pcm_substream *substream, int cmd) > SEND_GPOS(cif, 0, data->id, &rptr); > udelay(1); > } while (i != rptr.retlongs[1] && j++ < MAX_WRITE_RETRY); > - if (j >= MAX_WRITE_RETRY) > + if (j > MAX_WRITE_RETRY) > snd_printk(KERN_ERR "Riptide: Could not stop stream!"); > break; > case SNDRV_PCM_TRIGGER_PAUSE_PUSH: > @@ -1783,7 +1785,7 @@ snd_riptide_codec_write(struct snd_ac97 *ac97, unsigned short reg, > SEND_SACR(cif, val, reg); > SEND_RACR(cif, reg, &rptr); > } while (rptr.retwords[1] != val && i++ < MAX_WRITE_RETRY); > - if (i == MAX_WRITE_RETRY) > + if (i > MAX_WRITE_RETRY) > snd_printdd("Write AC97 reg failed\n"); > } > >