aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarod Wilson <jarod@redhat.com>2010-10-18 11:02:01 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-10-22 18:05:36 -0400
commit715d29a74450696696dc064f85ba4ff0eaadb1d2 (patch)
tree0d6541aec78b66df59ceee6afbd17460140d1e36
parentd889a135cb832c77b7f90a89b40090e4e9ba609b (diff)
[media] lirc_dev: more error-checking improvements
Signed-off-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/IR/lirc_dev.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/IR/lirc_dev.c
index 3eea3736711e..e3dbf12d00d9 100644
--- a/drivers/media/IR/lirc_dev.c
+++ b/drivers/media/IR/lirc_dev.c
@@ -74,8 +74,6 @@ static struct class *lirc_class;
74 */ 74 */
75static void lirc_irctl_init(struct irctl *ir) 75static void lirc_irctl_init(struct irctl *ir)
76{ 76{
77 dev_dbg(ir->d.dev, LOGHEAD "initializing irctl\n",
78 ir->d.name, ir->d.minor);
79 mutex_init(&ir->irctl_lock); 77 mutex_init(&ir->irctl_lock);
80 ir->d.minor = NOPLUG; 78 ir->d.minor = NOPLUG;
81} 79}
@@ -205,6 +203,12 @@ int lirc_register_driver(struct lirc_driver *d)
205 goto out; 203 goto out;
206 } 204 }
207 205
206 if (!d->dev) {
207 printk(KERN_ERR "%s: dev pointer not filled in!\n", __func__);
208 err = -EINVAL;
209 goto out;
210 }
211
208 if (MAX_IRCTL_DEVICES <= d->minor) { 212 if (MAX_IRCTL_DEVICES <= d->minor) {
209 dev_err(d->dev, "lirc_dev: lirc_register_driver: " 213 dev_err(d->dev, "lirc_dev: lirc_register_driver: "
210 "\"minor\" must be between 0 and %d (%d)!\n", 214 "\"minor\" must be between 0 and %d (%d)!\n",
@@ -319,7 +323,6 @@ int lirc_register_driver(struct lirc_driver *d)
319 d->features = LIRC_CAN_REC_LIRCCODE; 323 d->features = LIRC_CAN_REC_LIRCCODE;
320 324
321 ir->d = *d; 325 ir->d = *d;
322 ir->d.minor = minor;
323 326
324 device_create(lirc_class, ir->d.dev, 327 device_create(lirc_class, ir->d.dev,
325 MKDEV(MAJOR(lirc_base_dev), ir->d.minor), NULL, 328 MKDEV(MAJOR(lirc_base_dev), ir->d.minor), NULL,
@@ -474,11 +477,16 @@ int lirc_dev_fop_close(struct inode *inode, struct file *file)
474{ 477{
475 struct irctl *ir = irctls[iminor(inode)]; 478 struct irctl *ir = irctls[iminor(inode)];
476 479
480 if (!ir) {
481 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
482 return -EINVAL;
483 }
484
477 dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor); 485 dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor);
478 486
479 WARN_ON(mutex_lock_killable(&lirc_dev_lock)); 487 WARN_ON(mutex_lock_killable(&lirc_dev_lock));
480 488
481 --ir->open; 489 ir->open--;
482 if (ir->attached) { 490 if (ir->attached) {
483 ir->d.set_use_dec(ir->d.data); 491 ir->d.set_use_dec(ir->d.data);
484 module_put(ir->cdev.owner); 492 module_put(ir->cdev.owner);
@@ -499,6 +507,11 @@ unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait)
499 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; 507 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
500 unsigned int ret; 508 unsigned int ret;
501 509
510 if (!ir) {
511 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
512 return POLLERR;
513 }
514
502 dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor); 515 dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor);
503 516
504 if (!ir->attached) { 517 if (!ir->attached) {
@@ -613,12 +626,21 @@ ssize_t lirc_dev_fop_read(struct file *file,
613 loff_t *ppos) 626 loff_t *ppos)
614{ 627{
615 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; 628 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
616 unsigned char buf[ir->chunk_size]; 629 unsigned char *buf;
617 int ret = 0, written = 0; 630 int ret = 0, written = 0;
618 DECLARE_WAITQUEUE(wait, current); 631 DECLARE_WAITQUEUE(wait, current);
619 632
633 if (!ir) {
634 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
635 return -ENODEV;
636 }
637
620 dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor); 638 dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor);
621 639
640 buf = kzalloc(ir->chunk_size, GFP_KERNEL);
641 if (!buf)
642 return -ENOMEM;
643
622 if (mutex_lock_interruptible(&ir->irctl_lock)) 644 if (mutex_lock_interruptible(&ir->irctl_lock))
623 return -ERESTARTSYS; 645 return -ERESTARTSYS;
624 if (!ir->attached) { 646 if (!ir->attached) {
@@ -690,6 +712,7 @@ ssize_t lirc_dev_fop_read(struct file *file,
690 mutex_unlock(&ir->irctl_lock); 712 mutex_unlock(&ir->irctl_lock);
691 713
692out_unlocked: 714out_unlocked:
715 kfree(buf);
693 dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n", 716 dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n",
694 ir->d.name, ir->d.minor, ret ? "-EFAULT" : "OK", ret); 717 ir->d.name, ir->d.minor, ret ? "-EFAULT" : "OK", ret);
695 718
@@ -718,6 +741,11 @@ ssize_t lirc_dev_fop_write(struct file *file, const char *buffer,
718{ 741{
719 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; 742 struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)];
720 743
744 if (!ir) {
745 printk(KERN_ERR "%s: called with invalid irctl\n", __func__);
746 return -ENODEV;
747 }
748
721 dev_dbg(ir->d.dev, LOGHEAD "write called\n", ir->d.name, ir->d.minor); 749 dev_dbg(ir->d.dev, LOGHEAD "write called\n", ir->d.name, ir->d.minor);
722 750
723 if (!ir->attached) 751 if (!ir->attached)