Skip to contentSkip to conversation

fb: fix recent breakage in correct_chipset()

PATCH In review Dan Carpenter 4 participants 6 messages Jul 2, 2013 – Aug 1, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fb: fix recent breakage in correct_chipset()

The 6e36308a6f "fb: fix atyfb build warning" isn't right. It makes all the indexes off by one. This patch reverts it and casts the ARRAY_SIZE() to int to silence the build warning.

drivers/video/aty/atyfb_base.c +2 -2
index a89c15d..9b0f12c 100644
@@ -435,8 +435,8 @@ static int correct_chipset(struct atyfb_par *par)
 	const char *name;
 	int i;
 
-	for (i = ARRAY_SIZE(aty_chips); i > 0; i--)
-		if (par->pci_id = aty_chips[i - 1].pci_id)
+	for (i = (int)ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
+		if (par->pci_id = aty_chips[i].pci_id)
 			break;
 
 	if (i < 0)
#1 lore raw
Quoted 3 lines · Dan Carpenter

The 6e36308a6f "fb: fix atyfb build warning" isn't right. It makes all the indexes off by one. This patch reverts it and casts the ARRAY_SIZE() to int to silence the build warning.

Argh. Thanks.

Quoted 18 lines
drivers/video/aty/atyfb_base.c +2 -2
index a89c15d..9b0f12c 100644
@@ -435,8 +435,8 @@ static int correct_chipset(struct atyfb_par *par)
 	const char *name;
 	int i;
 
-	for (i = ARRAY_SIZE(aty_chips); i > 0; i--)
-		if (par->pci_id = aty_chips[i - 1].pci_id)
+	for (i = (int)ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
+		if (par->pci_id = aty_chips[i].pci_id)
 			break;
 
 	if (i < 0)
Signature · 1 line
~Randy
#2 lore raw
In reply to Dan Carpenter
Quoted 5 lines · Dan Carpenter

The 6e36308a6f "fb: fix atyfb build warning" isn't right. It makes all the indexes off by one. This patch reverts it and casts the ARRAY_SIZE() to int to silence the build warning.

Tomi,

My incorrect patch has been merged into mainline.
Please merge Dan's fix for it instead.

Thanks.

Quoted 16 lines
drivers/video/aty/atyfb_base.c +2 -2
index a89c15d..9b0f12c 100644
@@ -435,8 +435,8 @@ static int correct_chipset(struct atyfb_par *par)
 	const char *name;
 	int i;
 
-	for (i = ARRAY_SIZE(aty_chips); i > 0; i--)
-		if (par->pci_id = aty_chips[i - 1].pci_id)
+	for (i = (int)ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
+		if (par->pci_id = aty_chips[i].pci_id)
 			break;
 
 	if (i < 0)
Signature · 1 line
~Randy
#3 lore raw
In reply to Dan Carpenter
Quoted 12 lines · Dan Carpenter

The 6e36308a6f "fb: fix atyfb build warning" isn't right. It makes all the indexes off by one. This patch reverts it and casts the ARRAY_SIZE() to int to silence the build warning.

drivers/video/aty/atyfb_base.c +0 -0
index a89c15d..9b0f12c 100644

drivers/video/aty/atyfb_base.c static int correct_chipset(struct atyfb_par *par) · line 442

Quoted 10 lines
drivers/video/aty/atyfb_base.c +2 -2
@@ -435,8 +435,8 @@ static int correct_chipset(struct atyfb_par *par)
 	const char *name;
 	int i;
 
-	for (i = ARRAY_SIZE(aty_chips); i > 0; i--)
-		if (par->pci_id == aty_chips[i - 1].pci_id)
+	for (i = (int)ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
+		if (par->pci_id == aty_chips[i].pci_id)
 			break;
 
 	if (i < 0)

Thanks, I've applied this into my 3.11-fixes/fbdev branch.

Tomi

#4 lore raw
In reply to Dan Carpenter
Quoted 11 lines · Dan Carpenter

The 6e36308a6f "fb: fix atyfb build warning" isn't right. It makes all the indexes off by one. This patch reverts it and casts the ARRAY_SIZE() to int to silence the build warning.

drivers/video/aty/atyfb_base.c +0 -0
index a89c15d..9b0f12c 100644

drivers/video/aty/atyfb_base.c static int correct_chipset(struct atyfb_par *par) · line 442

Quoted 10 lines
drivers/video/aty/atyfb_base.c +2 -2
@@ -435,8 +435,8 @@ static int correct_chipset(struct atyfb_par *par)
        const char *name;
        int i;
 
-       for (i = ARRAY_SIZE(aty_chips); i > 0; i--)
-               if (par->pci_id = aty_chips[i - 1].pci_id)
+       for (i = (int)ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
+               if (par->pci_id = aty_chips[i].pci_id)
                        break;
 
        if (i < 0)

Sorry for chiming in late, but can't we just revert the order of the loop iteration and change i from int to size_t instead of adding a cast?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#5 lore raw
In reply to Dan Carpenter
Quoted 21 lines · Geert Uytterhoeven
Quoted 20 lines · Dan Carpenter

The 6e36308a6f "fb: fix atyfb build warning" isn't right. It makes all the indexes off by one. This patch reverts it and casts the ARRAY_SIZE() to int to silence the build warning.

drivers/video/aty/atyfb_base.c +2 -2
index a89c15d..9b0f12c 100644
@@ -435,8 +435,8 @@ static int correct_chipset(struct atyfb_par *par)
        const char *name;
        int i;
 
-       for (i = ARRAY_SIZE(aty_chips); i > 0; i--)
-               if (par->pci_id = aty_chips[i - 1].pci_id)
+       for (i = (int)ARRAY_SIZE(aty_chips) - 1; i >= 0; i--)
+               if (par->pci_id = aty_chips[i].pci_id)
                        break;
 
Quoted 5 lines

drivers/video/aty/atyfb_base.c static int correct_chipset(struct atyfb_par *par) · line 442

Quoted 1 line
drivers/video/aty/atyfb_base.c +0 -0
        if (i < 0)

Sorry for chiming in late, but can't we just revert the order of the loop iteration and change i from int to size_t instead of adding a cast?

Nope. That would be a nearly-forever loop.

regards,
dan carpenter