Commit 685eba2c authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] loop.c doesn't fail init gracefully

From: BlaisorBlade <blaisorblade_spam@yahoo.it>

loop_init doesn't fail gracefully for two reasons:

1) If initialization of loop driver fails, we have an call to
   devfs_add("loop") without any devfs_remove; I add that.

2) On lwn.net 2.6 kernel docs, Jonathan Corbet says: "If you are calling
   add_disk() in your driver initialization routine, you should not fail
   the initialization process after the first call."

So I make loop.c conform to this request by moving add_disk after all
memory allocations.
parent 56b63427
...@@ -1027,14 +1027,18 @@ int __init loop_init(void) ...@@ -1027,14 +1027,18 @@ int __init loop_init(void)
sprintf(disk->devfs_name, "loop/%d", i); sprintf(disk->devfs_name, "loop/%d", i);
disk->private_data = lo; disk->private_data = lo;
disk->queue = lo->lo_queue; disk->queue = lo->lo_queue;
add_disk(disk);
} }
/* We cannot fail after we call this, so another loop!*/
for (i = 0; i < max_loop; i++)
add_disk(disks[i]);
printk(KERN_INFO "loop: loaded (max %d devices)\n", max_loop); printk(KERN_INFO "loop: loaded (max %d devices)\n", max_loop);
return 0; return 0;
out_mem4: out_mem4:
while (i--) while (i--)
blk_put_queue(loop_dev[i].lo_queue); blk_put_queue(loop_dev[i].lo_queue);
devfs_remove("loop");
i = max_loop; i = max_loop;
out_mem3: out_mem3:
while (i--) while (i--)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment