diff options
Diffstat (limited to 'drivers/media/rc/lirc_dev.c')
-rw-r--r-- | drivers/media/rc/lirc_dev.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index fd237ab120bb..27997a9ceb0d 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c | |||
@@ -55,6 +55,8 @@ struct irctl { | |||
55 | struct lirc_buffer *buf; | 55 | struct lirc_buffer *buf; |
56 | unsigned int chunk_size; | 56 | unsigned int chunk_size; |
57 | 57 | ||
58 | struct cdev *cdev; | ||
59 | |||
58 | struct task_struct *task; | 60 | struct task_struct *task; |
59 | long jiffies_to_wait; | 61 | long jiffies_to_wait; |
60 | }; | 62 | }; |
@@ -62,7 +64,6 @@ struct irctl { | |||
62 | static DEFINE_MUTEX(lirc_dev_lock); | 64 | static DEFINE_MUTEX(lirc_dev_lock); |
63 | 65 | ||
64 | static struct irctl *irctls[MAX_IRCTL_DEVICES]; | 66 | static struct irctl *irctls[MAX_IRCTL_DEVICES]; |
65 | static struct cdev cdevs[MAX_IRCTL_DEVICES]; | ||
66 | 67 | ||
67 | /* Only used for sysfs but defined to void otherwise */ | 68 | /* Only used for sysfs but defined to void otherwise */ |
68 | static struct class *lirc_class; | 69 | static struct class *lirc_class; |
@@ -167,9 +168,13 @@ static struct file_operations lirc_dev_fops = { | |||
167 | 168 | ||
168 | static int lirc_cdev_add(struct irctl *ir) | 169 | static int lirc_cdev_add(struct irctl *ir) |
169 | { | 170 | { |
170 | int retval; | 171 | int retval = -ENOMEM; |
171 | struct lirc_driver *d = &ir->d; | 172 | struct lirc_driver *d = &ir->d; |
172 | struct cdev *cdev = &cdevs[d->minor]; | 173 | struct cdev *cdev; |
174 | |||
175 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); | ||
176 | if (!cdev) | ||
177 | goto err_out; | ||
173 | 178 | ||
174 | if (d->fops) { | 179 | if (d->fops) { |
175 | cdev_init(cdev, d->fops); | 180 | cdev_init(cdev, d->fops); |
@@ -180,12 +185,20 @@ static int lirc_cdev_add(struct irctl *ir) | |||
180 | } | 185 | } |
181 | retval = kobject_set_name(&cdev->kobj, "lirc%d", d->minor); | 186 | retval = kobject_set_name(&cdev->kobj, "lirc%d", d->minor); |
182 | if (retval) | 187 | if (retval) |
183 | return retval; | 188 | goto err_out; |
184 | 189 | ||
185 | retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); | 190 | retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); |
186 | if (retval) | 191 | if (retval) { |
187 | kobject_put(&cdev->kobj); | 192 | kobject_put(&cdev->kobj); |
193 | goto err_out; | ||
194 | } | ||
195 | |||
196 | ir->cdev = cdev; | ||
197 | |||
198 | return 0; | ||
188 | 199 | ||
200 | err_out: | ||
201 | kfree(cdev); | ||
189 | return retval; | 202 | return retval; |
190 | } | 203 | } |
191 | 204 | ||
@@ -214,7 +227,7 @@ int lirc_register_driver(struct lirc_driver *d) | |||
214 | if (MAX_IRCTL_DEVICES <= d->minor) { | 227 | if (MAX_IRCTL_DEVICES <= d->minor) { |
215 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " | 228 | dev_err(d->dev, "lirc_dev: lirc_register_driver: " |
216 | "\"minor\" must be between 0 and %d (%d)!\n", | 229 | "\"minor\" must be between 0 and %d (%d)!\n", |
217 | MAX_IRCTL_DEVICES-1, d->minor); | 230 | MAX_IRCTL_DEVICES - 1, d->minor); |
218 | err = -EBADRQC; | 231 | err = -EBADRQC; |
219 | goto out; | 232 | goto out; |
220 | } | 233 | } |
@@ -369,7 +382,7 @@ int lirc_unregister_driver(int minor) | |||
369 | 382 | ||
370 | if (minor < 0 || minor >= MAX_IRCTL_DEVICES) { | 383 | if (minor < 0 || minor >= MAX_IRCTL_DEVICES) { |
371 | printk(KERN_ERR "lirc_dev: %s: minor (%d) must be between " | 384 | printk(KERN_ERR "lirc_dev: %s: minor (%d) must be between " |
372 | "0 and %d!\n", __func__, minor, MAX_IRCTL_DEVICES-1); | 385 | "0 and %d!\n", __func__, minor, MAX_IRCTL_DEVICES - 1); |
373 | return -EBADRQC; | 386 | return -EBADRQC; |
374 | } | 387 | } |
375 | 388 | ||
@@ -380,7 +393,7 @@ int lirc_unregister_driver(int minor) | |||
380 | return -ENOENT; | 393 | return -ENOENT; |
381 | } | 394 | } |
382 | 395 | ||
383 | cdev = &cdevs[minor]; | 396 | cdev = ir->cdev; |
384 | 397 | ||
385 | mutex_lock(&lirc_dev_lock); | 398 | mutex_lock(&lirc_dev_lock); |
386 | 399 | ||
@@ -410,6 +423,7 @@ int lirc_unregister_driver(int minor) | |||
410 | } else { | 423 | } else { |
411 | lirc_irctl_cleanup(ir); | 424 | lirc_irctl_cleanup(ir); |
412 | cdev_del(cdev); | 425 | cdev_del(cdev); |
426 | kfree(cdev); | ||
413 | kfree(ir); | 427 | kfree(ir); |
414 | irctls[minor] = NULL; | 428 | irctls[minor] = NULL; |
415 | } | 429 | } |
@@ -453,7 +467,7 @@ int lirc_dev_fop_open(struct inode *inode, struct file *file) | |||
453 | goto error; | 467 | goto error; |
454 | } | 468 | } |
455 | 469 | ||
456 | cdev = &cdevs[iminor(inode)]; | 470 | cdev = ir->cdev; |
457 | if (try_module_get(cdev->owner)) { | 471 | if (try_module_get(cdev->owner)) { |
458 | ir->open++; | 472 | ir->open++; |
459 | retval = ir->d.set_use_inc(ir->d.data); | 473 | retval = ir->d.set_use_inc(ir->d.data); |
@@ -484,13 +498,15 @@ EXPORT_SYMBOL(lirc_dev_fop_open); | |||
484 | int lirc_dev_fop_close(struct inode *inode, struct file *file) | 498 | int lirc_dev_fop_close(struct inode *inode, struct file *file) |
485 | { | 499 | { |
486 | struct irctl *ir = irctls[iminor(inode)]; | 500 | struct irctl *ir = irctls[iminor(inode)]; |
487 | struct cdev *cdev = &cdevs[iminor(inode)]; | 501 | struct cdev *cdev; |
488 | 502 | ||
489 | if (!ir) { | 503 | if (!ir) { |
490 | printk(KERN_ERR "%s: called with invalid irctl\n", __func__); | 504 | printk(KERN_ERR "%s: called with invalid irctl\n", __func__); |
491 | return -EINVAL; | 505 | return -EINVAL; |
492 | } | 506 | } |
493 | 507 | ||
508 | cdev = ir->cdev; | ||
509 | |||
494 | dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor); | 510 | dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor); |
495 | 511 | ||
496 | WARN_ON(mutex_lock_killable(&lirc_dev_lock)); | 512 | WARN_ON(mutex_lock_killable(&lirc_dev_lock)); |
@@ -503,6 +519,7 @@ int lirc_dev_fop_close(struct inode *inode, struct file *file) | |||
503 | lirc_irctl_cleanup(ir); | 519 | lirc_irctl_cleanup(ir); |
504 | cdev_del(cdev); | 520 | cdev_del(cdev); |
505 | irctls[ir->d.minor] = NULL; | 521 | irctls[ir->d.minor] = NULL; |
522 | kfree(cdev); | ||
506 | kfree(ir); | 523 | kfree(ir); |
507 | } | 524 | } |
508 | 525 | ||