scsi: raise error when sg slab/mempool cannot be initialized
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]>
Signed-off-by Akinobu Mita <[email protected]>
--- drivers/scsi/scsi_lib.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/scsi/scsi_lib.c +14 -0
@@ -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 )