* [PATCH] ide-probe.c: check kmalloc return
@ 2001-01-11 16:48 Arnaldo Carvalho de Melo
2001-01-11 17:12 ` [PATCH] lance.c: check kmalloc return and get rid of check_region Arnaldo Carvalho de Melo
0 siblings, 1 reply; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2001-01-11 16:48 UTC (permalink / raw)
To: andre; +Cc: Alan Cox, linux-kernel
Hi,
Please consider applying.
- Arnaldo
--- linux-2.4.0-ac6/drivers/ide/ide-probe.c Thu Aug 10 10:14:26 2000
+++ linux-2.4.0-ac6.acme/drivers/ide/ide-probe.c Thu Jan 11 14:37:35 2001
@@ -56,6 +56,12 @@
struct hd_driveid *id;
id = drive->id = kmalloc (SECTOR_WORDS*4, GFP_ATOMIC); /* called with interrupts disabled! */
+ if (!id) {
+ printk(KERN_WARNING "%s: ouch, out of memory in do_identify!\n",
+ drive->name);
+ drive->present = 0;
+ return;
+ }
ide_input_data(drive, id, SECTOR_WORDS); /* read 512 bytes of id info */
ide__sti(); /* local CPU only */
ide_fix_driveid(id);
@@ -652,6 +658,10 @@
hwgroup = match->hwgroup;
} else {
hwgroup = kmalloc(sizeof(ide_hwgroup_t), GFP_KERNEL);
+ if (!hwgroup) {
+ restore_flags(flags); /* all CPUs */
+ return 1;
+ }
memset(hwgroup, 0, sizeof(ide_hwgroup_t));
hwgroup->hwif = hwif->next = hwif;
hwgroup->rq = NULL;
@@ -746,11 +756,23 @@
}
minors = units * (1<<PARTN_BITS);
gd = kmalloc (sizeof(struct gendisk), GFP_KERNEL);
+ if (!gd)
+ goto out;
gd->sizes = kmalloc (minors * sizeof(int), GFP_KERNEL);
+ if (!gd->sizes)
+ goto out_gd;
gd->part = kmalloc (minors * sizeof(struct hd_struct), GFP_KERNEL);
+ if (!gd->part)
+ goto out_sizes;
bs = kmalloc (minors*sizeof(int), GFP_KERNEL);
+ if (!bs)
+ goto out_part;
max_sect = kmalloc (minors*sizeof(int), GFP_KERNEL);
+ if (!max_sect)
+ goto out_bs;
max_ra = kmalloc (minors*sizeof(int), GFP_KERNEL);
+ if (!max_ra)
+ goto out_max_sect;
memset(gd->part, 0, minors * sizeof(struct hd_struct));
@@ -802,6 +824,13 @@
devfs_mk_dir (ide_devfs_handle, name, NULL);
}
}
+ goto out;
+out_max_sect: kfree(max_sect);
+out_bs: kfree(bs);
+out_part: kfree(gd->part);
+out_sizes: kfree(gd->sizes);
+out_gd: kfree(gd);
+out: return;
}
static int hwif_init (ide_hwif_t *hwif)
-
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] lance.c: check kmalloc return and get rid of check_region
2001-01-11 16:48 [PATCH] ide-probe.c: check kmalloc return Arnaldo Carvalho de Melo
@ 2001-01-11 17:12 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2001-01-11 17:12 UTC (permalink / raw)
To: Alan Cox; +Cc: linux-kernel
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/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-01-11 19:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-01-11 16:48 [PATCH] ide-probe.c: check kmalloc return Arnaldo Carvalho de Melo
2001-01-11 17:12 ` [PATCH] lance.c: check kmalloc return and get rid of check_region Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox