Hi all, check_region() patches attached. Next patchset will be ready in monday. Best regards, Andrey --
diff -urN /mnt/disk/linux/drivers/net/3c501.c /linux/drivers/net/3c501.c --- /mnt/disk/linux/drivers/net/3c501.c Tue Sep 12 23:47:56 2000 +++ /linux/drivers/net/3c501.c Thu Sep 28 20:48:23 2000 @@ -246,13 +246,8 @@ return -ENXIO; for (i = 0; netcard_portlist[i]; i++) - { - int ioaddr = netcard_portlist[i]; - if (check_region(ioaddr, EL1_IO_EXTENT)) - continue; - if (el1_probe1(dev, ioaddr) == 0) + if (el1_probe1(dev, netcard_portlist[i]) == 0) return 0; - } return -ENODEV; }
diff -urN /mnt/disk/linux/drivers/net/3c503.c /linux/drivers/net/3c503.c --- /mnt/disk/linux/drivers/net/3c503.c Tue Sep 12 23:49:16 2000 +++ /linux/drivers/net/3c503.c Thu Sep 28 21:23:06 2000 @@ -154,14 +154,18 @@ int __init el2_probe1(struct net_device *dev, int ioaddr) { - int i, iobase_reg, membase_reg, saved_406, wordlength; + int i, iobase_reg, membase_reg, saved_406, wordlength, retval; static unsigned version_printed = 0; unsigned long vendor_id; + if (!request_region(ioaddr, EL2_IO_EXTENT, "3c503")) + return -ENODEV; + /* Reset and/or avoid any lurking NE2000 */ if (inb(ioaddr + 0x408) == 0xff) { mdelay(1); - return -ENODEV; + retval = -ENODEV; + goto out; } /* We verify that it's a 3C503 board by checking the first three octets @@ -171,7 +175,8 @@ /* ASIC location registers should be 0 or have only a single bit set. */ if ( (iobase_reg & (iobase_reg - 1)) || (membase_reg & (membase_reg - 1))) { - return -ENODEV; + retval = -ENODEV; + goto out; } saved_406 = inb_p(ioaddr + 0x406); outb_p(ECNTRL_RESET|ECNTRL_THIN, ioaddr + 0x406); /* Reset it... */ @@ -183,7 +188,8 @@ if ((vendor_id != OLD_3COM_ID) && (vendor_id != NEW_3COM_ID)) { /* Restore the register we frobbed. */ outb(saved_406, ioaddr + 0x406); - return -ENODEV; + retval = -ENODEV; + goto out; } /* We should have a "dev" from Space.c or the static module table. */ @@ -191,8 +197,10 @@ printk("3c503.c: Passed a NULL device.\n"); dev = init_etherdev(0, 0); - if (!dev) - return -ENOMEM; + if (!dev) { + retval = -ENOMEM; + goto out; + } } if (ei_debug && version_printed++ == 0) @@ -202,8 +210,9 @@ /* Allocate dev->priv and fill in 8390 specific dev fields. */ if (ethdev_init(dev)) { printk ("3c503: unable to allocate memory for dev->priv.\n"); - return -ENOMEM; - } + retval = -ENOMEM; + goto out; + } printk("%s: 3c503 at i/o base %#3x, node ", dev->name, ioaddr); @@ -302,8 +311,6 @@ ei_status.block_input = &el2_block_input; ei_status.block_output = &el2_block_output; - request_region(ioaddr, EL2_IO_EXTENT, ei_status.name); - if (dev->irq == 2) dev->irq = 9; else if (dev->irq > 5 && dev->irq != 9) { @@ -330,6 +337,9 @@ dev->name, ei_status.name, (wordlength+1)<<3); } return 0; +out: + release_region(ioaddr, EL2_IO_EXTENT); + return retval; } static int
diff -urN /mnt/disk/linux/drivers/net/3c507.c /linux/drivers/net/3c507.c --- /mnt/disk/linux/drivers/net/3c507.c Tue Sep 26 19:48:54 2000 +++ /linux/drivers/net/3c507.c Thu Sep 28 22:42:41 2000 @@ -317,13 +317,9 @@ else if (base_addr != 0) return -ENXIO; /* Don't probe at all. */ - for (i = 0; netcard_portlist[i]; i++) { - int ioaddr = netcard_portlist[i]; - if (check_region(ioaddr, EL16_IO_EXTENT)) - continue; - if (el16_probe1(dev, ioaddr) == 0) + for (i = 0; netcard_portlist[i]; i++) + if (el16_probe1(dev, netcard_portlist[i]) == 0) return 0; - } return -ENODEV; } @@ -331,7 +327,7 @@ static int __init el16_probe1(struct net_device *dev, int ioaddr) { static unsigned char init_ID_done = 0, version_printed = 0; - int i, irq, irqval; + int i, irq, irqval, retval; struct net_local *lp; if (init_ID_done == 0) { @@ -348,15 +344,21 @@ init_ID_done = 1; } - if (inb(ioaddr) == '*' && inb(ioaddr+1) == '3' - && inb(ioaddr+2) == 'C' && inb(ioaddr+3) == 'O') - ; - else + if (!request_region(ioaddr, EL16_IO_EXTENT, "3c507")) return -ENODEV; + if ((inb(ioaddr) != '*') || (inb(ioaddr + 1) != '3') || + (inb(ioaddr + 2) != 'C') || (inb(ioaddr + 3) != 'O')) { + retval = -ENODEV; + goto out; + } + /* Allocate a new 'dev' if needed. */ if (dev == NULL) - dev = init_etherdev(0, 0); + if (!(dev = init_etherdev(0, 0))) { + retval = -ENOMEM; + goto out; + } if (net_debug && version_printed++ == 0) printk(version); @@ -371,11 +373,11 @@ irqval = request_irq(irq, &el16_interrupt, 0, "3c507", dev); if (irqval) { printk ("unable to get IRQ %d (irqval=%d).\n", irq, irqval); - return -EAGAIN; + retval = -EAGAIN; + goto out; } /* We've committed to using the board, and can start filling in *dev. */ - request_region(ioaddr, EL16_IO_EXTENT, "3c507"); dev->base_addr = ioaddr; outb(0x01, ioaddr + MISC_CTRL); @@ -419,8 +421,10 @@ /* Initialize the device structure. */ lp = dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL); - if (dev->priv == NULL) - return -ENOMEM; + if (dev->priv == NULL) { + retval = -ENOMEM; + goto out; + } memset(dev->priv, 0, sizeof(struct net_local)); spin_lock_init(&lp->lock); @@ -436,6 +440,9 @@ dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */ return 0; +out: + release_region(ioaddr, EL16_IO_EXTENT); + return retval; } static int el16_open(struct net_device *dev)
--- /mnt/disk/linux/drivers/net/ne.c Wed Sep 27 22:46:30 2000 +++ /linux/drivers/net/ne.c Thu Sep 28 20:45:32 2000 @@ -210,10 +210,7 @@ #ifndef MODULE /* Last resort. The semi-risky ISA auto-probe. */ for (base_addr = 0; netcard_portlist[base_addr] != 0; base_addr++) { - int ioaddr = netcard_portlist[base_addr]; - if (check_region(ioaddr, NE_IO_EXTENT)) - continue; - if (ne_probe1(dev, ioaddr) == 0) + if (ne_probe1(dev, netcard_portlist[base_addr]) == 0) return 0; } #endif @@ -235,9 +232,6 @@ if (pci_enable_device(pdev)) continue; pci_ioaddr = pci_resource_start (pdev, 0); - /* Avoid already found cards from previous calls */ - if (check_region(pci_ioaddr, NE_IO_EXTENT)) - continue; pci_irq_line = pdev->irq; if (pci_irq_line) break; /* Found it */ } @@ -307,12 +301,17 @@ const char *name = NULL; int start_page, stop_page; int neX000, ctron, copam, bad_card; - int reg0 = inb_p(ioaddr); + int reg0, retval; static unsigned version_printed = 0; - if (reg0 == 0xFF) + if (!request_region(ioaddr, NE_IO_EXTENT, "ne")) return -ENODEV; + if ((reg0 = inb_p(ioaddr)) == 0xFF) { + retval = -ENODEV; + goto out; + } + /* Do a preliminary verification that we have a 8390. */ { int regd; @@ -324,7 +323,8 @@ if (inb_p(ioaddr + EN0_COUNTER0) != 0) { outb_p(reg0, ioaddr); outb_p(regd, ioaddr + 0x0d); /* Restore the old values. */ - return -ENODEV; + retval = -ENODEV; + goto out; } } @@ -363,7 +363,8 @@ break; } else { printk(" not found (no reset ack).\n"); - return -ENODEV; + retval = -ENODEV; + goto out; } } @@ -465,11 +466,13 @@ { printk(" not found (invalid signature %2.2x %2.2x).\n", SA_prom[14], SA_prom[15]); - return -ENXIO; + retval = -ENXIO; + goto out; } #else printk(" not found.\n"); - return -ENXIO; + retval = -ENXIO; + goto out; #endif } @@ -495,14 +498,16 @@ if (! dev->irq) { printk(" failed to detect IRQ line.\n"); - return -EAGAIN; + retval = -EAGAIN; + goto out; } /* Allocate dev->priv and fill in 8390 specific dev fields. */ if (ethdev_init(dev)) { printk (" unable to get memory for dev->priv.\n"); - return -ENOMEM; + retval = -ENOMEM; + goto out; } /* Snarf the interrupt now. There's no point in waiting since we cannot @@ -515,11 +520,11 @@ printk (" unable to get IRQ %d (irqval=%d).\n", dev->irq, irqval); kfree(dev->priv); dev->priv = NULL; - return -EAGAIN; + retval = -EAGAIN; + goto out; } } dev->base_addr = ioaddr; - request_region(ioaddr, NE_IO_EXTENT, name); for(i = 0; i < ETHER_ADDR_LEN; i++) { printk(" %2.2x", SA_prom[i]); @@ -549,6 +554,9 @@ dev->stop = &ne_close; NS8390_init(dev, 0); return 0; +out: + release_region(ioaddr, NE_IO_EXTENT); + return retval; } static int ne_open(struct net_device *dev)