Skip to contentSkip to conversation

scsi: raise error when sg slab/mempool cannot be initialized

PATCH New Akinobu Mita 1 participant 1 message Dec 19, 2006 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: raise error when sg slab/mempool cannot be initialized

This patch raises error when sg slab or mempool cannot be initialized. It is better than crash after initialization.

Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/scsi_lib.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/scsi/scsi_lib.c +14 -0
Index: 2.6-mm/drivers/scsi/scsi_lib.c
===================================================================
@@ -1682,6 +1682,7 @@ int __init scsi_init_queue(void)
 		if (!sgp->slab) {
 			printk(KERN_ERR "SCSI: can't init sg slab %s\n",
 					sgp->name);
+			goto out;
 		}
 
 		sgp->pool = mempool_create_slab_pool(SG_MEMPOOL_SIZE,
@@ -1689,10 +1690,23 @@ int __init scsi_init_queue(void)
 		if (!sgp->pool) {
 			printk(KERN_ERR "SCSI: can't init sg mempool %s\n",
 					sgp->name);
+			goto out;
 		}
 	}
 
 	return 0;
+out:
+	for (i = 0; i < SG_MEMPOOL_NR; i++) {
+		struct scsi_host_sg_pool *sgp = scsi_sg_pools + i;
+		if (sgp->pool)
+			mempool_destroy(sgp->pool);
+		if (sgp->slab)
+			kmem_cache_destroy(sgp->slab);
+	}
+
+	kmem_cache_destroy(scsi_io_context_cache);
+
+	return -ENOMEM;
 }
 
 void scsi_exit_queue(void)