This makes it possible for lircd to read from a lirc chardev, and not keep it busy. Note that this changes the default for timeout reports to on. lircd already enables timeout reports when it opens a lirc device, leaving them on until the next reboot.
Showing the changes to drivers/media/rc/lirc_dev.c (1 of 2 files). Show all
Unified · Split
| @@ -28,7 +28,6 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "rc-core-priv.h" |
| 29 | 29 | #include <uapi/linux/lirc.h> |
| 30 | 30 | |
| 31 | −#define LOGHEAD "lirc_dev (%s[%d]): " | |
| 32 | 31 | #define LIRCBUF_SIZE 256 |
| 33 | 32 | |
| 34 | 33 | static dev_t lirc_base_dev; |
| @@ -47,6 +46,8 @@ static struct class *lirc_class; · 12 unmodified lines | ||
| 47 | 46 | */ |
| 48 | 47 | void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) |
| 49 | 48 | { |
| 49 | + unsigned long flags; | |
| 50 | + struct lirc_fh *fh; | |
| 50 | 51 | int sample; |
| 51 | 52 | |
| 52 | 53 | /* Packet start */ |
| @@ -75,9 +76,6 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) · 22 unmodified lines | ||
| 75 | 76 | dev->gap = true; |
| 76 | 77 | dev->gap_duration = ev.duration; |
| 77 | 78 | |
| 78 | − if (!dev->send_timeout_reports) | |
| 79 | − return; | |
| 80 | − | |
| 81 | 79 | sample = LIRC_TIMEOUT(ev.duration / 1000); |
| 82 | 80 | IR_dprintk(2, "timeout report (duration: %d)\n", sample); |
| 83 | 81 | |
| @@ -92,7 +90,11 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) · 8 unmodified lines | ||
| 92 | 90 | dev->gap_duration = min_t(u64, dev->gap_duration, |
| 93 | 91 | LIRC_VALUE_MASK); |
| 94 | 92 | |
| 95 | − kfifo_put(&dev->rawir, LIRC_SPACE(dev->gap_duration)); | |
| 93 | + spin_lock_irqsave(&dev->lirc_fh_lock, flags); | |
| 94 | + list_for_each_entry(fh, &dev->lirc_fh, list) | |
| 95 | + kfifo_put(&fh->rawir, | |
| 96 | + LIRC_SPACE(dev->gap_duration)); | |
| 97 | + spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | |
| 96 | 98 | dev->gap = false; |
| 97 | 99 | } |
| 98 | 100 | |
| @@ -102,22 +104,35 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev) · 3 unmodified lines | ||
| 102 | 104 | TO_US(ev.duration), TO_STR(ev.pulse)); |
| 103 | 105 | } |
| 104 | 106 | |
| 105 | − kfifo_put(&dev->rawir, sample); | |
| 106 | − wake_up_poll(&dev->wait_poll, POLLIN | POLLRDNORM); | |
| 107 | + spin_lock_irqsave(&dev->lirc_fh_lock, flags); | |
| 108 | + list_for_each_entry(fh, &dev->lirc_fh, list) { | |
| 109 | + if (LIRC_IS_TIMEOUT(sample) && !fh->send_timeout_reports) | |
| 110 | + continue; | |
| 111 | + if (kfifo_put(&fh->rawir, sample)) | |
| 112 | + wake_up_poll(&fh->wait_poll, POLLIN | POLLRDNORM); | |
| 113 | + } | |
| 114 | + spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | |
| 107 | 115 | } |
| 108 | 116 | |
| 109 | 117 | /** |
| 110 | 118 | * ir_lirc_scancode_event() - Send scancode data to lirc to be relayed to |
| 111 | − * userspace | |
| 119 | + * userspace. This can be called in atomic context. | |
| 112 | 120 | * @dev: the struct rc_dev descriptor of the device |
| 113 | 121 | * @lsc: the struct lirc_scancode describing the decoded scancode |
| 114 | 122 | */ |
| 115 | 123 | void ir_lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc) |
| 116 | 124 | { |
| 125 | + unsigned long flags; | |
| 126 | + struct lirc_fh *fh; | |
| 127 | + | |
| 117 | 128 | lsc->timestamp = ktime_get_ns(); |
| 118 | 129 | |
| 119 | − if (kfifo_put(&dev->scancodes, *lsc)) | |
| 120 | − wake_up_poll(&dev->wait_poll, POLLIN | POLLRDNORM); | |
| 130 | + spin_lock_irqsave(&dev->lirc_fh_lock, flags); | |
| 131 | + list_for_each_entry(fh, &dev->lirc_fh, list) { | |
| 132 | + if (kfifo_put(&fh->scancodes, *lsc)) | |
| 133 | + wake_up_poll(&fh->wait_poll, POLLIN | POLLRDNORM); | |
| 134 | + } | |
| 135 | + spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | |
| 121 | 136 | } |
| 122 | 137 | EXPORT_SYMBOL_GPL(ir_lirc_scancode_event); |
| 123 | 138 | |
| @@ -125,55 +140,88 @@ static int ir_lirc_open(struct inode *inode, struct file *file) · 1 unmodified line | ||
| 125 | 140 | { |
| 126 | 141 | struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev, |
| 127 | 142 | lirc_cdev); |
| 143 | + struct lirc_fh *fh = kzalloc(sizeof(*fh), GFP_KERNEL); | |
| 144 | + unsigned long flags; | |
| 128 | 145 | int retval; |
| 129 | 146 | |
| 130 | − retval = rc_open(dev); | |
| 131 | − if (retval) | |
| 132 | − return retval; | |
| 147 | + if (!fh) | |
| 148 | + return -ENOMEM; | |
| 133 | 149 | |
| 134 | − retval = mutex_lock_interruptible(&dev->lock); | |
| 135 | − if (retval) | |
| 136 | − goto out_rc; | |
| 150 | + get_device(&dev->dev); | |
| 137 | 151 | |
| 138 | 152 | if (!dev->registered) { |
| 139 | 153 | retval = -ENODEV; |
| 140 | − goto out_unlock; | |
| 154 | + goto out_fh; | |
| 141 | 155 | } |
| 142 | 156 | |
| 143 | − if (dev->lirc_open) { | |
| 144 | − retval = -EBUSY; | |
| 145 | − goto out_unlock; | |
| 157 | + if (dev->driver_type == RC_DRIVER_IR_RAW) { | |
| 158 | + if (kfifo_alloc(&fh->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL)) { | |
| 159 | + retval = -ENOMEM; | |
| 160 | + goto out_fh; | |
| 161 | + } | |
| 146 | 162 | } |
| 147 | 163 | |
| 148 | − if (dev->driver_type == RC_DRIVER_IR_RAW) | |
| 149 | − kfifo_reset_out(&dev->rawir); | |
| 150 | − if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | |
| 151 | − kfifo_reset_out(&dev->scancodes); | |
| 164 | + if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { | |
| 165 | + if (kfifo_alloc(&fh->scancodes, 32, GFP_KERNEL)) { | |
| 166 | + retval = -ENOMEM; | |
| 167 | + goto out_rawir; | |
| 168 | + } | |
| 169 | + } | |
| 170 | + | |
| 171 | + fh->send_mode = LIRC_MODE_PULSE; | |
| 172 | + fh->rc = dev; | |
| 173 | + fh->send_timeout_reports = true; | |
| 174 | + | |
| 175 | + if (dev->driver_type == RC_DRIVER_SCANCODE) | |
| 176 | + fh->rec_mode = LIRC_MODE_SCANCODE; | |
| 177 | + else | |
| 178 | + fh->rec_mode = LIRC_MODE_MODE2; | |
| 179 | + | |
| 180 | + retval = rc_open(dev); | |
| 181 | + if (retval) | |
| 182 | + goto out_kfifo; | |
| 183 | + | |
| 184 | + init_waitqueue_head(&fh->wait_poll); | |
| 152 | 185 | |
| 153 | − dev->lirc_open++; | |
| 154 | − file->private_data = dev; | |
| 186 | + file->private_data = fh; | |
| 187 | + spin_lock_irqsave(&dev->lirc_fh_lock, flags); | |
| 188 | + list_add(&fh->list, &dev->lirc_fh); | |
| 189 | + spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | |
| 155 | 190 | |
| 156 | 191 | nonseekable_open(inode, file); |
| 157 | − mutex_unlock(&dev->lock); | |
| 158 | 192 | |
| 159 | 193 | return 0; |
| 194 | +out_kfifo: | |
| 195 | + if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | |
| 196 | + kfifo_free(&fh->scancodes); | |
| 197 | +out_rawir: | |
| 198 | + if (dev->driver_type == RC_DRIVER_IR_RAW) | |
| 199 | + kfifo_free(&fh->rawir); | |
| 200 | +out_fh: | |
| 201 | + kfree(fh); | |
| 202 | + put_device(&dev->dev); | |
| 160 | 203 | |
| 161 | −out_unlock: | |
| 162 | − mutex_unlock(&dev->lock); | |
| 163 | −out_rc: | |
| 164 | − rc_close(dev); | |
| 165 | 204 | return retval; |
| 166 | 205 | } |
| 167 | 206 | |
| 168 | 207 | static int ir_lirc_close(struct inode *inode, struct file *file) |
| 169 | 208 | { |
| 170 | − struct rc_dev *dev = file->private_data; | |
| 209 | + struct lirc_fh *fh = file->private_data; | |
| 210 | + struct rc_dev *dev = fh->rc; | |
| 211 | + unsigned long flags; | |
| 171 | 212 | |
| 172 | − mutex_lock(&dev->lock); | |
| 173 | − dev->lirc_open--; | |
| 174 | − mutex_unlock(&dev->lock); | |
| 213 | + spin_lock_irqsave(&dev->lirc_fh_lock, flags); | |
| 214 | + list_del(&fh->list); | |
| 215 | + spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | |
| 216 | + | |
| 217 | + if (dev->driver_type == RC_DRIVER_IR_RAW) | |
| 218 | + kfifo_free(&fh->rawir); | |
| 219 | + if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | |
| 220 | + kfifo_free(&fh->scancodes); | |
| 221 | + kfree(fh); | |
| 175 | 222 | |
| 176 | 223 | rc_close(dev); |
| 224 | + put_device(&dev->dev); | |
| 177 | 225 | |
| 178 | 226 | return 0; |
| 179 | 227 | } |
| @@ -181,7 +229,8 @@ static int ir_lirc_close(struct inode *inode, struct file *file) · 1 unmodified line | ||
| 181 | 229 | static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, |
| 182 | 230 | size_t n, loff_t *ppos) |
| 183 | 231 | { |
| 184 | − struct rc_dev *dev = file->private_data; | |
| 232 | + struct lirc_fh *fh = file->private_data; | |
| 233 | + struct rc_dev *dev = fh->rc; | |
| 185 | 234 | unsigned int *txbuf = NULL; |
| 186 | 235 | struct ir_raw_event *raw = NULL; |
| 187 | 236 | ssize_t ret = -EINVAL; |
| @@ -201,7 +250,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, · 13 unmodified lines | ||
| 201 | 250 | goto out; |
| 202 | 251 | } |
| 203 | 252 | |
| 204 | − if (dev->send_mode == LIRC_MODE_SCANCODE) { | |
| 253 | + if (fh->send_mode == LIRC_MODE_SCANCODE) { | |
| 205 | 254 | struct lirc_scancode scan; |
| 206 | 255 | |
| 207 | 256 | if (n != sizeof(scan)) |
| @@ -276,7 +325,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, · 68 unmodified lines | ||
| 276 | 325 | if (ret < 0) |
| 277 | 326 | goto out; |
| 278 | 327 | |
| 279 | − if (dev->send_mode == LIRC_MODE_SCANCODE) { | |
| 328 | + if (fh->send_mode == LIRC_MODE_SCANCODE) { | |
| 280 | 329 | ret = n; |
| 281 | 330 | } else { |
| 282 | 331 | for (duration = i = 0; i < ret; i++) |
| @@ -303,10 +352,11 @@ out: · 20 unmodified lines | ||
| 303 | 352 | return ret; |
| 304 | 353 | } |
| 305 | 354 | |
| 306 | −static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, | |
| 355 | +static long ir_lirc_ioctl(struct file *file, unsigned int cmd, | |
| 307 | 356 | unsigned long arg) |
| 308 | 357 | { |
| 309 | − struct rc_dev *dev = filep->private_data; | |
| 358 | + struct lirc_fh *fh = file->private_data; | |
| 359 | + struct rc_dev *dev = fh->rc; | |
| 310 | 360 | u32 __user *argp = (u32 __user *)(arg); |
| 311 | 361 | int ret = 0; |
| 312 | 362 | __u32 val = 0, tmp; |
| @@ -361,7 +411,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 48 unmodified lines | ||
| 361 | 411 | if (dev->driver_type == RC_DRIVER_IR_RAW_TX) |
| 362 | 412 | return -ENOTTY; |
| 363 | 413 | |
| 364 | − val = dev->rec_mode; | |
| 414 | + val = fh->rec_mode; | |
| 365 | 415 | break; |
| 366 | 416 | |
| 367 | 417 | case LIRC_SET_REC_MODE: |
| @@ -379,14 +429,14 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 11 unmodified lines | ||
| 379 | 429 | break; |
| 380 | 430 | } |
| 381 | 431 | |
| 382 | − dev->rec_mode = val; | |
| 432 | + fh->rec_mode = val; | |
| 383 | 433 | return 0; |
| 384 | 434 | |
| 385 | 435 | case LIRC_GET_SEND_MODE: |
| 386 | 436 | if (!dev->tx_ir) |
| 387 | 437 | return -ENOTTY; |
| 388 | 438 | |
| 389 | − val = dev->send_mode; | |
| 439 | + val = fh->send_mode; | |
| 390 | 440 | break; |
| 391 | 441 | |
| 392 | 442 | case LIRC_SET_SEND_MODE: |
| @@ -396,7 +446,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 3 unmodified lines | ||
| 396 | 446 | if (!(val == LIRC_MODE_PULSE || val == LIRC_MODE_SCANCODE)) |
| 397 | 447 | return -EINVAL; |
| 398 | 448 | |
| 399 | − dev->send_mode = val; | |
| 449 | + fh->send_mode = val; | |
| 400 | 450 | return 0; |
| 401 | 451 | |
| 402 | 452 | /* TX settings */ |
| @@ -430,7 +480,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 27 unmodified lines | ||
| 430 | 480 | return -EINVAL; |
| 431 | 481 | |
| 432 | 482 | return dev->s_rx_carrier_range(dev, |
| 433 | − dev->carrier_low, | |
| 483 | + fh->carrier_low, | |
| 434 | 484 | val); |
| 435 | 485 | |
| 436 | 486 | case LIRC_SET_REC_CARRIER_RANGE: |
| @@ -440,7 +490,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 3 unmodified lines | ||
| 440 | 490 | if (val <= 0) |
| 441 | 491 | return -EINVAL; |
| 442 | 492 | |
| 443 | − dev->carrier_low = val; | |
| 493 | + fh->carrier_low = val; | |
| 444 | 494 | return 0; |
| 445 | 495 | |
| 446 | 496 | case LIRC_GET_REC_RESOLUTION: |
| @@ -498,7 +548,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 51 unmodified lines | ||
| 498 | 548 | if (!dev->timeout) |
| 499 | 549 | return -ENOTTY; |
| 500 | 550 | |
| 501 | − dev->send_timeout_reports = !!val; | |
| 551 | + fh->send_timeout_reports = !!val; | |
| 502 | 552 | break; |
| 503 | 553 | |
| 504 | 554 | default: |
| @@ -514,20 +564,21 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, · 9 unmodified lines | ||
| 514 | 564 | static unsigned int ir_lirc_poll(struct file *file, |
| 515 | 565 | struct poll_table_struct *wait) |
| 516 | 566 | { |
| 517 | − struct rc_dev *rcdev = file->private_data; | |
| 567 | + struct lirc_fh *fh = file->private_data; | |
| 568 | + struct rc_dev *rcdev = fh->rc; | |
| 518 | 569 | unsigned int events = 0; |
| 519 | 570 | |
| 520 | − poll_wait(file, &rcdev->wait_poll, wait); | |
| 571 | + poll_wait(file, &fh->wait_poll, wait); | |
| 521 | 572 | |
| 522 | 573 | if (!rcdev->registered) { |
| 523 | 574 | events = POLLHUP | POLLERR; |
| 524 | 575 | } else if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) { |
| 525 | − if (rcdev->rec_mode == LIRC_MODE_SCANCODE && | |
| 526 | − !kfifo_is_empty(&rcdev->scancodes)) | |
| 576 | + if (fh->rec_mode == LIRC_MODE_SCANCODE && | |
| 577 | + !kfifo_is_empty(&fh->scancodes)) | |
| 527 | 578 | events = POLLIN | POLLRDNORM; |
| 528 | 579 | |
| 529 | − if (rcdev->rec_mode == LIRC_MODE_MODE2 && | |
| 530 | − !kfifo_is_empty(&rcdev->rawir)) | |
| 580 | + if (fh->rec_mode == LIRC_MODE_MODE2 && | |
| 581 | + !kfifo_is_empty(&fh->rawir)) | |
| 531 | 582 | events = POLLIN | POLLRDNORM; |
| 532 | 583 | } |
| 533 | 584 | |
| @@ -537,7 +588,8 @@ static unsigned int ir_lirc_poll(struct file *file, · 3 unmodified lines | ||
| 537 | 588 | static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, |
| 538 | 589 | size_t length) |
| 539 | 590 | { |
| 540 | − struct rc_dev *rcdev = file->private_data; | |
| 591 | + struct lirc_fh *fh = file->private_data; | |
| 592 | + struct rc_dev *rcdev = fh->rc; | |
| 541 | 593 | unsigned int copied; |
| 542 | 594 | int ret; |
| 543 | 595 | |
| @@ -545,12 +597,12 @@ static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, · 1 unmodified line | ||
| 545 | 597 | return -EINVAL; |
| 546 | 598 | |
| 547 | 599 | do { |
| 548 | − if (kfifo_is_empty(&rcdev->rawir)) { | |
| 600 | + if (kfifo_is_empty(&fh->rawir)) { | |
| 549 | 601 | if (file->f_flags & O_NONBLOCK) |
| 550 | 602 | return -EAGAIN; |
| 551 | 603 | |
| 552 | − ret = wait_event_interruptible(rcdev->wait_poll, | |
| 553 | − !kfifo_is_empty(&rcdev->rawir) || | |
| 604 | + ret = wait_event_interruptible(fh->wait_poll, | |
| 605 | + !kfifo_is_empty(&fh->rawir) || | |
| 554 | 606 | !rcdev->registered); |
| 555 | 607 | if (ret) |
| 556 | 608 | return ret; |
| @@ -562,7 +614,7 @@ static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, · 5 unmodified lines | ||
| 562 | 614 | ret = mutex_lock_interruptible(&rcdev->lock); |
| 563 | 615 | if (ret) |
| 564 | 616 | return ret; |
| 565 | − ret = kfifo_to_user(&rcdev->rawir, buffer, length, &copied); | |
| 617 | + ret = kfifo_to_user(&fh->rawir, buffer, length, &copied); | |
| 566 | 618 | mutex_unlock(&rcdev->lock); |
| 567 | 619 | if (ret) |
| 568 | 620 | return ret; |
| @@ -574,7 +626,8 @@ static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer, · 5 unmodified lines | ||
| 574 | 626 | static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, |
| 575 | 627 | size_t length) |
| 576 | 628 | { |
| 577 | − struct rc_dev *rcdev = file->private_data; | |
| 629 | + struct lirc_fh *fh = file->private_data; | |
| 630 | + struct rc_dev *rcdev = fh->rc; | |
| 578 | 631 | unsigned int copied; |
| 579 | 632 | int ret; |
| 580 | 633 | |
| @@ -583,12 +636,12 @@ static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, · 2 unmodified lines | ||
| 583 | 636 | return -EINVAL; |
| 584 | 637 | |
| 585 | 638 | do { |
| 586 | − if (kfifo_is_empty(&rcdev->scancodes)) { | |
| 639 | + if (kfifo_is_empty(&fh->scancodes)) { | |
| 587 | 640 | if (file->f_flags & O_NONBLOCK) |
| 588 | 641 | return -EAGAIN; |
| 589 | 642 | |
| 590 | − ret = wait_event_interruptible(rcdev->wait_poll, | |
| 591 | − !kfifo_is_empty(&rcdev->scancodes) || | |
| 643 | + ret = wait_event_interruptible(fh->wait_poll, | |
| 644 | + !kfifo_is_empty(&fh->scancodes) || | |
| 592 | 645 | !rcdev->registered); |
| 593 | 646 | if (ret) |
| 594 | 647 | return ret; |
| @@ -600,7 +653,7 @@ static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, · 5 unmodified lines | ||
| 600 | 653 | ret = mutex_lock_interruptible(&rcdev->lock); |
| 601 | 654 | if (ret) |
| 602 | 655 | return ret; |
| 603 | − ret = kfifo_to_user(&rcdev->scancodes, buffer, length, &copied); | |
| 656 | + ret = kfifo_to_user(&fh->scancodes, buffer, length, &copied); | |
| 604 | 657 | mutex_unlock(&rcdev->lock); |
| 605 | 658 | if (ret) |
| 606 | 659 | return ret; |
| @@ -612,7 +665,8 @@ static ssize_t ir_lirc_read_scancode(struct file *file, char __user *buffer, · 5 unmodified lines | ||
| 612 | 665 | static ssize_t ir_lirc_read(struct file *file, char __user *buffer, |
| 613 | 666 | size_t length, loff_t *ppos) |
| 614 | 667 | { |
| 615 | − struct rc_dev *rcdev = file->private_data; | |
| 668 | + struct lirc_fh *fh = file->private_data; | |
| 669 | + struct rc_dev *rcdev = fh->rc; | |
| 616 | 670 | |
| 617 | 671 | if (rcdev->driver_type == RC_DRIVER_IR_RAW_TX) |
| 618 | 672 | return -EINVAL; |
| @@ -620,7 +674,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer, · 1 unmodified line | ||
| 620 | 674 | if (!rcdev->registered) |
| 621 | 675 | return -ENODEV; |
| 622 | 676 | |
| 623 | − if (rcdev->rec_mode == LIRC_MODE_MODE2) | |
| 677 | + if (fh->rec_mode == LIRC_MODE_MODE2) | |
| 624 | 678 | return ir_lirc_read_mode2(file, buffer, length); |
| 625 | 679 | else /* LIRC_MODE_SCANCODE */ |
| 626 | 680 | return ir_lirc_read_scancode(file, buffer, length); |
| @@ -644,11 +698,6 @@ static void lirc_release_device(struct device *ld) · 17 unmodified lines | ||
| 644 | 698 | { |
| 645 | 699 | struct rc_dev *rcdev = container_of(ld, struct rc_dev, lirc_dev); |
| 646 | 700 | |
| 647 | − if (rcdev->driver_type == RC_DRIVER_IR_RAW) | |
| 648 | − kfifo_free(&rcdev->rawir); | |
| 649 | − if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) | |
| 650 | − kfifo_free(&rcdev->scancodes); | |
| 651 | − | |
| 652 | 701 | put_device(&rcdev->dev); |
| 653 | 702 | } |
| 654 | 703 | |
| @@ -656,40 +705,20 @@ int ir_lirc_register(struct rc_dev *dev) · 1 unmodified line | ||
| 656 | 705 | { |
| 657 | 706 | int err, minor; |
| 658 | 707 | |
| 659 | − device_initialize(&dev->lirc_dev); | |
| 660 | − dev->lirc_dev.class = lirc_class; | |
| 661 | − dev->lirc_dev.release = lirc_release_device; | |
| 662 | − dev->send_mode = LIRC_MODE_PULSE; | |
| 663 | − | |
| 664 | − if (dev->driver_type == RC_DRIVER_SCANCODE) | |
| 665 | − dev->rec_mode = LIRC_MODE_SCANCODE; | |
| 666 | − else | |
| 667 | − dev->rec_mode = LIRC_MODE_MODE2; | |
| 668 | − | |
| 669 | − if (dev->driver_type == RC_DRIVER_IR_RAW) { | |
| 670 | − if (kfifo_alloc(&dev->rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL)) | |
| 671 | − return -ENOMEM; | |
| 672 | − } | |
| 673 | − | |
| 674 | − if (dev->driver_type != RC_DRIVER_IR_RAW_TX) { | |
| 675 | − if (kfifo_alloc(&dev->scancodes, 32, GFP_KERNEL)) { | |
| 676 | − kfifo_free(&dev->rawir); | |
| 677 | − return -ENOMEM; | |
| 678 | − } | |
| 679 | − } | |
| 680 | − | |
| 681 | − init_waitqueue_head(&dev->wait_poll); | |
| 682 | − | |
| 683 | 708 | minor = ida_simple_get(&lirc_ida, 0, RC_DEV_MAX, GFP_KERNEL); |
| 684 | − if (minor < 0) { | |
| 685 | − err = minor; | |
| 686 | − goto out_kfifo; | |
| 687 | − } | |
| 709 | + if (minor < 0) | |
| 710 | + return minor; | |
| 688 | 711 | |
| 712 | + device_initialize(&dev->lirc_dev); | |
| 713 | + dev->lirc_dev.class = lirc_class; | |
| 689 | 714 | dev->lirc_dev.parent = &dev->dev; |
| 715 | + dev->lirc_dev.release = lirc_release_device; | |
| 690 | 716 | dev->lirc_dev.devt = MKDEV(MAJOR(lirc_base_dev), minor); |
| 691 | 717 | dev_set_name(&dev->lirc_dev, "lirc%d", minor); |
| 692 | 718 | |
| 719 | + INIT_LIST_HEAD(&dev->lirc_fh); | |
| 720 | + spin_lock_init(&dev->lirc_fh_lock); | |
| 721 | + | |
| 693 | 722 | cdev_init(&dev->lirc_cdev, &lirc_fops); |
| 694 | 723 | |
| 695 | 724 | err = cdev_device_add(&dev->lirc_cdev, &dev->lirc_dev); |
| @@ -705,32 +734,24 @@ int ir_lirc_register(struct rc_dev *dev) · 9 unmodified lines | ||
| 705 | 734 | |
| 706 | 735 | out_ida: |
| 707 | 736 | ida_simple_remove(&lirc_ida, minor); |
| 708 | −out_kfifo: | |
| 709 | − if (dev->driver_type == RC_DRIVER_IR_RAW) | |
| 710 | − kfifo_free(&dev->rawir); | |
| 711 | − if (dev->driver_type != RC_DRIVER_IR_RAW_TX) | |
| 712 | − kfifo_free(&dev->scancodes); | |
| 713 | 737 | return err; |
| 714 | 738 | } |
| 715 | 739 | |
| 716 | 740 | void ir_lirc_unregister(struct rc_dev *dev) |
| 717 | 741 | { |
| 742 | + unsigned long flags; | |
| 743 | + struct lirc_fh *fh; | |
| 744 | + | |
| 718 | 745 | dev_dbg(&dev->dev, "lirc_dev: driver %s unregistered from minor = %d\n", |
| 719 | 746 | dev->driver_name, MINOR(dev->lirc_dev.devt)); |
| 720 | 747 | |
| 721 | − mutex_lock(&dev->lock); | |
| 722 | − | |
| 723 | − if (dev->lirc_open) { | |
| 724 | − dev_dbg(&dev->dev, LOGHEAD "releasing opened driver\n", | |
| 725 | − dev->driver_name, MINOR(dev->lirc_dev.devt)); | |
| 726 | − wake_up_poll(&dev->wait_poll, POLLHUP); | |
| 727 | − } | |
| 728 | − | |
| 729 | − mutex_unlock(&dev->lock); | |
| 748 | + spin_lock_irqsave(&dev->lirc_fh_lock, flags); | |
| 749 | + list_for_each_entry(fh, &dev->lirc_fh, list) | |
| 750 | + wake_up_poll(&fh->wait_poll, POLLHUP | POLLERR); | |
| 751 | + spin_unlock_irqrestore(&dev->lirc_fh_lock, flags); | |
| 730 | 752 | |
| 731 | 753 | cdev_device_del(&dev->lirc_cdev, &dev->lirc_dev); |
| 732 | 754 | ida_simple_remove(&lirc_ida, MINOR(dev->lirc_dev.devt)); |
| 733 | − put_device(&dev->lirc_dev); | |
| 734 | 755 | } |
| 735 | 756 | |
| 736 | 757 | int __init lirc_dev_init(void) |