Commit 46f6ef4a authored by Jens Axboe's avatar Jens Axboe

bsg: convert to dynamic major

240 was hardcoded, that was clearly a dumb mistake. Convert bsg
to use alloc_chrdev_region() to retrieve a dynamic major.
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 25fd1643
...@@ -68,11 +68,6 @@ enum { ...@@ -68,11 +68,6 @@ enum {
#define dprintk(fmt, args...) #define dprintk(fmt, args...)
#endif #endif
/*
* just for testing
*/
#define BSG_MAJOR (240)
static DEFINE_MUTEX(bsg_mutex); static DEFINE_MUTEX(bsg_mutex);
static int bsg_device_nr, bsg_minor_idx; static int bsg_device_nr, bsg_minor_idx;
...@@ -82,6 +77,7 @@ static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE]; ...@@ -82,6 +77,7 @@ static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE];
static struct class *bsg_class; static struct class *bsg_class;
static LIST_HEAD(bsg_class_list); static LIST_HEAD(bsg_class_list);
static int bsg_major;
static struct kmem_cache *bsg_cmd_cachep; static struct kmem_cache *bsg_cmd_cachep;
...@@ -943,7 +939,7 @@ void bsg_unregister_queue(struct request_queue *q) ...@@ -943,7 +939,7 @@ void bsg_unregister_queue(struct request_queue *q)
mutex_lock(&bsg_mutex); mutex_lock(&bsg_mutex);
sysfs_remove_link(&q->kobj, "bsg"); sysfs_remove_link(&q->kobj, "bsg");
class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor)); class_device_destroy(bsg_class, MKDEV(bsg_major, bcd->minor));
bcd->class_dev = NULL; bcd->class_dev = NULL;
list_del_init(&bcd->list); list_del_init(&bcd->list);
bsg_device_nr--; bsg_device_nr--;
...@@ -989,7 +985,7 @@ int bsg_register_queue(struct request_queue *q, const char *name) ...@@ -989,7 +985,7 @@ int bsg_register_queue(struct request_queue *q, const char *name)
bsg_minor_idx = 0; bsg_minor_idx = 0;
bcd->queue = q; bcd->queue = q;
dev = MKDEV(BSG_MAJOR, bcd->minor); dev = MKDEV(bsg_major, bcd->minor);
class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name); class_dev = class_device_create(bsg_class, NULL, dev, bcd->dev, "%s", name);
if (IS_ERR(class_dev)) { if (IS_ERR(class_dev)) {
ret = PTR_ERR(class_dev); ret = PTR_ERR(class_dev);
...@@ -1010,7 +1006,7 @@ int bsg_register_queue(struct request_queue *q, const char *name) ...@@ -1010,7 +1006,7 @@ int bsg_register_queue(struct request_queue *q, const char *name)
return 0; return 0;
err: err:
if (class_dev) if (class_dev)
class_device_destroy(bsg_class, MKDEV(BSG_MAJOR, bcd->minor)); class_device_destroy(bsg_class, MKDEV(bsg_major, bcd->minor));
mutex_unlock(&bsg_mutex); mutex_unlock(&bsg_mutex);
return ret; return ret;
} }
...@@ -1047,6 +1043,7 @@ static struct cdev bsg_cdev = { ...@@ -1047,6 +1043,7 @@ static struct cdev bsg_cdev = {
static int __init bsg_init(void) static int __init bsg_init(void)
{ {
int ret, i; int ret, i;
dev_t devid;
bsg_cmd_cachep = kmem_cache_create("bsg_cmd", bsg_cmd_cachep = kmem_cache_create("bsg_cmd",
sizeof(struct bsg_command), 0, 0, NULL, NULL); sizeof(struct bsg_command), 0, 0, NULL, NULL);
...@@ -1064,19 +1061,21 @@ static int __init bsg_init(void) ...@@ -1064,19 +1061,21 @@ static int __init bsg_init(void)
return PTR_ERR(bsg_class); return PTR_ERR(bsg_class);
} }
ret = register_chrdev_region(MKDEV(BSG_MAJOR, 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); kmem_cache_destroy(bsg_cmd_cachep);
class_destroy(bsg_class); class_destroy(bsg_class);
return ret; return ret;
} }
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); kmem_cache_destroy(bsg_cmd_cachep);
class_destroy(bsg_class); class_destroy(bsg_class);
unregister_chrdev_region(MKDEV(BSG_MAJOR, 0), BSG_MAX_DEVS); unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS);
return ret; return ret;
} }
...@@ -1085,11 +1084,11 @@ static int __init bsg_init(void) ...@@ -1085,11 +1084,11 @@ static int __init bsg_init(void)
printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret); printk(KERN_ERR "bsg: failed register scsi interface %d\n", ret);
kmem_cache_destroy(bsg_cmd_cachep); kmem_cache_destroy(bsg_cmd_cachep);
class_destroy(bsg_class); class_destroy(bsg_class);
unregister_chrdev(BSG_MAJOR, "bsg"); unregister_chrdev(bsg_major, "bsg");
return ret; return ret;
} }
printk(KERN_INFO "%s loaded\n", bsg_version); printk(KERN_INFO "%s loaded (major %d)\n", bsg_version, bsg_major);
return 0; return 0;
} }
......
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