Skip to contentSkip to conversation

sky2: Make hw->ports the number of ports allocated

PATCH In review Mike McCormack 2 participants 2 messages Sep 12, 2009

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

PATCH 1/1 sky2: Make hw->ports the number of ports allocated

If allocation of the second ports fails, make sure that hw->ports
is not 2 otherwise we'll crash trying to access the second port.

---
 drivers/net/sky2.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/net/sky2.c +4 -0
index 018aa58..c17ee26 100644
@@ -4563,6 +4563,10 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 			free_netdev(dev1);
 		} else
 			sky2_show_addr(dev1);
+
+		/* couldn't allocate the second port */
+		if (!hw->dev[1])
+			--hw->ports;
 	}
 
 	setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw);
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 13 lines · On Sat, 12 Sep 2009 12:19:23 +0900 Mike McCormack <[email protected]> wrote:

If allocation of the second ports fails, make sure that hw->ports
is not 2 otherwise we'll crash trying to access the second port.

---
 drivers/net/sky2.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/net/sky2.c +0 -0
index 018aa58..c17ee26 100644

drivers/net/sky2.c static int __devinit sky2_probe(struct pci_dev *pdev, · line 4572

Quoted 10 lines
drivers/net/sky2.c +4 -0
@@ -4563,6 +4563,10 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
 			free_netdev(dev1);
 		} else
 			sky2_show_addr(dev1);
+
+		/* couldn't allocate the second port */
+		if (!hw->dev[1])
+			--hw->ports;
 	}
 
 	setup_timer(&hw->watchdog_timer, sky2_watchdog, (unsigned long) hw);

If it couldn't allocate the port, would be better to unwind the first port and fail the probe, rather than silently failing in a really sick system.