unsigned int duration = 0; /* signal duration in us */
int i;
+ if (!dev->registered)
+ return -ENODEV;
+
start = ktime_get();
if (!dev->tx_ir) {
return ret;
}
+ if (!dev->registered)
+ return -ENODEV;
+
switch (cmd) {
case LIRC_GET_FEATURES:
if (dev->driver_type == RC_DRIVER_IR_RAW) {
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))
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;
if (length < sizeof(unsigned int) || length % sizeof(unsigned int))
return -EINVAL;
- if (!d->attached)
+ if (!rcdev->registered)
return -ENODEV;
do {
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);
cdev_init(&d->cdev, d->fops);
d->cdev.owner = d->owner;
- d->attached = true;
err = cdev_device_add(&d->cdev, &d->dev);
if (err) {
mutex_lock(&d->mutex);
- d->attached = false;
if (d->open) {
dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n",
d->name, d->minor);
if (retval)
return retval;
- if (!d->attached) {
+ if (!rcdev->registered) {
retval = -ENODEV;
goto out;
}
goto out_lirc;
}
+ dev->registered = true;
+
IR_dprintk(1, "Registered rc%u (driver: %s)\n",
dev->minor,
dev->driver_name ? dev->driver_name : "unknown");
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);
* @rdev: &struct rc_dev associated with the device
* @fops: &struct file_operations for the device
* @owner: the module owning this struct
- * @attached: if the device is still live
* @open: open count for the device's chardev
* @mutex: serialises file_operations calls
* @dev: &struct device assigned to the device
const struct file_operations *fops;
struct module *owner;
- bool attached;
int open;
struct mutex mutex; /* protect from simultaneous accesses */
* @wait_poll: poll struct for lirc device
* @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or
* LIRC_MODE_PULSE
+ * @registered: set to true by rc_register_device(), false by
+ * rc_unregister_device
* @change_protocol: allow changing the protocol used on hardware decoders
* @open: callback to allow drivers to enable polling/irq when IR input device
* is opened.
wait_queue_head_t wait_poll;
u8 send_mode;
#endif
+ bool registered;
int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
int (*open)(struct rc_dev *dev);
void (*close)(struct rc_dev *dev);