[PATCH] lance.c: check kmalloc return and get rid of check_region

From: Arnaldo Carvalho de Melo (acme@conectiva.com.br)
Date: Thu Jan 11 2001 - 12:12:12 EST


Hi,

        Please consider applying.

- Arnaldo

--- linux-2.4.0-ac6/drivers/net/lance.c Wed Jan 10 22:31:42 2001
+++ linux-2.4.0-ac6.acme/drivers/net/lance.c Thu Jan 11 15:08:06 2001
@@ -33,6 +33,9 @@
     
     Forward ported v1.14 to 2.1.129, merged the PCI and misc changes from
     the 2.1 version of the old driver - Alan Cox
+
+ Get rid of check_region, check kmalloc return in lance_probe1
+ Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 11/01/2001
 */
 
 static const char *version = "lance.c:v1.15ac 1999/11/13 dplatt@3do.com, becker@cesdis.gsfc.nasa.gov\n";
@@ -352,17 +355,27 @@
 
         for (port = lance_portlist; *port; port++) {
                 int ioaddr = *port;
+ struct resource *r = request_region(ioaddr, LANCE_TOTAL_SIZE,
+ "lance-probe");
 
- if ( check_region(ioaddr, LANCE_TOTAL_SIZE) == 0) {
+ if (r) {
                         /* Detect "normal" 0x57 0x57 and the NI6510EB 0x52 0x44
                            signatures w/ minimal I/O reads */
                         char offset15, offset14 = inb(ioaddr + 14);
                         
                         if ((offset14 == 0x52 || offset14 == 0x57) &&
- ((offset15 = inb(ioaddr + 15)) == 0x57 || offset15 == 0x44)) {
+ ((offset15 = inb(ioaddr + 15)) == 0x57 ||
+ offset15 == 0x44)) {
                                 result = lance_probe1(dev, ioaddr, 0, 0);
- if ( !result ) return 0;
+ if (!result) {
+ struct lance_private *lp = dev->priv;
+ int ver = lp->chip_version;
+
+ r->name = chip_table[ver].name;
+ return 0;
+ }
                         }
+ release_resource(r);
                 }
         }
         return -ENODEV;
@@ -444,12 +457,10 @@
                 printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
 
         dev->base_addr = ioaddr;
- request_region(ioaddr, LANCE_TOTAL_SIZE, chip_table[lance_version].name);
-
         /* Make certain the data structures used by the LANCE are aligned and DMAble. */
                 
         lp = (struct lance_private *)(((unsigned long)kmalloc(sizeof(*lp)+7,
- GFP_DMA | GFP_KERNEL)+7) & ~7);
+ GFP_DMA | GFP_KERNEL)+7) & ~7);
         if(lp==NULL)
                 return -ENODEV;
         if (lance_debug > 6) printk(" (#0x%05lx)", (unsigned long)lp);
@@ -457,11 +468,16 @@
         dev->priv = lp;
         lp->name = chipname;
         lp->rx_buffs = (unsigned long)kmalloc(PKT_BUF_SZ*RX_RING_SIZE,
+
+ if (!lp->rx_buffs)
+ goto out_lp;
                                                                                   GFP_DMA | GFP_KERNEL);
- if (lance_need_isa_bounce_buffers)
+ if (lance_need_isa_bounce_buffers) {
                 lp->tx_bounce_buffs = kmalloc(PKT_BUF_SZ*TX_RING_SIZE,
- GFP_DMA | GFP_KERNEL);
- else
+ GFP_DMA | GFP_KERNEL);
+ if (!lp->tx_bounce_buffs)
+ goto out_rx;
+ } else
                 lp->tx_bounce_buffs = NULL;
 
         lp->chip_version = lance_version;
@@ -628,6 +644,9 @@
         dev->watchdog_timeo = TX_TIMEOUT;
 
         return 0;
+out_rx: kfree(lp->rx_buffs);
+out_lp: kfree(lp);
+ return -ENOMEM;
 }
 
 static int
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jan 15 2001 - 21:00:31 EST