Skip to contentSkip to conversation

depca: release resources on errors

janitor Randy.Dunlap 3 participants 5 messages Jan 25, 2004 – Jan 30, 2004

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

Hi,
Please apply to 2.6.current.

Thanks,
--
~Randy

From: Leann Ogasawara <[email protected]>

Hi All,

Inserts missing iounmap's and release_mem_region's. Appreciate feedback.

Leann

diffed against 2.6.1

===== drivers/net/depca.c 1.20 vs edited =====

diff -puN drivers/net/depca.c~depca_iounmap drivers/net/depca.c

diff -puN drivers/net/depca.c~depca_iounmap drivers/net/depca.c

 linux-262-rc1-bk1-rddunlap/drivers/net/depca.c |    4 ++++
 1 files changed, 4 insertions(+)
drivers/net/depca.c renamed from drivers/net/depca.c~depca_iounmap +4 -0
diff -puN drivers/net/depca.c~depca_iounmap drivers/net/depca.c
@@ -771,6 +771,8 @@ static int __init depca_hw_init (struct 
 		status = -ENXIO;
 		if (!irqnum) {
 			printk(" and failed to detect IRQ line.\n");
+			iounmap(lp->sh_mem);
+			release_mem_region(mem_start, mem_len);
 			goto out_priv;
 		} else {
 			for (dev->irq = 0, i = 0; (depca_irq[i]) && (!dev->irq); i++)
@@ -781,6 +783,8 @@ static int __init depca_hw_init (struct 
 
 			if (!dev->irq) {
 				printk(" but incorrect IRQ line detected.\n");
+				iounmap(lp->sh_mem);
+				release_mem_region(mem_start, mem_len);
 				return -ENXIO;
 			}
 		}

_

#1 lore raw

Most of these patches you're sending are already in netdev-2.6, AFAICS...

Jeff

#2 lore raw

On Sun, 25 Jan 2004 11:36:38 -0500 Jeff Garzik <[email protected]> wrote:

| Most of these patches you're sending are already in netdev-2.6, AFAICS...

net: remove unnecessary type casting -- not found in netdev

tc35815: handle ioremap() failure -- still missed (*Leann)

depca: release resource on errors -- yes, already in netdev

dgrs: add iounmap()s to failure paths -- still missed (*Leann)

--
~Randy

*Leann: Please rediff these 2 patches after Jeff's netdev patches are merged, or rediff them against his patchsets.
http://www.kernel.org/pub/linux/kernel/people/jgarzik/patchkits/2.6/

#3 lore raw
Quoted 6 lines · Randy.Dunlap

On Sun, 25 Jan 2004 11:36:38 -0500 Jeff Garzik <[email protected]> wrote:

| Most of these patches you're sending are already in netdev-2.6, AFAICS...

net: remove unnecessary type casting -- not found in netdev

I applied this one

Quoted 1 line

tc35815: handle ioremap() failure -- still missed (*Leann)

        dev->base_addr = (unsigned long)ioremap(base_addr, 
sizeof(struct tc35815_regs));
        if (!dev->base_addr) {
                ret = -ENOMEM;
                goto err_out;
        }
Quoted 1 line

dgrs: add iounmap()s to failure paths -- still missed (*Leann)

this wants fixing as well

#4 lore raw

On Sun, 2004-01-25 at 20:25, Jeff Garzik wrote:
[snip]

Quoted 3 lines
Quoted 1 line

dgrs: add iounmap()s to failure paths -- still missed (*Leann)

this wants fixing as well

Updated and rediffed janitor cleanup for drivers/net/dgrs.c against netdev-2.6. I don't have the hardware to fully test, but module compiled/loaded/unloaded fine. Feedback appreciated. Thanks,

Leann

===== drivers/net/dgrs.c 1.23 vs edited =====

drivers/net/dgrs.c +47 -16
@@ -327,8 +327,11 @@
 	 */
 	priv0->vplxdma[PLX_DMA0_MODE/4] = 0xFFFFFFFF;
 	x = priv0->vplxdma[PLX_DMA0_MODE/4];
-	if (x != 0x00001FFF)
+	if (x != 0x00001FFF) {
+		iounmap((void *) priv0->vplxdma);
+		priv0->vplxdma = NULL;
 		return (0);
+	}
 
 	return (1);
 }
@@ -989,6 +992,7 @@
 {
 	DGRS_PRIV	*priv0 = (DGRS_PRIV *) dev0->priv;
 	int		is;
+	int		ret;
 	unsigned long	i;
 
 	static int	iv2is[16] = {
@@ -1004,7 +1008,8 @@
 	if (!priv0->vmem)
 	{
 		printk("%s: cannot map in board memory\n", dev0->name);
-		return -ENXIO;
+		ret = -ENXIO;
+		goto err_out;
 	}
 
 	/*
@@ -1020,7 +1025,8 @@
 		if (!is)
 		{
 			printk("%s: Illegal IRQ %d\n", dev0->name, dev0->irq);
-			return -ENXIO;
+			ret = -ENXIO;
+			goto err_iounmap_vmem;
 		}
 		OUTB(dev0->base_addr + ES4H_AS_31_24,
 			(uchar) (dev0->mem_start >> 24) );
@@ -1047,10 +1053,9 @@
 	memcpy(priv0->vmem, dgrs_code, dgrs_ncode);	/* Load code */
 	if (memcmp(priv0->vmem, dgrs_code, dgrs_ncode))
 	{
-		iounmap(priv0->vmem);
-		priv0->vmem = NULL;
 		printk("%s: download compare failed\n", dev0->name);
-		return -ENXIO;
+		ret = -ENXIO;
+		goto err_iounmap_vplxdma;
 	}
 
 	/*
@@ -1101,7 +1106,8 @@
 	if (priv0->bcomm->bc_status < BC_RUN)
 	{
 		printk("%s: board not operating\n", dev0->name);
-		return -ENXIO;
+		ret = -ENXIO;
+		goto err_iounmap_vplxdma;
 	}
 
 	priv0->port = (PORT *) S2H(priv0->bcomm->bc_port);
@@ -1139,6 +1145,19 @@
 	}
 
 	return (0);
+
+ err_iounmap_vplxdma:
+	if (priv0->vplxdma) {
+		iounmap((void *) priv0->vplxdma);
+		priv0->vplxdma = NULL;
+	}
+
+ err_iounmap_vmem:
+	iounmap(priv0->vmem);
+
+ err_out:
+	priv0->vmem = NULL;
+	return ret;
 }
 
 /*
@@ -1175,7 +1194,7 @@
 	{
 		printk("%s: Illegal Ethernet Address\n", dev->name);
 		rc = -ENXIO;
-		goto err_out;
+		goto err_iounmap;
 	}
 
 	/*
@@ -1187,7 +1206,7 @@
 	
 	rc = request_irq(dev->irq, &dgrs_intr, SA_SHIRQ, "RightSwitch", dev);
 	if (rc)
-		goto err_out;
+		goto err_iounmap;
 
 	priv->intrcnt = 0;
 	for (i = jiffies + 2*HZ + HZ/2; time_after(i, jiffies); )
@@ -1218,6 +1237,15 @@
 
 err_free_irq:
 	free_irq(dev->irq, dev);
+
+err_iounmap:
+	if (priv->vplxdma) {
+		iounmap((void *) priv->vplxdma);
+		priv->vplxdma = NULL;
+	}
+	iounmap(priv->vmem);
+	priv->vmem = NULL;
+
 err_out:
        	return rc;
 }
@@ -1331,13 +1359,21 @@
 
  fail:	
 	while (i >= 0) {
-		struct net_device *d = priv->devtbl[i--];
+		struct net_device *d = priv->devtbl[--i];
 		unregister_netdev(d);
 		free_netdev(d);
 	}
 
  err2:
 	free_irq(dev->irq, dev);
+	if (priv->vplxdma) {
+		iounmap((void *) priv->vplxdma);
+		priv->vplxdma = NULL;
+	}
+
+	iounmap(priv->vmem);
+	priv->vmem = NULL;
+
  err1:
 	free_netdev(dev);
  err0:
@@ -1364,15 +1400,10 @@
 	if (priv->vmem)
 		iounmap(priv->vmem);
 	if (priv->vplxdma)
-		iounmap((uchar *) priv->vplxdma);
+		iounmap((void *) priv->vplxdma);
 
 	if (dev->irq)
 		free_irq(dev->irq, dev);
-
-	for (i = 1; i < priv->nports; ++i) {
-		if (priv->devtbl[i])
-			unregister_netdev(priv->devtbl[i]);
-	}
 }
 
 #ifdef CONFIG_PCI