| @@ -20,38 +20,29 @@ · 19 unmodified lines |
| 20 | #define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver" | 20 | #define BSG_DESCRIPTION "Block layer SCSI generic (bsg) driver" |
| 21 | #define BSG_VERSION "0.4" | 21 | #define BSG_VERSION "0.4" |
| 22 | | 22 | |
| 23 | #define bsg_dbg(bd, fmt, ...) \ | | |
| 24 | pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__) | | |
| 25 | | | |
| 26 | struct bsg_device { | 23 | struct bsg_device { |
| 27 | struct request_queue *queue; | 24 | struct request_queue *queue; |
| 28 | spinlock_t lock; | 25 | const struct bsg_ops *ops; |
| 29 | struct hlist_node dev_list; | 26 | struct device device; |
| 30 | refcount_t ref_count; | 27 | struct cdev cdev; |
| 31 | char name[20]; | | |
| 32 | int max_queue; | 28 | int max_queue; |
| 33 | }; | 29 | }; |
| 34 | | 30 | |
| | 31 | static inline struct bsg_device *to_bsg_device(struct inode *inode) |
| | 32 | { |
| | 33 | return container_of(inode->i_cdev, struct bsg_device, cdev); |
| | 34 | } |
| | 35 | |
| 35 | #define BSG_DEFAULT_CMDS 64 | 36 | #define BSG_DEFAULT_CMDS 64 |
| 36 | #define BSG_MAX_DEVS 32768 | 37 | #define BSG_MAX_DEVS 32768 |
| 37 | | 38 | |
| 38 | static DEFINE_MUTEX(bsg_mutex); | 39 | static DEFINE_IDA(bsg_minor_ida); |
| 39 | static DEFINE_IDR(bsg_minor_idr); | | |
| 40 | | | |
| 41 | #define BSG_LIST_ARRAY_SIZE 8 | | |
| 42 | static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE]; | | |
| 43 | | | |
| 44 | static struct class *bsg_class; | 40 | static struct class *bsg_class; |
| 45 | static int bsg_major; | 41 | static int bsg_major; |
| 46 | | 42 | |
| 47 | static inline struct hlist_head *bsg_dev_idx_hash(int index) | | |
| 48 | { | | |
| 49 | return &bsg_device_list[index & (BSG_LIST_ARRAY_SIZE - 1)]; | | |
| 50 | } | | |
| 51 | | | |
| 52 | #define uptr64(val) ((void __user *)(uintptr_t)(val)) | 43 | #define uptr64(val) ((void __user *)(uintptr_t)(val)) |
| 53 | | 44 | |
| 54 | static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) | 45 | static int bsg_sg_io(struct bsg_device *bd, fmode_t mode, void __user *uarg) |
| 55 | { | 46 | { |
| 56 | struct request *rq; | 47 | struct request *rq; |
| 57 | struct bio *bio; | 48 | struct bio *bio; |
| @@ -61,21 +52,18 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 3 unmodified lines |
| 61 | if (copy_from_user(&hdr, uarg, sizeof(hdr))) | 52 | if (copy_from_user(&hdr, uarg, sizeof(hdr))) |
| 62 | return -EFAULT; | 53 | return -EFAULT; |
| 63 | | 54 | |
| 64 | if (!q->bsg_dev.class_dev) | | |
| 65 | return -ENXIO; | | |
| 66 | | | |
| 67 | if (hdr.guard != 'Q') | 55 | if (hdr.guard != 'Q') |
| 68 | return -EINVAL; | 56 | return -EINVAL; |
| 69 | ret = q->bsg_dev.ops->check_proto(&hdr); | 57 | ret = bd->ops->check_proto(&hdr); |
| 70 | if (ret) | 58 | if (ret) |
| 71 | return ret; | 59 | return ret; |
| 72 | | 60 | |
| 73 | rq = blk_get_request(q, hdr.dout_xfer_len ? | 61 | rq = blk_get_request(bd->queue, hdr.dout_xfer_len ? |
| 74 | REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0); | 62 | REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0); |
| 75 | if (IS_ERR(rq)) | 63 | if (IS_ERR(rq)) |
| 76 | return PTR_ERR(rq); | 64 | return PTR_ERR(rq); |
| 77 | | 65 | |
| 78 | ret = q->bsg_dev.ops->fill_hdr(rq, &hdr, mode); | 66 | ret = bd->ops->fill_hdr(rq, &hdr, mode); |
| 79 | if (ret) { | 67 | if (ret) { |
| 80 | blk_put_request(rq); | 68 | blk_put_request(rq); |
| 81 | return ret; | 69 | return ret; |
| @@ -83,17 +71,17 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 1 unmodified line |
| 83 | | 71 | |
| 84 | rq->timeout = msecs_to_jiffies(hdr.timeout); | 72 | rq->timeout = msecs_to_jiffies(hdr.timeout); |
| 85 | if (!rq->timeout) | 73 | if (!rq->timeout) |
| 86 | rq->timeout = q->sg_timeout; | 74 | rq->timeout = rq->q->sg_timeout; |
| 87 | if (!rq->timeout) | 75 | if (!rq->timeout) |
| 88 | rq->timeout = BLK_DEFAULT_SG_TIMEOUT; | 76 | rq->timeout = BLK_DEFAULT_SG_TIMEOUT; |
| 89 | if (rq->timeout < BLK_MIN_SG_TIMEOUT) | 77 | if (rq->timeout < BLK_MIN_SG_TIMEOUT) |
| 90 | rq->timeout = BLK_MIN_SG_TIMEOUT; | 78 | rq->timeout = BLK_MIN_SG_TIMEOUT; |
| 91 | | 79 | |
| 92 | if (hdr.dout_xfer_len) { | 80 | if (hdr.dout_xfer_len) { |
| 93 | ret = blk_rq_map_user(q, rq, NULL, uptr64(hdr.dout_xferp), | 81 | ret = blk_rq_map_user(rq->q, rq, NULL, uptr64(hdr.dout_xferp), |
| 94 | hdr.dout_xfer_len, GFP_KERNEL); | 82 | hdr.dout_xfer_len, GFP_KERNEL); |
| 95 | } else if (hdr.din_xfer_len) { | 83 | } else if (hdr.din_xfer_len) { |
| 96 | ret = blk_rq_map_user(q, rq, NULL, uptr64(hdr.din_xferp), | 84 | ret = blk_rq_map_user(rq->q, rq, NULL, uptr64(hdr.din_xferp), |
| 97 | hdr.din_xfer_len, GFP_KERNEL); | 85 | hdr.din_xfer_len, GFP_KERNEL); |
| 98 | } | 86 | } |
| 99 | | 87 | |
| @@ -103,171 +91,50 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, void __user *uarg) · 3 unmodified lines |
| 103 | bio = rq->bio; | 91 | bio = rq->bio; |
| 104 | | 92 | |
| 105 | blk_execute_rq(NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL)); | 93 | blk_execute_rq(NULL, rq, !(hdr.flags & BSG_FLAG_Q_AT_TAIL)); |
| 106 | ret = rq->q->bsg_dev.ops->complete_rq(rq, &hdr); | 94 | ret = bd->ops->complete_rq(rq, &hdr); |
| 107 | blk_rq_unmap_user(bio); | 95 | blk_rq_unmap_user(bio); |
| 108 | | 96 | |
| 109 | out_free_rq: | 97 | out_free_rq: |
| 110 | rq->q->bsg_dev.ops->free_rq(rq); | 98 | bd->ops->free_rq(rq); |
| 111 | blk_put_request(rq); | 99 | blk_put_request(rq); |
| 112 | if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr))) | 100 | if (!ret && copy_to_user(uarg, &hdr, sizeof(hdr))) |
| 113 | return -EFAULT; | 101 | return -EFAULT; |
| 114 | return ret; | 102 | return ret; |
| 115 | } | 103 | } |
| 116 | | 104 | |
| 117 | static struct bsg_device *bsg_alloc_device(void) | | |
| 118 | { | | |
| 119 | struct bsg_device *bd; | | |
| 120 | | | |
| 121 | bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL); | | |
| 122 | if (unlikely(!bd)) | | |
| 123 | return NULL; | | |
| 124 | | | |
| 125 | spin_lock_init(&bd->lock); | | |
| 126 | bd->max_queue = BSG_DEFAULT_CMDS; | | |
| 127 | INIT_HLIST_NODE(&bd->dev_list); | | |
| 128 | return bd; | | |
| 129 | } | | |
| 130 | | | |
| 131 | static int bsg_put_device(struct bsg_device *bd) | | |
| 132 | { | | |
| 133 | struct request_queue *q = bd->queue; | | |
| 134 | | | |
| 135 | mutex_lock(&bsg_mutex); | | |
| 136 | | | |
| 137 | if (!refcount_dec_and_test(&bd->ref_count)) { | | |
| 138 | mutex_unlock(&bsg_mutex); | | |
| 139 | return 0; | | |
| 140 | } | | |
| 141 | | | |
| 142 | hlist_del(&bd->dev_list); | | |
| 143 | mutex_unlock(&bsg_mutex); | | |
| 144 | | | |
| 145 | bsg_dbg(bd, "tearing down\n"); | | |
| 146 | | | |
| 147 | /* | | |
| 148 | * close can always block | | |
| 149 | */ | | |
| 150 | kfree(bd); | | |
| 151 | blk_put_queue(q); | | |
| 152 | return 0; | | |
| 153 | } | | |
| 154 | | | |
| 155 | static struct bsg_device *bsg_add_device(struct inode *inode, | | |
| 156 | struct request_queue *rq, | | |
| 157 | struct file *file) | | |
| 158 | { | | |
| 159 | struct bsg_device *bd; | | |
| 160 | unsigned char buf[32]; | | |
| 161 | | | |
| 162 | lockdep_assert_held(&bsg_mutex); | | |
| 163 | | | |
| 164 | if (!blk_get_queue(rq)) | | |
| 165 | return ERR_PTR(-ENXIO); | | |
| 166 | | | |
| 167 | bd = bsg_alloc_device(); | | |
| 168 | if (!bd) { | | |
| 169 | blk_put_queue(rq); | | |
| 170 | return ERR_PTR(-ENOMEM); | | |
| 171 | } | | |
| 172 | | | |
| 173 | bd->queue = rq; | | |
| 174 | | | |
| 175 | refcount_set(&bd->ref_count, 1); | | |
| 176 | hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); | | |
| 177 | | | |
| 178 | strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); | | |
| 179 | bsg_dbg(bd, "bound to <%s>, max queue %d\n", | | |
| 180 | format_dev_t(buf, inode->i_rdev), bd->max_queue); | | |
| 181 | | | |
| 182 | return bd; | | |
| 183 | } | | |
| 184 | | | |
| 185 | static struct bsg_device *__bsg_get_device(int minor, struct request_queue *q) | | |
| 186 | { | | |
| 187 | struct bsg_device *bd; | | |
| 188 | | | |
| 189 | lockdep_assert_held(&bsg_mutex); | | |
| 190 | | | |
| 191 | hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { | | |
| 192 | if (bd->queue == q) { | | |
| 193 | refcount_inc(&bd->ref_count); | | |
| 194 | goto found; | | |
| 195 | } | | |
| 196 | } | | |
| 197 | bd = NULL; | | |
| 198 | found: | | |
| 199 | return bd; | | |
| 200 | } | | |
| 201 | | | |
| 202 | static struct bsg_device *bsg_get_device(struct inode *inode, struct file *file) | | |
| 203 | { | | |
| 204 | struct bsg_device *bd; | | |
| 205 | struct bsg_class_device *bcd; | | |
| 206 | | | |
| 207 | /* | | |
| 208 | * find the class device | | |
| 209 | */ | | |
| 210 | mutex_lock(&bsg_mutex); | | |
| 211 | bcd = idr_find(&bsg_minor_idr, iminor(inode)); | | |
| 212 | | | |
| 213 | if (!bcd) { | | |
| 214 | bd = ERR_PTR(-ENODEV); | | |
| 215 | goto out_unlock; | | |
| 216 | } | | |
| 217 | | | |
| 218 | bd = __bsg_get_device(iminor(inode), bcd->queue); | | |
| 219 | if (!bd) | | |
| 220 | bd = bsg_add_device(inode, bcd->queue, file); | | |
| 221 | | | |
| 222 | out_unlock: | | |
| 223 | mutex_unlock(&bsg_mutex); | | |
| 224 | return bd; | | |
| 225 | } | | |
| 226 | | | |
| 227 | static int bsg_open(struct inode *inode, struct file *file) | 105 | static int bsg_open(struct inode *inode, struct file *file) |
| 228 | { | 106 | { |
| 229 | struct bsg_device *bd; | 107 | if (!blk_get_queue(to_bsg_device(inode)->queue)) |
| 230 | | 108 | return -ENXIO; |
| 231 | bd = bsg_get_device(inode, file); | | |
| 232 | | | |
| 233 | if (IS_ERR(bd)) | | |
| 234 | return PTR_ERR(bd); | | |
| 235 | | | |
| 236 | file->private_data = bd; | | |
| 237 | return 0; | 109 | return 0; |
| 238 | } | 110 | } |
| 239 | | 111 | |
| 240 | static int bsg_release(struct inode *inode, struct file *file) | 112 | static int bsg_release(struct inode *inode, struct file *file) |
| 241 | { | 113 | { |
| 242 | struct bsg_device *bd = file->private_data; | 114 | blk_put_queue(to_bsg_device(inode)->queue); |
| 243 | | 115 | return 0; |
| 244 | file->private_data = NULL; | | |
| 245 | return bsg_put_device(bd); | | |
| 246 | } | 116 | } |
| 247 | | 117 | |
| 248 | static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg) | 118 | static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg) |
| 249 | { | 119 | { |
| 250 | return put_user(bd->max_queue, uarg); | 120 | return put_user(READ_ONCE(bd->max_queue), uarg); |
| 251 | } | 121 | } |
| 252 | | 122 | |
| 253 | static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg) | 123 | static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg) |
| 254 | { | 124 | { |
| 255 | int queue; | 125 | int max_queue; |
| 256 | | 126 | |
| 257 | if (get_user(queue, uarg)) | 127 | if (get_user(max_queue, uarg)) |
| 258 | return -EFAULT; | 128 | return -EFAULT; |
| 259 | if (queue < 1) | 129 | if (max_queue < 1) |
| 260 | return -EINVAL; | 130 | return -EINVAL; |
| 261 | | 131 | WRITE_ONCE(bd->max_queue, max_queue); |
| 262 | spin_lock_irq(&bd->lock); | | |
| 263 | bd->max_queue = queue; | | |
| 264 | spin_unlock_irq(&bd->lock); | | |
| 265 | return 0; | 132 | return 0; |
| 266 | } | 133 | } |
| 267 | | 134 | |
| 268 | static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 135 | static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 269 | { | 136 | { |
| 270 | struct bsg_device *bd = file->private_data; | 137 | struct bsg_device *bd = to_bsg_device(file_inode(file)); |
| 271 | struct request_queue *q = bd->queue; | 138 | struct request_queue *q = bd->queue; |
| 272 | void __user *uarg = (void __user *) arg; | 139 | void __user *uarg = (void __user *) arg; |
| 273 | int __user *intp = uarg; | 140 | int __user *intp = uarg; |
| @@ -312,7 +179,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · 38 unmodified lines |
| 312 | case SG_EMULATED_HOST: | 179 | case SG_EMULATED_HOST: |
| 313 | return put_user(1, intp); | 180 | return put_user(1, intp); |
| 314 | case SG_IO: | 181 | case SG_IO: |
| 315 | return bsg_sg_io(q, file->f_mode, uarg); | 182 | return bsg_sg_io(bd, file->f_mode, uarg); |
| 316 | case SCSI_IOCTL_SEND_COMMAND: | 183 | case SCSI_IOCTL_SEND_COMMAND: |
| 317 | pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n", | 184 | pr_warn_ratelimited("%s: calling unsupported SCSI_IOCTL_SEND_COMMAND\n", |
| 318 | current->comm); | 185 | current->comm); |
| @@ -331,83 +198,66 @@ static const struct file_operations bsg_fops = { · 12 unmodified lines |
| 331 | .llseek = default_llseek, | 198 | .llseek = default_llseek, |
| 332 | }; | 199 | }; |
| 333 | | 200 | |
| 334 | void bsg_unregister_queue(struct request_queue *q) | 201 | void bsg_unregister_queue(struct bsg_device *bd) |
| 335 | { | 202 | { |
| 336 | struct bsg_class_device *bcd = &q->bsg_dev; | 203 | if (bd->queue->kobj.sd) |
| 337 | | 204 | sysfs_remove_link(&bd->queue->kobj, "bsg"); |
| 338 | if (!bcd->class_dev) | 205 | cdev_device_del(&bd->cdev, &bd->device); |
| 339 | return; | 206 | ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt)); |
| 340 | | 207 | kfree(bd); |
| 341 | mutex_lock(&bsg_mutex); | | |
| 342 | idr_remove(&bsg_minor_idr, bcd->minor); | | |
| 343 | if (q->kobj.sd) | | |
| 344 | sysfs_remove_link(&q->kobj, "bsg"); | | |
| 345 | device_unregister(bcd->class_dev); | | |
| 346 | bcd->class_dev = NULL; | | |
| 347 | mutex_unlock(&bsg_mutex); | | |
| 348 | } | 208 | } |
| 349 | EXPORT_SYMBOL_GPL(bsg_unregister_queue); | 209 | EXPORT_SYMBOL_GPL(bsg_unregister_queue); |
| 350 | | 210 | |
| 351 | int bsg_register_queue(struct request_queue *q, struct device *parent, | 211 | struct bsg_device *bsg_register_queue(struct request_queue *q, |
| 352 | const char *name, const struct bsg_ops *ops) | 212 | struct device *parent, const char *name, |
| | 213 | const struct bsg_ops *ops) |
| 353 | { | 214 | { |
| 354 | struct bsg_class_device *bcd; | 215 | struct bsg_device *bd; |
| 355 | dev_t dev; | | |
| 356 | int ret; | 216 | int ret; |
| 357 | struct device *class_dev = NULL; | | |
| 358 | | | |
| 359 | /* | | |
| 360 | * we need a proper transport to send commands, not a stacked device | | |
| 361 | */ | | |
| 362 | if (!queue_is_mq(q)) | | |
| 363 | return 0; | | |
| 364 | | 217 | |
| 365 | bcd = &q->bsg_dev; | 218 | bd = kzalloc(sizeof(*bd), GFP_KERNEL); |
| 366 | memset(bcd, 0, sizeof(*bcd)); | 219 | if (!bd) |
| 367 | | 220 | return ERR_PTR(-ENOMEM); |
| 368 | mutex_lock(&bsg_mutex); | 221 | bd->max_queue = BSG_DEFAULT_CMDS; |
| | 222 | bd->queue = q; |
| | 223 | bd->ops = ops; |
| 369 | | 224 | |
| 370 | ret = idr_alloc(&bsg_minor_idr, bcd, 0, BSG_MAX_DEVS, GFP_KERNEL); | 225 | ret = ida_simple_get(&bsg_minor_ida, 0, BSG_MAX_DEVS, GFP_KERNEL); |
| 371 | if (ret < 0) { | 226 | if (ret < 0) { |
| 372 | if (ret == -ENOSPC) { | 227 | if (ret == -ENOSPC) |
| 373 | printk(KERN_ERR "bsg: too many bsg devices\n"); | 228 | dev_err(parent, "bsg: too many bsg devices\n"); |
| 374 | ret = -EINVAL; | 229 | goto out_kfree; |
| 375 | } | | |
| 376 | goto unlock; | | |
| 377 | } | | |
| 378 | | | |
| 379 | bcd->minor = ret; | | |
| 380 | bcd->queue = q; | | |
| 381 | bcd->ops = ops; | | |
| 382 | dev = MKDEV(bsg_major, bcd->minor); | | |
| 383 | class_dev = device_create(bsg_class, parent, dev, NULL, "%s", name); | | |
| 384 | if (IS_ERR(class_dev)) { | | |
| 385 | ret = PTR_ERR(class_dev); | | |
| 386 | goto idr_remove; | | |
| 387 | } | 230 | } |
| 388 | bcd->class_dev = class_dev; | 231 | bd->device.devt = MKDEV(bsg_major, ret); |
| | 232 | bd->device.class = bsg_class; |
| | 233 | bd->device.parent = parent; |
| | 234 | dev_set_name(&bd->device, "%s", name); |
| | 235 | device_initialize(&bd->device); |
| | 236 | |
| | 237 | cdev_init(&bd->cdev, &bsg_fops); |
| | 238 | bd->cdev.owner = THIS_MODULE; |
| | 239 | ret = cdev_device_add(&bd->cdev, &bd->device); |
| | 240 | if (ret) |
| | 241 | goto out_ida_remove; |
| 389 | | 242 | |
| 390 | if (q->kobj.sd) { | 243 | if (q->kobj.sd) { |
| 391 | ret = sysfs_create_link(&q->kobj, &bcd->class_dev->kobj, "bsg"); | 244 | ret = sysfs_create_link(&q->kobj, &bd->device.kobj, "bsg"); |
| 392 | if (ret) | 245 | if (ret) |
| 393 | goto unregister_class_dev; | 246 | goto out_device_del; |
| 394 | } | 247 | } |
| 395 | | 248 | |
| 396 | mutex_unlock(&bsg_mutex); | 249 | return bd; |
| 397 | return 0; | | |
| 398 | | 250 | |
| 399 | unregister_class_dev: | 251 | out_device_del: |
| 400 | device_unregister(class_dev); | 252 | cdev_device_del(&bd->cdev, &bd->device); |
| 401 | idr_remove: | 253 | out_ida_remove: |
| 402 | idr_remove(&bsg_minor_idr, bcd->minor); | 254 | ida_simple_remove(&bsg_minor_ida, MINOR(bd->device.devt)); |
| 403 | unlock: | 255 | out_kfree: |
| 404 | mutex_unlock(&bsg_mutex); | 256 | kfree(bd); |
| 405 | return ret; | 257 | return ERR_PTR(ret); |
| 406 | } | 258 | } |
| 407 | EXPORT_SYMBOL_GPL(bsg_register_queue); | 259 | EXPORT_SYMBOL_GPL(bsg_register_queue); |
| 408 | | 260 | |
| 409 | static struct cdev bsg_cdev; | | |
| 410 | | | |
| 411 | static char *bsg_devnode(struct device *dev, umode_t *mode) | 261 | static char *bsg_devnode(struct device *dev, umode_t *mode) |
| 412 | { | 262 | { |
| 413 | return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev)); | 263 | return kasprintf(GFP_KERNEL, "bsg/%s", dev_name(dev)); |
| @@ -415,11 +265,8 @@ static char *bsg_devnode(struct device *dev, umode_t *mode) · 1 unmodified line |
| 415 | | 265 | |
| 416 | static int __init bsg_init(void) | 266 | static int __init bsg_init(void) |
| 417 | { | 267 | { |
| 418 | int ret, i; | | |
| 419 | dev_t devid; | 268 | dev_t devid; |
| 420 | | 269 | int ret; |
| 421 | for (i = 0; i < BSG_LIST_ARRAY_SIZE; i++) | | |
| 422 | INIT_HLIST_HEAD(&bsg_device_list[i]); | | |
| 423 | | 270 | |
| 424 | bsg_class = class_create(THIS_MODULE, "bsg"); | 271 | bsg_class = class_create(THIS_MODULE, "bsg"); |
| 425 | if (IS_ERR(bsg_class)) | 272 | if (IS_ERR(bsg_class)) |
| @@ -429,19 +276,12 @@ static int __init bsg_init(void) · 3 unmodified lines |
| 429 | ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg"); | 276 | ret = alloc_chrdev_region(&devid, 0, BSG_MAX_DEVS, "bsg"); |
| 430 | if (ret) | 277 | if (ret) |
| 431 | goto destroy_bsg_class; | 278 | goto destroy_bsg_class; |
| 432 | | | |
| 433 | bsg_major = MAJOR(devid); | 279 | bsg_major = MAJOR(devid); |
| 434 | | 280 | |
| 435 | cdev_init(&bsg_cdev, &bsg_fops); | | |
| 436 | ret = cdev_add(&bsg_cdev, MKDEV(bsg_major, 0), BSG_MAX_DEVS); | | |
| 437 | if (ret) | | |
| 438 | goto unregister_chrdev; | | |
| 439 | | | |
| 440 | printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION | 281 | printk(KERN_INFO BSG_DESCRIPTION " version " BSG_VERSION |
| 441 | " loaded (major %d)\n", bsg_major); | 282 | " loaded (major %d)\n", bsg_major); |
| 442 | return 0; | 283 | return 0; |
| 443 | unregister_chrdev: | 284 | |
| 444 | unregister_chrdev_region(MKDEV(bsg_major, 0), BSG_MAX_DEVS); | | |
| 445 | destroy_bsg_class: | 285 | destroy_bsg_class: |
| 446 | class_destroy(bsg_class); | 286 | class_destroy(bsg_class); |
| 447 | return ret; | 287 | return ret; |