bsg: fix initialization error handling bugs
This fixes the following bugs and cleans up the initialization code: - cdev_del is missing. - unregister_chrdev_region should be used instead of unregister_chrdev. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
This commit is contained in:
parent
5cdf7f7678
commit
9b9f770cef
38
block/bsg.c
38
block/bsg.c
|
@ -1057,39 +1057,37 @@ static int __init bsg_init(void)
|
||||||
|
|
||||||
bsg_class = class_create(THIS_MODULE, "bsg");
|
bsg_class = class_create(THIS_MODULE, "bsg");
|
||||||
if (IS_ERR(bsg_class)) {
|
if (IS_ERR(bsg_class)) {
|
||||||
kmem_cache_destroy(bsg_cmd_cachep);
|
ret = PTR_ERR(bsg_class);
|
||||||
return PTR_ERR(bsg_class);
|
goto destroy_kmemcache;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
|
ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
|
||||||
if (ret) {
|
if (ret)
|
||||||
kmem_cache_destroy(bsg_cmd_cachep);
|
goto destroy_bsg_class;
|
||||||
class_destroy(bsg_class);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bsg_major = MAJOR(devid);
|
bsg_major = MAJOR(devid);
|
||||||
|
|
||||||
cdev_init(&bsg_cdev, &bsg_fops);
|
cdev_init(&bsg_cdev, &bsg_fops);
|
||||||
ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS);
|
ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS);
|
||||||
if (ret) {
|
if (ret)
|
||||||
kmem_cache_destroy(bsg_cmd_cachep);
|
goto unregister_chrdev;
|
||||||
class_destroy(bsg_class);
|
|
||||||
unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = scsi_register_interface(&bsg_intf);
|
ret = scsi_register_interface(&bsg_intf);
|
||||||
if (ret) {
|
if (ret)
|
||||||
printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret);
|
goto remove_cdev;
|
||||||
kmem_cache_destroy(bsg_cmd_cachep);
|
|
||||||
class_destroy(bsg_class);
|
|
||||||
unregister_chrdev(bsg_major, "bsg");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
printk(KERN_INFO "%s loaded (major %d)\n", bsg_version, bsg_major);
|
printk(KERN_INFO "%s loaded (major %d)\n", bsg_version, bsg_major);
|
||||||
return 0;
|
return 0;
|
||||||
|
remove_cdev:
|
||||||
|
printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret);
|
||||||
|
cdev_del(&bsg_cdev);
|
||||||
|
unregister_chrdev:
|
||||||
|
unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
|
||||||
|
destroy_bsg_class:
|
||||||
|
class_destroy(bsg_class);
|
||||||
|
destroy_kmemcache:
|
||||||
|
kmem_cache_destroy(bsg_cmd_cachep);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
MODULE_AUTHOR("Jens Axboe");
|
MODULE_AUTHOR("Jens Axboe");
|
||||||
|
|
Loading…
Reference in New Issue