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>
This commit is contained in:
parent
71695aff9f
commit
7790e81f7e
|
@ -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 */
|
unsigned int duration = 0; /* signal duration in us */
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (!dev->registered)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
start = ktime_get();
|
start = ktime_get();
|
||||||
|
|
||||||
if (!dev->tx_ir) {
|
if (!dev->tx_ir) {
|
||||||
|
@ -224,6 +227,9 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dev->registered)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case LIRC_GET_FEATURES:
|
case LIRC_GET_FEATURES:
|
||||||
if (dev->driver_type == RC_DRIVER_IR_RAW) {
|
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 poll_table_struct *wait)
|
||||||
{
|
{
|
||||||
struct rc_dev *rcdev = file->private_data;
|
struct rc_dev *rcdev = file->private_data;
|
||||||
struct lirc_dev *d = rcdev->lirc_dev;
|
|
||||||
unsigned int events = 0;
|
unsigned int events = 0;
|
||||||
|
|
||||||
poll_wait(file, &rcdev->wait_poll, wait);
|
poll_wait(file, &rcdev->wait_poll, wait);
|
||||||
|
|
||||||
if (!d->attached)
|
if (!rcdev->registered)
|
||||||
events = POLLHUP | POLLERR;
|
events = POLLHUP | POLLERR;
|
||||||
else if (rcdev->driver_type == RC_DRIVER_IR_RAW &&
|
else if (rcdev->driver_type == RC_DRIVER_IR_RAW &&
|
||||||
!kfifo_is_empty(&rcdev->rawir))
|
!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)
|
size_t length, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct rc_dev *rcdev = file->private_data;
|
struct rc_dev *rcdev = file->private_data;
|
||||||
struct lirc_dev *d = rcdev->lirc_dev;
|
|
||||||
unsigned int copied;
|
unsigned int copied;
|
||||||
int ret;
|
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))
|
if (length < sizeof(unsigned int) || length % sizeof(unsigned int))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (!d->attached)
|
if (!rcdev->registered)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -444,12 +448,12 @@ static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
|
||||||
|
|
||||||
ret = wait_event_interruptible(rcdev->wait_poll,
|
ret = wait_event_interruptible(rcdev->wait_poll,
|
||||||
!kfifo_is_empty(&rcdev->rawir) ||
|
!kfifo_is_empty(&rcdev->rawir) ||
|
||||||
!d->attached);
|
!rcdev->registered);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!d->attached)
|
if (!rcdev->registered)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
ret = mutex_lock_interruptible(&rcdev->lock);
|
ret = mutex_lock_interruptible(&rcdev->lock);
|
||||||
|
|
|
@ -122,7 +122,6 @@ int lirc_register_device(struct lirc_dev *d)
|
||||||
|
|
||||||
cdev_init(&d->cdev, d->fops);
|
cdev_init(&d->cdev, d->fops);
|
||||||
d->cdev.owner = d->owner;
|
d->cdev.owner = d->owner;
|
||||||
d->attached = true;
|
|
||||||
|
|
||||||
err = cdev_device_add(&d->cdev, &d->dev);
|
err = cdev_device_add(&d->cdev, &d->dev);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -153,7 +152,6 @@ void lirc_unregister_device(struct lirc_dev *d)
|
||||||
|
|
||||||
mutex_lock(&d->mutex);
|
mutex_lock(&d->mutex);
|
||||||
|
|
||||||
d->attached = false;
|
|
||||||
if (d->open) {
|
if (d->open) {
|
||||||
dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n",
|
dev_dbg(&d->dev, LOGHEAD "releasing opened driver\n",
|
||||||
d->name, d->minor);
|
d->name, d->minor);
|
||||||
|
@ -180,7 +178,7 @@ int lirc_dev_fop_open(struct inode *inode, struct file *file)
|
||||||
if (retval)
|
if (retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
if (!d->attached) {
|
if (!rcdev->registered) {
|
||||||
retval = -ENODEV;
|
retval = -ENODEV;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1809,6 +1809,8 @@ int rc_register_device(struct rc_dev *dev)
|
||||||
goto out_lirc;
|
goto out_lirc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dev->registered = true;
|
||||||
|
|
||||||
IR_dprintk(1, "Registered rc%u (driver: %s)\n",
|
IR_dprintk(1, "Registered rc%u (driver: %s)\n",
|
||||||
dev->minor,
|
dev->minor,
|
||||||
dev->driver_name ? dev->driver_name : "unknown");
|
dev->driver_name ? dev->driver_name : "unknown");
|
||||||
|
@ -1871,6 +1873,14 @@ void rc_unregister_device(struct rc_dev *dev)
|
||||||
|
|
||||||
rc_free_rx_device(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)
|
if (dev->driver_type != RC_DRIVER_SCANCODE)
|
||||||
ir_lirc_unregister(dev);
|
ir_lirc_unregister(dev);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
* @rdev: &struct rc_dev associated with the device
|
* @rdev: &struct rc_dev associated with the device
|
||||||
* @fops: &struct file_operations for the device
|
* @fops: &struct file_operations for the device
|
||||||
* @owner: the module owning this struct
|
* @owner: the module owning this struct
|
||||||
* @attached: if the device is still live
|
|
||||||
* @open: open count for the device's chardev
|
* @open: open count for the device's chardev
|
||||||
* @mutex: serialises file_operations calls
|
* @mutex: serialises file_operations calls
|
||||||
* @dev: &struct device assigned to the device
|
* @dev: &struct device assigned to the device
|
||||||
|
@ -40,7 +39,6 @@ struct lirc_dev {
|
||||||
const struct file_operations *fops;
|
const struct file_operations *fops;
|
||||||
struct module *owner;
|
struct module *owner;
|
||||||
|
|
||||||
bool attached;
|
|
||||||
int open;
|
int open;
|
||||||
|
|
||||||
struct mutex mutex; /* protect from simultaneous accesses */
|
struct mutex mutex; /* protect from simultaneous accesses */
|
||||||
|
|
|
@ -127,6 +127,8 @@ enum rc_filter_type {
|
||||||
* @wait_poll: poll struct for lirc device
|
* @wait_poll: poll struct for lirc device
|
||||||
* @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or
|
* @send_mode: lirc mode for sending, either LIRC_MODE_SCANCODE or
|
||||||
* LIRC_MODE_PULSE
|
* 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
|
* @change_protocol: allow changing the protocol used on hardware decoders
|
||||||
* @open: callback to allow drivers to enable polling/irq when IR input device
|
* @open: callback to allow drivers to enable polling/irq when IR input device
|
||||||
* is opened.
|
* is opened.
|
||||||
|
@ -197,6 +199,7 @@ struct rc_dev {
|
||||||
wait_queue_head_t wait_poll;
|
wait_queue_head_t wait_poll;
|
||||||
u8 send_mode;
|
u8 send_mode;
|
||||||
#endif
|
#endif
|
||||||
|
bool registered;
|
||||||
int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
|
int (*change_protocol)(struct rc_dev *dev, u64 *rc_proto);
|
||||||
int (*open)(struct rc_dev *dev);
|
int (*open)(struct rc_dev *dev);
|
||||||
void (*close)(struct rc_dev *dev);
|
void (*close)(struct rc_dev *dev);
|
||||||
|
|
Loading…
Reference in New Issue