diff options
author | Sean Young <sean@mess.org> | 2017-09-26 07:31:29 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2017-12-14 10:35:18 -0500 |
commit | 7790e81f7e1f7f122f8fcccd91443a2571421aba (patch) | |
tree | 168eb07f96e9204c3b2a11b0e5cbfb98c083af54 /drivers/media/rc | |
parent | 71695aff9fe036857596965635e2607cf561a230 (diff) | |
download | blackbird-obmc-linux-7790e81f7e1f7f122f8fcccd91443a2571421aba.tar.gz blackbird-obmc-linux-7790e81f7e1f7f122f8fcccd91443a2571421aba.zip |
media: lirc: move lirc_dev->attached to rc_dev->registered
This is done to further remove the lirc kernel api. Ensure that every
fops checks for this.
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Diffstat (limited to 'drivers/media/rc')
-rw-r--r-- | drivers/media/rc/ir-lirc-codec.c | 16 | ||||
-rw-r--r-- | drivers/media/rc/lirc_dev.c | 4 | ||||
-rw-r--r-- | drivers/media/rc/rc-main.c | 10 |
3 files changed, 21 insertions, 9 deletions
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c index 2fa1f905a266..ff74a5d7a0f3 100644 --- a/drivers/media/rc/ir-lirc-codec.c +++ b/drivers/media/rc/ir-lirc-codec.c @@ -101,6 +101,9 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf, unsigned int duration = 0; /* signal duration in us */ int i; + if (!dev->registered) + return -ENODEV; + start = ktime_get(); if (!dev->tx_ir) { @@ -224,6 +227,9 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, return ret; } + if (!dev->registered) + return -ENODEV; + switch (cmd) { case LIRC_GET_FEATURES: if (dev->driver_type == RC_DRIVER_IR_RAW) { @@ -406,12 +412,11 @@ static unsigned int ir_lirc_poll(struct file *file, struct poll_table_struct *wait) { struct rc_dev *rcdev = file->private_data; - struct lirc_dev *d = rcdev->lirc_dev; unsigned int events = 0; poll_wait(file, &rcdev->wait_poll, wait); - if (!d->attached) + if (!rcdev->registered) events = POLLHUP | POLLERR; else if (rcdev->driver_type == RC_DRIVER_IR_RAW && !kfifo_is_empty(&rcdev->rawir)) @@ -424,7 +429,6 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer, size_t length, loff_t *ppos) { struct rc_dev *rcdev = file->private_data; - struct lirc_dev *d = rcdev->lirc_dev; unsigned int copied; int ret; @@ -434,7 +438,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer, if (length < sizeof(unsigned int) || length % sizeof(unsigned int)) return -EINVAL; - if (!d->attached) + if (!rcdev->registered) return -ENODEV; do { @@ -444,12 +448,12 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer, ret = wait_event_interruptible(rcdev->wait_poll, !kfifo_is_empty(&rcdev->rawir) || - !d->attached); + !rcdev->registered); if (ret) return ret; } - if (!d->attached) + if (!rcdev->registered) return -ENODEV; ret = mutex_lock_interruptible(&rcdev->lock); diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c index 9a0ad8d9a0cb..22171267aa90 100644 --- a/drivers/media/rc/lirc_dev.c +++ b/drivers/media/rc/lirc_dev.c @@ -122,7 +122,6 @@ int lirc_register_device(struct lirc_dev *d) cdev_init(&d->cdev, d->fops); d->cdev.owner = d->owner; - d->attached = true; err = cdev_device_add(&d->cdev, &d->dev); if (err) { @@ -153,7 +152,6 @@ void lirc_unregister_device(struct lirc_dev *d) mutex_lock(&d->mutex); - d->attached = false; if (d->open) { dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n", d->name, d->minor); @@ -180,7 +178,7 @@ int lirc_dev_fop_open(struct inode *inode, struct file *file) if (retval) return retval; - if (!d->attached) { + if (!rcdev->registered) { retval = -ENODEV; goto out; } diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c index e944d28b96d2..8b1b20e7a3c3 100644 --- a/drivers/media/rc/rc-main.c +++ b/drivers/media/rc/rc-main.c @@ -1809,6 +1809,8 @@ int rc_register_device(struct rc_dev *dev) goto out_lirc; } + dev->registered = true; + IR_dprintk(1, "Registered rc%u (driver: %s)\n", dev->minor, dev->driver_name ? dev->driver_name : "unknown"); @@ -1871,6 +1873,14 @@ void rc_unregister_device(struct rc_dev *dev) rc_free_rx_device(dev); + mutex_lock(&dev->lock); + dev->registered = false; + mutex_unlock(&dev->lock); + + /* + * lirc device should be freed with dev->registered = false, so + * that userspace polling will get notified. + */ if (dev->driver_type != RC_DRIVER_SCANCODE) ir_lirc_unregister(dev); |