public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [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

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