diff options
Diffstat (limited to 'drivers/media/IR/lirc_dev.c')
-rw-r--r-- | drivers/media/IR/lirc_dev.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/IR/lirc_dev.c index 8418b14ee4d2..756656e17bdd 100644 --- a/drivers/media/IR/lirc_dev.c +++ b/drivers/media/IR/lirc_dev.c | |||
@@ -522,10 +522,8 @@ unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait) | |||
522 | 522 | ||
523 | dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor); | 523 | dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor); |
524 | 524 | ||
525 | if (!ir->attached) { | 525 | if (!ir->attached) |
526 | mutex_unlock(&ir->irctl_lock); | ||
527 | return POLLERR; | 526 | return POLLERR; |
528 | } | ||
529 | 527 | ||
530 | poll_wait(file, &ir->buf->wait_poll, wait); | 528 | poll_wait(file, &ir->buf->wait_poll, wait); |
531 | 529 | ||
@@ -649,18 +647,18 @@ ssize_t lirc_dev_fop_read(struct file *file, | |||
649 | if (!buf) | 647 | if (!buf) |
650 | return -ENOMEM; | 648 | return -ENOMEM; |
651 | 649 | ||
652 | if (mutex_lock_interruptible(&ir->irctl_lock)) | 650 | if (mutex_lock_interruptible(&ir->irctl_lock)) { |
653 | return -ERESTARTSYS; | 651 | ret = -ERESTARTSYS; |
652 | goto out_unlocked; | ||
653 | } | ||
654 | if (!ir->attached) { | 654 | if (!ir->attached) { |
655 | mutex_unlock(&ir->irctl_lock); | 655 | ret = -ENODEV; |
656 | return -ENODEV; | 656 | goto out_locked; |
657 | } | 657 | } |
658 | 658 | ||
659 | if (length % ir->chunk_size) { | 659 | if (length % ir->chunk_size) { |
660 | dev_dbg(ir->d.dev, LOGHEAD "read result = -EINVAL\n", | 660 | ret = -EINVAL; |
661 | ir->d.name, ir->d.minor); | 661 | goto out_locked; |
662 | mutex_unlock(&ir->irctl_lock); | ||
663 | return -EINVAL; | ||
664 | } | 662 | } |
665 | 663 | ||
666 | /* | 664 | /* |
@@ -711,18 +709,23 @@ ssize_t lirc_dev_fop_read(struct file *file, | |||
711 | lirc_buffer_read(ir->buf, buf); | 709 | lirc_buffer_read(ir->buf, buf); |
712 | ret = copy_to_user((void *)buffer+written, buf, | 710 | ret = copy_to_user((void *)buffer+written, buf, |
713 | ir->buf->chunk_size); | 711 | ir->buf->chunk_size); |
714 | written += ir->buf->chunk_size; | 712 | if (!ret) |
713 | written += ir->buf->chunk_size; | ||
714 | else | ||
715 | ret = -EFAULT; | ||
715 | } | 716 | } |
716 | } | 717 | } |
717 | 718 | ||
718 | remove_wait_queue(&ir->buf->wait_poll, &wait); | 719 | remove_wait_queue(&ir->buf->wait_poll, &wait); |
719 | set_current_state(TASK_RUNNING); | 720 | set_current_state(TASK_RUNNING); |
721 | |||
722 | out_locked: | ||
720 | mutex_unlock(&ir->irctl_lock); | 723 | mutex_unlock(&ir->irctl_lock); |
721 | 724 | ||
722 | out_unlocked: | 725 | out_unlocked: |
723 | kfree(buf); | 726 | kfree(buf); |
724 | dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n", | 727 | dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n", |
725 | ir->d.name, ir->d.minor, ret ? "-EFAULT" : "OK", ret); | 728 | ir->d.name, ir->d.minor, ret ? "<fail>" : "<ok>", ret); |
726 | 729 | ||
727 | return ret ? ret : written; | 730 | return ret ? ret : written; |
728 | } | 731 | } |