Commit a88c844c1748ba494d38b1053829ec046c74ebfd
Committed by
Jeff Garzik
1 parent
571de88b87
Exists in
master
and in
7 other branches
[PATCH] pcnet32: show name of failing device
Display the name eth%d or pci_name() of device which fails to allocate memory. When changing ring size via ethtool, it also releases the lock before returning on error. Added comment that the caller of pcnet32_alloc_ring must call pcnet32_free_ring on error, to avoid leak. Tested ia32 by forcing allocation errors. Signed-off-by: Don Fry <brazilnut@us.ibm.com> Signed-off-by: Jeff Garzik <jgarzik@pobox.com>
Showing 1 changed file with 41 additions and 21 deletions Side-by-side Diff
drivers/net/pcnet32.c
... | ... | @@ -22,8 +22,8 @@ |
22 | 22 | *************************************************************************/ |
23 | 23 | |
24 | 24 | #define DRV_NAME "pcnet32" |
25 | -#define DRV_VERSION "1.31a" | |
26 | -#define DRV_RELDATE "12.Sep.2005" | |
25 | +#define DRV_VERSION "1.31b" | |
26 | +#define DRV_RELDATE "06.Oct.2005" | |
27 | 27 | #define PFX DRV_NAME ": " |
28 | 28 | |
29 | 29 | static const char *version = |
... | ... | @@ -260,6 +260,8 @@ |
260 | 260 | * v1.31 02 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> added set_ringparam(). |
261 | 261 | * v1.31a 12 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> set min ring size to 4 |
262 | 262 | * to allow loopback test to work unchanged. |
263 | + * v1.31b 06 Oct 2005 Don Fry changed alloc_ring to show name of device | |
264 | + * if allocation fails | |
263 | 265 | */ |
264 | 266 | |
265 | 267 | |
... | ... | @@ -408,7 +410,7 @@ |
408 | 410 | static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
409 | 411 | void *ptr); |
410 | 412 | static void pcnet32_purge_tx_ring(struct net_device *dev); |
411 | -static int pcnet32_alloc_ring(struct net_device *dev); | |
413 | +static int pcnet32_alloc_ring(struct net_device *dev, char *name); | |
412 | 414 | static void pcnet32_free_ring(struct net_device *dev); |
413 | 415 | |
414 | 416 | |
415 | 417 | |
416 | 418 | |
... | ... | @@ -669,15 +671,17 @@ |
669 | 671 | lp->rx_mod_mask = lp->rx_ring_size - 1; |
670 | 672 | lp->rx_len_bits = (i << 4); |
671 | 673 | |
672 | - if (pcnet32_alloc_ring(dev)) { | |
674 | + if (pcnet32_alloc_ring(dev, dev->name)) { | |
673 | 675 | pcnet32_free_ring(dev); |
676 | + spin_unlock_irqrestore(&lp->lock, flags); | |
674 | 677 | return -ENOMEM; |
675 | 678 | } |
676 | 679 | |
677 | 680 | spin_unlock_irqrestore(&lp->lock, flags); |
678 | 681 | |
679 | 682 | if (pcnet32_debug & NETIF_MSG_DRV) |
680 | - printk(KERN_INFO PFX "Ring Param Settings: RX: %d, TX: %d\n", lp->rx_ring_size, lp->tx_ring_size); | |
683 | + printk(KERN_INFO PFX "%s: Ring Param Settings: RX: %d, TX: %d\n", | |
684 | + dev->name, lp->rx_ring_size, lp->tx_ring_size); | |
681 | 685 | |
682 | 686 | if (netif_running(dev)) |
683 | 687 | pcnet32_open(dev); |
... | ... | @@ -1340,7 +1344,8 @@ |
1340 | 1344 | } |
1341 | 1345 | lp->a = *a; |
1342 | 1346 | |
1343 | - if (pcnet32_alloc_ring(dev)) { | |
1347 | + /* prior to register_netdev, dev->name is not yet correct */ | |
1348 | + if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) { | |
1344 | 1349 | ret = -ENOMEM; |
1345 | 1350 | goto err_free_ring; |
1346 | 1351 | } |
1347 | 1352 | |
1348 | 1353 | |
1349 | 1354 | |
1350 | 1355 | |
1351 | 1356 | |
1352 | 1357 | |
1353 | 1358 | |
1354 | 1359 | |
1355 | 1360 | |
1356 | 1361 | |
1357 | 1362 | |
1358 | 1363 | |
... | ... | @@ -1448,48 +1453,63 @@ |
1448 | 1453 | } |
1449 | 1454 | |
1450 | 1455 | |
1451 | -static int pcnet32_alloc_ring(struct net_device *dev) | |
1456 | +/* if any allocation fails, caller must also call pcnet32_free_ring */ | |
1457 | +static int pcnet32_alloc_ring(struct net_device *dev, char *name) | |
1452 | 1458 | { |
1453 | 1459 | struct pcnet32_private *lp = dev->priv; |
1454 | 1460 | |
1455 | - if ((lp->tx_ring = pci_alloc_consistent(lp->pci_dev, sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, | |
1456 | - &lp->tx_ring_dma_addr)) == NULL) { | |
1461 | + lp->tx_ring = pci_alloc_consistent(lp->pci_dev, | |
1462 | + sizeof(struct pcnet32_tx_head) * lp->tx_ring_size, | |
1463 | + &lp->tx_ring_dma_addr); | |
1464 | + if (lp->tx_ring == NULL) { | |
1457 | 1465 | if (pcnet32_debug & NETIF_MSG_DRV) |
1458 | - printk(KERN_ERR PFX "Consistent memory allocation failed.\n"); | |
1466 | + printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n", | |
1467 | + name); | |
1459 | 1468 | return -ENOMEM; |
1460 | 1469 | } |
1461 | 1470 | |
1462 | - if ((lp->rx_ring = pci_alloc_consistent(lp->pci_dev, sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, | |
1463 | - &lp->rx_ring_dma_addr)) == NULL) { | |
1471 | + lp->rx_ring = pci_alloc_consistent(lp->pci_dev, | |
1472 | + sizeof(struct pcnet32_rx_head) * lp->rx_ring_size, | |
1473 | + &lp->rx_ring_dma_addr); | |
1474 | + if (lp->rx_ring == NULL) { | |
1464 | 1475 | if (pcnet32_debug & NETIF_MSG_DRV) |
1465 | - printk(KERN_ERR PFX "Consistent memory allocation failed.\n"); | |
1476 | + printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n", | |
1477 | + name); | |
1466 | 1478 | return -ENOMEM; |
1467 | 1479 | } |
1468 | 1480 | |
1469 | - if (!(lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, GFP_ATOMIC))) { | |
1481 | + lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, | |
1482 | + GFP_ATOMIC); | |
1483 | + if (!lp->tx_dma_addr) { | |
1470 | 1484 | if (pcnet32_debug & NETIF_MSG_DRV) |
1471 | - printk(KERN_ERR PFX "Memory allocation failed.\n"); | |
1485 | + printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); | |
1472 | 1486 | return -ENOMEM; |
1473 | 1487 | } |
1474 | 1488 | memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size); |
1475 | 1489 | |
1476 | - if (!(lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, GFP_ATOMIC))) { | |
1490 | + lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, | |
1491 | + GFP_ATOMIC); | |
1492 | + if (!lp->rx_dma_addr) { | |
1477 | 1493 | if (pcnet32_debug & NETIF_MSG_DRV) |
1478 | - printk(KERN_ERR PFX "Memory allocation failed.\n"); | |
1494 | + printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); | |
1479 | 1495 | return -ENOMEM; |
1480 | 1496 | } |
1481 | 1497 | memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size); |
1482 | 1498 | |
1483 | - if (!(lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, GFP_ATOMIC))) { | |
1499 | + lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, | |
1500 | + GFP_ATOMIC); | |
1501 | + if (!lp->tx_skbuff) { | |
1484 | 1502 | if (pcnet32_debug & NETIF_MSG_DRV) |
1485 | - printk(KERN_ERR PFX "Memory allocation failed.\n"); | |
1503 | + printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); | |
1486 | 1504 | return -ENOMEM; |
1487 | 1505 | } |
1488 | 1506 | memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size); |
1489 | 1507 | |
1490 | - if (!(lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, GFP_ATOMIC))) { | |
1508 | + lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, | |
1509 | + GFP_ATOMIC); | |
1510 | + if (!lp->rx_skbuff) { | |
1491 | 1511 | if (pcnet32_debug & NETIF_MSG_DRV) |
1492 | - printk(KERN_ERR PFX "Memory allocation failed.\n"); | |
1512 | + printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name); | |
1493 | 1513 | return -ENOMEM; |
1494 | 1514 | } |
1495 | 1515 | memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size); |