Skip to contentSkip to conversation

Check unsigned < 0 in /drivers/net/acenic.c

PATCH In review Eric Sesterhenn / snakebyte 2 participants 4 messages Dec 16, 2005 – Jan 11, 2006

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

PATCH 1/1 Check unsigned < 0 in /drivers/net/acenic.c

hi,

since read_eeprom_byte() returns a negative value on an error condition, tmp should be signed so the comparisons in line 1007 and 1017 can catch the error.

drivers/net/acenic.c renamed from drivers/net/acenic.c.orig +2 -1
@@ -905,7 +905,8 @@ static int __devinit ace_init(struct net
 	struct pci_dev *pdev;
 	unsigned long myjif;
 	u64 tmp_ptr;
-	u32 tig_ver, mac1, mac2, tmp, pci_state;
+	u32 tig_ver, mac1, mac2, pci_state;
+	int tmp;
 	int board_idx, ecode = 0;
 	short i;
 	unsigned char cache_size;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 7 lines

since read_eeprom_byte() returns a negative value on an error condition, tmp should be signed so the comparisons in line 1007 and 1017 can catch the error.

drivers/net/acenic.c static int __devinit ace_init(struct net · line 912

Quoted 9 lines
drivers/net/acenic.c renamed from drivers/net/acenic.c.orig +2 -1
@@ -905,7 +905,8 @@ static int __devinit ace_init(struct net
 	struct pci_dev *pdev;
 	unsigned long myjif;
 	u64 tmp_ptr;
-	u32 tig_ver, mac1, mac2, tmp, pci_state;
+	u32 tig_ver, mac1, mac2, pci_state;
+	int tmp;
 	int board_idx, ecode = 0;
 	short i;
 	unsigned char cache_size;

Looks like there are two different tmps: one for read_eeprom_byte, another for writing to PCI state.

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#2 lore raw
In reply to Eric Sesterhenn / snakebyte
Quoted 2 lines · Alexey Dobriyan

Looks like there are two different tmps: one for read_eeprom_byte, another for writing to PCI state.

guess, this patch is better then. but maybe you can suggest a better variable name then tmp2... :)

drivers/net/acenic.c renamed from drivers/net/acenic.c.orig +7 -7
@@ -906,7 +906,7 @@ static int __devinit ace_init(struct net
 	unsigned long myjif;
 	u64 tmp_ptr;
 	u32 tig_ver, mac1, mac2, tmp, pci_state;
-	int board_idx, ecode = 0;
+	int board_idx, tmp2, ecode = 0;
 	short i;
 	unsigned char cache_size;
 
@@ -1003,22 +1003,22 @@ static int __devinit ace_init(struct net
 	mac1 = 0;
 	for(i = 0; i < 4; i++) {
 		mac1 = mac1 << 8;
-		tmp = read_eeprom_byte(dev, 0x8c+i);
-		if (tmp < 0) {
+		tmp2 = read_eeprom_byte(dev, 0x8c+i);
+		if (tmp2 < 0) {
 			ecode = -EIO;
 			goto init_error;
 		} else
-			mac1 |= (tmp & 0xff);
+			mac1 |= (tmp2 & 0xff);
 	}
 	mac2 = 0;
 	for(i = 4; i < 8; i++) {
 		mac2 = mac2 << 8;
-		tmp = read_eeprom_byte(dev, 0x8c+i);
-		if (tmp < 0) {
+		tmp2 = read_eeprom_byte(dev, 0x8c+i);
+		if (tmp2 < 0) {
 			ecode = -EIO;
 			goto init_error;
 		} else
-			mac2 |= (tmp & 0xff);
+			mac2 |= (tmp2 & 0xff);
 	}
 
 	writel(mac1, &regs->MacAddrHi);

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#3 lore raw
In reply to Eric Sesterhenn / snakebyte
Quoted 6 lines · Eric Sesterhenn / snakebyte
Quoted 2 lines · Alexey Dobriyan

Looks like there are two different tmps: one for read_eeprom_byte, another for writing to PCI state.

guess, this patch is better then. but maybe you can suggest a better variable name then tmp2... :)

Argh... Sorry for not being clear enough. "tmp" is a good name as soon as you put it in those mac reading loops. I fixed it locally.

drivers/net/acenic.c +4 -0
@@ -1002,6 +1002,8 @@ static int __devinit ace_init(struct net
 
 	mac1 = 0;
 	for(i = 0; i < 4; i++) {
+		int tmp;
+
 		mac1 = mac1 << 8;
 		tmp = read_eeprom_byte(dev, 0x8c+i);
 		if (tmp < 0) {
@@ -1012,6 +1014,8 @@ static int __devinit ace_init(struct net
 	}
 	mac2 = 0;
 	for(i = 4; i < 8; i++) {
+		int tmp;
+
 		mac2 = mac2 << 8;
 		tmp = read_eeprom_byte(dev, 0x8c+i);
 		if (tmp < 0) {

drivers/net/acenic.c static int __devinit ace_init(struct net · line 911

Quoted 10 lines
drivers/net/acenic.c renamed from drivers/net/acenic.c.orig +1 -1
@@ -906,7 +906,7 @@ static int __devinit ace_init(struct net
 	unsigned long myjif;
 	u64 tmp_ptr;
 	u32 tig_ver, mac1, mac2, tmp, pci_state;
-	int board_idx, ecode = 0;
+	int board_idx, tmp2, ecode = 0;
 	short i;
 	unsigned char cache_size;

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors