aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/bsg.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/block/bsg.c b/block/bsg.c
index 26a9372962ce..cdb00e5544b1 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -68,11 +68,6 @@ enum {
68#define dprintk(fmt, args...) 68#define dprintk(fmt, args...)
69#endif 69#endif
70 70
71/*
72 * just for testing
73 */
74#define BSG_MAJOR (240)
75
76static DEFINE_MUTEX(bsg_mutex); 71static DEFINE_MUTEX(bsg_mutex);
77static int bsg_device_nr, bsg_minor_idx; 72static int bsg_device_nr, bsg_minor_idx;
78 73
@@ -82,6 +77,7 @@ static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE];
82 77
83static struct class *bsg_class; 78static struct class *bsg_class;
84static LIST_HEAD(bsg_class_list); 79static LIST_HEAD(bsg_class_list);
80static int bsg_major;
85 81
86static struct kmem_cache *bsg_cmd_cachep; 82static struct kmem_cache *bsg_cmd_cachep;
87 83
@@ -943,7 +939,7 @@ void bsg_unregister_queue(struct request_queue *q)
943 939
944 mutex_lock(&bsg_mutex); 940 mutex_lock(&bsg_mutex);
945 sysfs_remove_link(&q->kobj, "bsg"); 941 sysfs_remove_link(&q->kobj, "bsg");
946 class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor)); 942 class_device_destroy(bsg_class, MKDEV(bsg_major, bcd->minor));
947 bcd->class_dev = NULL; 943 bcd->class_dev = NULL;
948 list_del_init(&bcd->list); 944 list_del_init(&bcd->list);
949 bsg_device_nr--; 945 bsg_device_nr--;
@@ -989,7 +985,7 @@ retry:
989 bsg_minor_idx = 0; 985 bsg_minor_idx = 0;
990 986
991 bcd->queue = q; 987 bcd->queue = q;
992 dev = MKDEV(BSG_MAJOR, bcd->minor); 988 dev = MKDEV(bsg_major, bcd->minor);
993 class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name); 989 class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name);
994 if (IS_ERR(class_dev)) { 990 if (IS_ERR(class_dev)) {
995 ret = PTR_ERR(class_dev); 991 ret = PTR_ERR(class_dev);
@@ -1010,7 +1006,7 @@ retry:
1010 return 0; 1006 return 0;
1011err: 1007err:
1012 if (class_dev) 1008 if (class_dev)
1013 class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor)); 1009 class_device_destroy(bsg_class, MKDEV(bsg_major, bcd->minor));
1014 mutex_unlock(&bsg_mutex); 1010 mutex_unlock(&bsg_mutex);
1015 return ret; 1011 return ret;
1016} 1012}
@@ -1047,6 +1043,7 @@ static struct cdev bsg_cdev = {
1047static int __init bsg_init(void) 1043static int __init bsg_init(void)
1048{ 1044{
1049 int ret, i; 1045 int ret, i;
1046 dev_t devid;
1050 1047
1051 bsg_cmd_cachep = kmem_cache_create("bsg_cmd", 1048 bsg_cmd_cachep = kmem_cache_create("bsg_cmd",
1052 sizeof(struct bsg_command), 0, 0, NULL, NULL); 1049 sizeof(struct bsg_command), 0, 0, NULL, NULL);
@@ -1064,19 +1061,21 @@ static int __init bsg_init(void)
1064 return PTR_ERR(bsg_class); 1061 return PTR_ERR(bsg_class);
1065 } 1062 }
1066 1063
1067 ret = register_chrdev_region(MKDEV(BSG_MAJOR, 0), BSG_MAX_DEVS, "bsg"); 1064 ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg");
1068 if (ret) { 1065 if (ret) {
1069 kmem_cache_destroy(bsg_cmd_cachep); 1066 kmem_cache_destroy(bsg_cmd_cachep);
1070 class_destroy(bsg_class); 1067 class_destroy(bsg_class);
1071 return ret; 1068 return ret;
1072 } 1069 }
1073 1070
1071 bsg_major = MAJOR(devid);
1072
1074 cdev_init(&bsg_cdev, &bsg_fops); 1073 cdev_init(&bsg_cdev, &bsg_fops);
1075 ret = cdev_add(&bsg_cdev, MKDEV(BSG_MAJOR, 0), BSG_MAX_DEVS); 1074 ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS);
1076 if (ret) { 1075 if (ret) {
1077 kmem_cache_destroy(bsg_cmd_cachep); 1076 kmem_cache_destroy(bsg_cmd_cachep);
1078 class_destroy(bsg_class); 1077 class_destroy(bsg_class);
1079 unregister_chrdev_region(MKDEV(BSG_MAJOR, 0), BSG_MAX_DEVS); 1078 unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
1080 return ret; 1079 return ret;
1081 } 1080 }
1082 1081
@@ -1085,11 +1084,11 @@ static int __init bsg_init(void)
1085 printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret); 1084 printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret);
1086 kmem_cache_destroy(bsg_cmd_cachep); 1085 kmem_cache_destroy(bsg_cmd_cachep);
1087 class_destroy(bsg_class); 1086 class_destroy(bsg_class);
1088 unregister_chrdev(BSG_MAJOR, "bsg"); 1087 unregister_chrdev(bsg_major, "bsg");
1089 return ret; 1088 return ret;
1090 } 1089 }
1091 1090
1092 printk(KERN_INFO "%s loaded\n", bsg_version); 1091 printk(KERN_INFO "%s loaded (major %d)\n", bsg_version, bsg_major);
1093 return 0; 1092 return 0;
1094} 1093}
1095 1094