Skip to content

Commit

Permalink
[SCSI] handle scsi_init_queue failure properly
Browse files Browse the repository at this point in the history
scsi_init_queue is expected to clean up allocated things when it
fails.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
  • Loading branch information
FUJITA Tomonori authored and James Bottomley committed Jan 30, 2008
1 parent b172b6e commit 3d9dd6e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drivers/scsi/scsi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ int __init scsi_init_queue(void)
0, 0, NULL);
if (!scsi_bidi_sdb_cache) {
printk(KERN_ERR "SCSI: can't init scsi bidi sdb cache\n");
return -ENOMEM;
goto cleanup_io_context;
}

for (i = 0; i < SG_MEMPOOL_NR; i++) {
Expand All @@ -1694,17 +1694,33 @@ int __init scsi_init_queue(void)
if (!sgp->slab) {
printk(KERN_ERR "SCSI: can't init sg slab %s\n",
sgp->name);
goto cleanup_bidi_sdb;
}

sgp->pool = mempool_create_slab_pool(SG_MEMPOOL_SIZE,
sgp->slab);
if (!sgp->pool) {
printk(KERN_ERR "SCSI: can't init sg mempool %s\n",
sgp->name);
goto cleanup_bidi_sdb;
}
}

return 0;

cleanup_bidi_sdb:
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_bidi_sdb_cache);
cleanup_io_context:
kmem_cache_destroy(scsi_io_context_cache);

return -ENOMEM;
}

void scsi_exit_queue(void)
Expand Down

0 comments on commit 3d9dd6e

Please sign in to comment.