aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2007-07-17 06:20:46 -0400
committerJens Axboe <jens.axboe@oracle.com>2007-07-17 06:20:46 -0400
commit9b9f770cef0037fd0e4d623f31ddfa8acda38205 (patch)
treea0b8937223df1e5a519375d1fa797157b4a930a2
parent5cdf7f7678493996a835ef2e627976de8f9d1f40 (diff)
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>
-rw-r--r--block/bsg.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/block/bsg.c b/block/bsg.c
index cdb00e5544b1..b25378459ff0 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -1057,39 +1057,37 @@ static int __init bsg_init(void)
1057 1057
1058 bsg_class = class_create(THIS_MODULE, "bsg"); 1058 bsg_class = class_create(THIS_MODULE, "bsg");
1059 if (IS_ERR(bsg_class)) { 1059 if (IS_ERR(bsg_class)) {
1060 kmem_cache_destroy(bsg_cmd_cachep); 1060 ret = PTR_ERR(bsg_class);
1061 return PTR_ERR(bsg_class); 1061 goto destroy_kmemcache;
1062 } 1062 }
1063 1063
1064 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg"); 1064 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
1065 if (ret) { 1065 if (ret)
1066 kmem_cache_destroy(bsg_cmd_cachep); 1066 goto destroy_bsg_class;
1067 class_destroy(bsg_class);
1068 return ret;
1069 }
1070 1067
1071 bsg_major = MAJOR(devid); 1068 bsg_major = MAJOR(devid);
1072 1069
1073 cdev_init(&bsg_cdev, &bsg_fops); 1070 cdev_init(&bsg_cdev, &bsg_fops);
1074 ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS); 1071 ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS);
1075 if (ret) { 1072 if (ret)
1076 kmem_cache_destroy(bsg_cmd_cachep); 1073 goto unregister_chrdev;
1077 class_destroy(bsg_class);
1078 unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
1079 return ret;
1080 }
1081 1074
1082 ret = scsi_register_interface(&bsg_intf); 1075 ret = scsi_register_interface(&bsg_intf);
1083 if (ret) { 1076 if (ret)
1084 printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret); 1077 goto remove_cdev;
1085 kmem_cache_destroy(bsg_cmd_cachep);
1086 class_destroy(bsg_class);
1087 unregister_chrdev(bsg_major, "bsg");
1088 return ret;
1089 }
1090 1078
1091 printk(KERN_INFO "%s loaded (major %d)\n", bsg_version, bsg_major); 1079 printk(KERN_INFO "%s loaded (major %d)\n", bsg_version, bsg_major);
1092 return 0; 1080 return 0;
1081remove_cdev:
1082 printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret);
1083 cdev_del(&bsg_cdev);
1084unregister_chrdev:
1085 unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
1086destroy_bsg_class:
1087 class_destroy(bsg_class);
1088destroy_kmemcache:
1089 kmem_cache_destroy(bsg_cmd_cachep);
1090 return ret;
1093} 1091}
1094 1092
1095MODULE_AUTHOR("Jens Axboe"); 1093MODULE_AUTHOR("Jens Axboe");