Skip to contentSkip to conversation

drivers/media/video/bt8xx/bttv-cards.c: fix off-by-one

PATCH In review Adrian Bunk 2 participants 2 messages Mar 26, 2007 – Mar 29, 2007 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/media/video/bt8xx/bttv-cards.c: fix off-by-one

This patch fixes an off-by-one error spotted by the Coverity checker.

---

drivers/media/video/bt8xx/bttv-cards.c renamed from drivers/media/video/bt8xx/bttv-cards.c.old +1 -1
@@ -2983,7 +2983,7 @@
 	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 < 4; i++) {
 		printk("%s0x%x", i ? "," : "", bttv_tvcards[btv->c.type].gpiomux[i]);
 	}
 	printk("\n");
#1 lore raw

Hi Adrian,

Em Seg, 2007-03-26 às 06:08 +0200, Adrian Bunk escreveu:

Quoted 1 line

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

Changeset: 5476
From: Mauro Carvalho Chehab <[email protected]>
Commiter: Mauro Carvalho Chehab <[email protected]>
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 <[email protected]> for pointing me about this trouble.

---

drivers/media/video/bt8xx/bttv-cards.c +3 -3
diff -upNr oldtree/drivers/media/video/bt8xx/bttv-cards.c linux/drivers/media/video/bt8xx/bttv-cards.c
@@ -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");