Commit b15e3937 authored by David Härdeman's avatar David Härdeman Committed by Mauro Carvalho Chehab

[media] media: lirc_dev: merge struct irctl into struct lirc_dev

The use of two separate structs (lirc_dev aka lirc_driver and irctl) makes
it much harder to follow the proper lifetime of the various structs and
necessitates hacks such as keeping a copy of struct lirc_dev inside
struct irctl.

Merging the two structs means that lirc_dev can properly manage the
lifetime of the resulting struct and simplifies the code at the same time.

[mchehab@s-opensource.com: fix merge conflict]
Signed-off-by: default avatarDavid Härdeman <david@hardeman.nu>
Signed-off-by: default avatarSean Young <sean@mess.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@osg.samsung.com>
parent 13f96555
......@@ -35,7 +35,7 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
struct lirc_codec *lirc = &dev->raw->lirc;
int sample;
if (!dev->raw->lirc.ldev || !dev->raw->lirc.ldev->rbuf)
if (!dev->raw->lirc.ldev || !dev->raw->lirc.ldev->buf)
return -EINVAL;
/* Packet start */
......@@ -84,7 +84,7 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
(u64)LIRC_VALUE_MASK);
gap_sample = LIRC_SPACE(lirc->gap_duration);
lirc_buffer_write(dev->raw->lirc.ldev->rbuf,
lirc_buffer_write(dev->raw->lirc.ldev->buf,
(unsigned char *)&gap_sample);
lirc->gap = false;
}
......@@ -95,9 +95,9 @@ static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
TO_US(ev.duration), TO_STR(ev.pulse));
}
lirc_buffer_write(dev->raw->lirc.ldev->rbuf,
lirc_buffer_write(dev->raw->lirc.ldev->buf,
(unsigned char *) &sample);
wake_up(&dev->raw->lirc.ldev->rbuf->wait_poll);
wake_up(&dev->raw->lirc.ldev->buf->wait_poll);
return 0;
}
......@@ -384,12 +384,12 @@ static int ir_lirc_register(struct rc_dev *dev)
dev->driver_name);
ldev->features = features;
ldev->data = &dev->raw->lirc;
ldev->rbuf = NULL;
ldev->buf = NULL;
ldev->code_length = sizeof(struct ir_raw_event) * 8;
ldev->chunk_size = sizeof(int);
ldev->buffer_size = LIRCBUF_SIZE;
ldev->fops = &lirc_fops;
ldev->dev = &dev->dev;
ldev->dev.parent = &dev->dev;
ldev->rdev = dev;
ldev->owner = THIS_MODULE;
......@@ -402,7 +402,7 @@ static int ir_lirc_register(struct rc_dev *dev)
return 0;
out:
kfree(ldev);
lirc_free_device(ldev);
return rc;
}
......@@ -411,7 +411,6 @@ static int ir_lirc_unregister(struct rc_dev *dev)
struct lirc_codec *lirc = &dev->raw->lirc;
lirc_unregister_device(lirc->ldev);
kfree(lirc->ldev);
lirc->ldev = NULL;
return 0;
......
This diff is collapsed.
......@@ -184,10 +184,8 @@ static void release_ir_device(struct kref *ref)
* ir->open_count == 0 - happens on final close()
* ir_lock, tx_ref_lock, rx_ref_lock, all released
*/
if (ir->l) {
if (ir->l)
lirc_unregister_device(ir->l);
lirc_free_device(ir->l);
}
if (kfifo_initialized(&ir->rbuf.fifo))
lirc_buffer_free(&ir->rbuf);
......@@ -318,7 +316,7 @@ static int add_to_buf(struct IR *ir)
int ret;
int failures = 0;
unsigned char sendbuf[1] = { 0 };
struct lirc_buffer *rbuf = ir->l->rbuf;
struct lirc_buffer *rbuf = ir->l->buf;
struct IR_rx *rx;
struct IR_tx *tx;
......@@ -464,7 +462,7 @@ static int add_to_buf(struct IR *ir)
static int lirc_thread(void *arg)
{
struct IR *ir = arg;
struct lirc_buffer *rbuf = ir->l->rbuf;
struct lirc_buffer *rbuf = ir->l->buf;
dev_dbg(ir->dev, "poll thread started\n");
......@@ -885,7 +883,7 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
{
struct IR *ir = lirc_get_pdata(filep);
struct IR_rx *rx;
struct lirc_buffer *rbuf = ir->l->rbuf;
struct lirc_buffer *rbuf = ir->l->buf;
int ret = 0, written = 0, retries = 0;
unsigned int m;
DECLARE_WAITQUEUE(wait, current);
......@@ -1203,7 +1201,7 @@ static unsigned int poll(struct file *filep, poll_table *wait)
{
struct IR *ir = lirc_get_pdata(filep);
struct IR_rx *rx;
struct lirc_buffer *rbuf = ir->l->rbuf;
struct lirc_buffer *rbuf = ir->l->buf;
unsigned int ret;
dev_dbg(ir->dev, "%s called\n", __func__);
......@@ -1449,6 +1447,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
ir->l->code_length = 13;
ir->l->fops = &lirc_fops;
ir->l->owner = THIS_MODULE;
ir->l->dev.parent = &adap->dev;
/*
* FIXME this is a pointer reference to us, but no refcount.
......@@ -1456,13 +1455,12 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
* This OK for now, since lirc_dev currently won't touch this
* buffer as we provide our own lirc_fops.
*
* Currently our own lirc_fops rely on this ir->l->rbuf pointer
* Currently our own lirc_fops rely on this ir->l->buf pointer
*/
ir->l->rbuf = &ir->rbuf;
ir->l->dev = &adap->dev;
ir->l->buf = &ir->rbuf;
/* This will be returned by lirc_get_pdata() */
ir->l->data = ir;
ret = lirc_buffer_init(ir->l->rbuf, 2, BUFLEN / 2);
ret = lirc_buffer_init(ir->l->buf, 2, BUFLEN / 2);
if (ret) {
lirc_free_device(ir->l);
ir->l = NULL;
......
......@@ -17,6 +17,8 @@
#include <linux/poll.h>
#include <linux/kfifo.h>
#include <media/lirc.h>
#include <linux/device.h>
#include <linux/cdev.h>
struct lirc_buffer {
wait_queue_head_t wait_poll;
......@@ -127,14 +129,19 @@ static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
* LIRC_CAN_SET_REC_TIMEOUT is defined.
* @max_timeout: Maximum timeout for record. Valid only if
* LIRC_CAN_SET_REC_TIMEOUT is defined.
* @rbuf: if not NULL, it will be used as a read buffer, you will
* @buf: if %NULL, lirc_dev will allocate and manage the buffer,
* otherwise allocated by the caller which will
* have to write to the buffer by other means, like irq's
* (see also lirc_serial.c).
* @buf_internal: whether lirc_dev has allocated the read buffer or not
* @rdev: &struct rc_dev associated with the device
* @fops: &struct file_operations for the device
* @dev: &struct device assigned to the device
* @owner: the module owning this struct
* @irctl: &struct irctl assigned to the device
* @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
* @cdev: &struct cdev assigned to the device
*/
struct lirc_dev {
char name[40];
......@@ -144,16 +151,23 @@ struct lirc_dev {
unsigned int buffer_size; /* in chunks holding one code each */
unsigned int chunk_size;
struct lirc_buffer *buf;
bool buf_internal;
void *data;
int min_timeout;
int max_timeout;
struct lirc_buffer *rbuf;
struct rc_dev *rdev;
const struct file_operations *fops;
struct device *dev;
struct module *owner;
struct irctl *irctl;
bool attached;
int open;
struct mutex mutex; /* protect from simultaneous accesses */
struct device dev;
struct cdev cdev;
};
struct lirc_dev *lirc_allocate_device(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment