summaryrefslogtreecommitdiff
path: root/drivers/net/pcnet32.c
diff options
context:
space:
mode:
authorDon Fry <brazilnut@us.ibm.com>2005-11-01 12:04:33 -0800
committerJeff Garzik <jgarzik@pobox.com>2005-11-05 14:40:55 -0500
commita88c844c1748ba494d38b1053829ec046c74ebfd (patch)
treed9897386dc4254134cc6e5ca1e6c63f76544fa43 /drivers/net/pcnet32.c
parent571de88b87e978b21ac4da481d317678aac9e562 (diff)
[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>
Diffstat (limited to 'drivers/net/pcnet32.c')
-rw-r--r--drivers/net/pcnet32.c62
1 files changed, 41 insertions, 21 deletions
diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
index 70fe81a89df9..31e6dd049859 100644
--- a/drivers/net/pcnet32.c
+++ b/drivers/net/pcnet32.c
@@ -22,8 +22,8 @@
*************************************************************************/
#define DRV_NAME "pcnet32"
-#define DRV_VERSION "1.31a"
-#define DRV_RELDATE "12.Sep.2005"
+#define DRV_VERSION "1.31b"
+#define DRV_RELDATE "06.Oct.2005"
#define PFX DRV_NAME ": "
static const char *version =
@@ -260,6 +260,8 @@ static int homepna[MAX_UNITS];
* v1.31 02 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> added set_ringparam().
* v1.31a 12 Sep 2005 Hubert WS Lin <wslin@tw.ibm.c0m> set min ring size to 4
* to allow loopback test to work unchanged.
+ * v1.31b 06 Oct 2005 Don Fry changed alloc_ring to show name of device
+ * if allocation fails
*/
@@ -408,7 +410,7 @@ static int pcnet32_get_regs_len(struct net_device *dev);
static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
void *ptr);
static void pcnet32_purge_tx_ring(struct net_device *dev);
-static int pcnet32_alloc_ring(struct net_device *dev);
+static int pcnet32_alloc_ring(struct net_device *dev, char *name);
static void pcnet32_free_ring(struct net_device *dev);
@@ -669,15 +671,17 @@ static int pcnet32_set_ringparam(struct net_device *dev, struct ethtool_ringpara
lp->rx_mod_mask = lp->rx_ring_size - 1;
lp->rx_len_bits = (i << 4);
- if (pcnet32_alloc_ring(dev)) {
+ if (pcnet32_alloc_ring(dev, dev->name)) {
pcnet32_free_ring(dev);
+ spin_unlock_irqrestore(&lp->lock, flags);
return -ENOMEM;
}
spin_unlock_irqrestore(&lp->lock, flags);
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_INFO PFX "Ring Param Settings: RX: %d, TX: %d\n", lp->rx_ring_size, lp->tx_ring_size);
+ printk(KERN_INFO PFX "%s: Ring Param Settings: RX: %d, TX: %d\n",
+ dev->name, lp->rx_ring_size, lp->tx_ring_size);
if (netif_running(dev))
pcnet32_open(dev);
@@ -1340,7 +1344,8 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
}
lp->a = *a;
- if (pcnet32_alloc_ring(dev)) {
+ /* prior to register_netdev, dev->name is not yet correct */
+ if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
ret = -ENOMEM;
goto err_free_ring;
}
@@ -1448,48 +1453,63 @@ err_release_region:
}
-static int pcnet32_alloc_ring(struct net_device *dev)
+/* if any allocation fails, caller must also call pcnet32_free_ring */
+static int pcnet32_alloc_ring(struct net_device *dev, char *name)
{
struct pcnet32_private *lp = dev->priv;
- if ((lp->tx_ring = pci_alloc_consistent(lp->pci_dev, sizeof(struct pcnet32_tx_head) * lp->tx_ring_size,
- &lp->tx_ring_dma_addr)) == NULL) {
+ lp->tx_ring = pci_alloc_consistent(lp->pci_dev,
+ sizeof(struct pcnet32_tx_head) * lp->tx_ring_size,
+ &lp->tx_ring_dma_addr);
+ if (lp->tx_ring == NULL) {
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_ERR PFX "Consistent memory allocation failed.\n");
+ printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n",
+ name);
return -ENOMEM;
}
- if ((lp->rx_ring = pci_alloc_consistent(lp->pci_dev, sizeof(struct pcnet32_rx_head) * lp->rx_ring_size,
- &lp->rx_ring_dma_addr)) == NULL) {
+ lp->rx_ring = pci_alloc_consistent(lp->pci_dev,
+ sizeof(struct pcnet32_rx_head) * lp->rx_ring_size,
+ &lp->rx_ring_dma_addr);
+ if (lp->rx_ring == NULL) {
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_ERR PFX "Consistent memory allocation failed.\n");
+ printk("\n" KERN_ERR PFX "%s: Consistent memory allocation failed.\n",
+ name);
return -ENOMEM;
}
- if (!(lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size, GFP_ATOMIC))) {
+ lp->tx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->tx_ring_size,
+ GFP_ATOMIC);
+ if (!lp->tx_dma_addr) {
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_ERR PFX "Memory allocation failed.\n");
+ printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
return -ENOMEM;
}
memset(lp->tx_dma_addr, 0, sizeof(dma_addr_t) * lp->tx_ring_size);
- if (!(lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size, GFP_ATOMIC))) {
+ lp->rx_dma_addr = kmalloc(sizeof(dma_addr_t) * lp->rx_ring_size,
+ GFP_ATOMIC);
+ if (!lp->rx_dma_addr) {
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_ERR PFX "Memory allocation failed.\n");
+ printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
return -ENOMEM;
}
memset(lp->rx_dma_addr, 0, sizeof(dma_addr_t) * lp->rx_ring_size);
- if (!(lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size, GFP_ATOMIC))) {
+ lp->tx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->tx_ring_size,
+ GFP_ATOMIC);
+ if (!lp->tx_skbuff) {
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_ERR PFX "Memory allocation failed.\n");
+ printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
return -ENOMEM;
}
memset(lp->tx_skbuff, 0, sizeof(struct sk_buff *) * lp->tx_ring_size);
- if (!(lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size, GFP_ATOMIC))) {
+ lp->rx_skbuff = kmalloc(sizeof(struct sk_buff *) * lp->rx_ring_size,
+ GFP_ATOMIC);
+ if (!lp->rx_skbuff) {
if (pcnet32_debug & NETIF_MSG_DRV)
- printk(KERN_ERR PFX "Memory allocation failed.\n");
+ printk("\n" KERN_ERR PFX "%s: Memory allocation failed.\n", name);
return -ENOMEM;
}
memset(lp->rx_skbuff, 0, sizeof(struct sk_buff *) * lp->rx_ring_size);