LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@infradead.org>
To: Adrian Bunk <bunk@stusta.de>
Cc: v4l-dvb-maintainer@linuxtv.org, linux-kernel@vger.kernel.org
Subject: Re: [v4l-dvb-maintainer] [2.6 patch] drivers/media/video/bt8xx/bttv-cards.c: fix off-by-one
Date: Thu, 29 Mar 2007 09:08:21 -0300	[thread overview]
Message-ID: <1175170101.4453.47.camel@localhost> (raw)
In-Reply-To: <20070326040855.GA16477@stusta.de>

[-- Attachment #1: Type: text/plain, Size: 413 bytes --]

Hi Adrian,

Em Seg, 2007-03-26 às 06:08 +0200, Adrian Bunk escreveu:
> This patch fixes an off-by-one error spotted by the Coverity checker.

Thanks for pointing us about this. Instead of your patch, however, it is
better to replace all magic numbers at for on all gpiomask stuff. This
will avoid future troubles if this array have any changes on its size.

I'm enclosing a patch doing this fix.
 
Cheers,
Mauro

[-- Attachment #2: 5476.patch --]
[-- Type: text/x-patch, Size: 1751 bytes --]

Changeset: 5476
From: Mauro Carvalho Chehab  <mchehab@infradead.org>
Commiter: Mauro Carvalho Chehab <mchehab@infradead.org>
Date: Wed Mar 28 22:37:20 2007 -0300
Subject: Fix gpiomux array size

there were several "magic" for loops, addressing gpiomux array size (4).
Adrian Bunk showed that one of the loops were wrong, going from 0 to 4.
This patch provides the right fix for this trouble, by using ARRAY_SIZE
on all places where we have a for loop using gpiomux.
Thanks to Adrian Bunk <bunk@stusta.de> for pointing me about this trouble.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
---

diff -upNr oldtree/drivers/media/video/bt8xx/bttv-cards.c linux/drivers/media/video/bt8xx/bttv-cards.c
--- oldtree/drivers/media/video/bt8xx/bttv-cards.c	2007-03-29 09:00:15.000000000 -0300
+++ linux/drivers/media/video/bt8xx/bttv-cards.c	2007-03-29 09:00:12.000000000 -0300
@@ -2970,20 +2970,20 @@ void __devinit bttv_idcard(struct bttv *
 
 	if (UNSET != audiomux[0]) {
 		gpiobits = 0;
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
 			bttv_tvcards[btv->c.type].gpiomux[i] = audiomux[i];
 			gpiobits |= audiomux[i];
 		}
 	} else {
 		gpiobits = audioall;
-		for (i = 0; i < 4; i++) {
+		for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
 			bttv_tvcards[btv->c.type].gpiomux[i] = audioall;
 		}
 	}
 	bttv_tvcards[btv->c.type].gpiomask = (UNSET != gpiomask) ? gpiomask : gpiobits;
 	printk(KERN_INFO "bttv%d: gpio config override: mask=0x%x, mux=",
 	       btv->c.nr,bttv_tvcards[btv->c.type].gpiomask);
-	for (i = 0; i < 5; i++) {
+	for (i = 0; i < ARRAY_SIZE(bttv_tvcards->gpiomux); i++) {
 		printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].gpiomux[i]);
 	}
 	printk("\n");

      reply	other threads:[~2007-03-29 12:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-26  4:08 Adrian Bunk
2007-03-29 12:08 ` Mauro Carvalho Chehab [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1175170101.4453.47.camel@localhost \
    --to=mchehab@infradead.org \
    --cc=bunk@stusta.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=v4l-dvb-maintainer@linuxtv.org \
    --subject='Re: [v4l-dvb-maintainer] [2.6 patch] drivers/media/video/bt8xx/bttv-cards.c: fix off-by-one' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).