aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2017-06-25 08:31:45 -0400
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>2017-10-04 12:53:32 -0400
commitb145ef94f63e02c2615ffde61a376b53f3367bc6 (patch)
tree259deba6c2ad61c67adf9ca78253e967c56ae55d
parent615cd3fe6cccb950b46728120009a1805cce908e (diff)
[media] media: lirc_dev: make chunk_size and buffer_size mandatory
Make setting chunk_size and buffer_size mandatory for drivers which expect lirc_dev to allocate the lirc_buffer (i.e. ir-lirc-codec) and don't set them in lirc-zilog (which creates its own buffer). Also remove an unnecessary copy of chunk_size in struct irctl (the same information is already available from struct lirc_buffer). Signed-off-by: David Härdeman <david@hardeman.nu> Signed-off-by: Sean Young <sean@mess.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
-rw-r--r--drivers/media/rc/lirc_dev.c26
-rw-r--r--drivers/staging/media/lirc/lirc_zilog.c5
-rw-r--r--include/media/lirc_dev.h9
3 files changed, 19 insertions, 21 deletions
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index ffa203eb2045..1915ffc52955 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -41,7 +41,6 @@ struct irctl {
41 struct mutex irctl_lock; 41 struct mutex irctl_lock;
42 struct lirc_buffer *buf; 42 struct lirc_buffer *buf;
43 bool buf_internal; 43 bool buf_internal;
44 unsigned int chunk_size;
45 44
46 struct device dev; 45 struct device dev;
47 struct cdev cdev; 46 struct cdev cdev;
@@ -74,16 +73,8 @@ static void lirc_release(struct device *ld)
74static int lirc_allocate_buffer(struct irctl *ir) 73static int lirc_allocate_buffer(struct irctl *ir)
75{ 74{
76 int err = 0; 75 int err = 0;
77 int bytes_in_key;
78 unsigned int chunk_size;
79 unsigned int buffer_size;
80 struct lirc_driver *d = &ir->d; 76 struct lirc_driver *d = &ir->d;
81 77
82 bytes_in_key = BITS_TO_LONGS(d->code_length) +
83 (d->code_length % 8 ? 1 : 0);
84 buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key;
85 chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key;
86
87 if (d->rbuf) { 78 if (d->rbuf) {
88 ir->buf = d->rbuf; 79 ir->buf = d->rbuf;
89 ir->buf_internal = false; 80 ir->buf_internal = false;
@@ -94,7 +85,7 @@ static int lirc_allocate_buffer(struct irctl *ir)
94 goto out; 85 goto out;
95 } 86 }
96 87
97 err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); 88 err = lirc_buffer_init(ir->buf, d->chunk_size, d->buffer_size);
98 if (err) { 89 if (err) {
99 kfree(ir->buf); 90 kfree(ir->buf);
100 ir->buf = NULL; 91 ir->buf = NULL;
@@ -104,7 +95,6 @@ static int lirc_allocate_buffer(struct irctl *ir)
104 ir->buf_internal = true; 95 ir->buf_internal = true;
105 d->rbuf = ir->buf; 96 d->rbuf = ir->buf;
106 } 97 }
107 ir->chunk_size = ir->buf->chunk_size;
108 98
109out: 99out:
110 return err; 100 return err;
@@ -131,6 +121,16 @@ int lirc_register_driver(struct lirc_driver *d)
131 return -EINVAL; 121 return -EINVAL;
132 } 122 }
133 123
124 if (!d->rbuf && d->chunk_size < 1) {
125 pr_err("chunk_size must be set!\n");
126 return -EINVAL;
127 }
128
129 if (!d->rbuf && d->buffer_size < 1) {
130 pr_err("buffer_size must be set!\n");
131 return -EINVAL;
132 }
133
134 if (d->code_length < 1 || d->code_length > (BUFLEN * 8)) { 134 if (d->code_length < 1 || d->code_length > (BUFLEN * 8)) {
135 dev_err(d->dev, "code length must be less than %d bits\n", 135 dev_err(d->dev, "code length must be less than %d bits\n",
136 BUFLEN * 8); 136 BUFLEN * 8);
@@ -407,7 +407,7 @@ ssize_t lirc_dev_fop_read(struct file *file,
407 407
408 dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor); 408 dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor);
409 409
410 buf = kzalloc(ir->chunk_size, GFP_KERNEL); 410 buf = kzalloc(ir->buf->chunk_size, GFP_KERNEL);
411 if (!buf) 411 if (!buf)
412 return -ENOMEM; 412 return -ENOMEM;
413 413
@@ -420,7 +420,7 @@ ssize_t lirc_dev_fop_read(struct file *file,
420 goto out_locked; 420 goto out_locked;
421 } 421 }
422 422
423 if (length % ir->chunk_size) { 423 if (length % ir->buf->chunk_size) {
424 ret = -EINVAL; 424 ret = -EINVAL;
425 goto out_locked; 425 goto out_locked;
426 } 426 }
diff --git a/drivers/staging/media/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c
index c4a4c2f93ae8..780b2d9f2f4b 100644
--- a/drivers/staging/media/lirc/lirc_zilog.c
+++ b/drivers/staging/media/lirc/lirc_zilog.c
@@ -1348,8 +1348,6 @@ static const struct file_operations lirc_fops = {
1348static struct lirc_driver lirc_template = { 1348static struct lirc_driver lirc_template = {
1349 .name = "lirc_zilog", 1349 .name = "lirc_zilog",
1350 .code_length = 13, 1350 .code_length = 13,
1351 .buffer_size = BUFLEN / 2,
1352 .chunk_size = 2,
1353 .fops = &lirc_fops, 1351 .fops = &lirc_fops,
1354 .owner = THIS_MODULE, 1352 .owner = THIS_MODULE,
1355}; 1353};
@@ -1456,8 +1454,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1456 ir->l.dev = &adap->dev; 1454 ir->l.dev = &adap->dev;
1457 /* This will be returned by lirc_get_pdata() */ 1455 /* This will be returned by lirc_get_pdata() */
1458 ir->l.data = ir; 1456 ir->l.data = ir;
1459 ret = lirc_buffer_init(ir->l.rbuf, 1457 ret = lirc_buffer_init(ir->l.rbuf, 2, BUFLEN / 2);
1460 ir->l.chunk_size, ir->l.buffer_size);
1461 if (ret) 1458 if (ret)
1462 goto out_put_ir; 1459 goto out_put_ir;
1463 } 1460 }
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
index d07a53232ffc..8e3894e2d2c8 100644
--- a/include/media/lirc_dev.h
+++ b/include/media/lirc_dev.h
@@ -121,13 +121,14 @@ static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf,
121 * 121 *
122 * @code_length: length of the remote control key code expressed in bits. 122 * @code_length: length of the remote control key code expressed in bits.
123 * 123 *
124 * @buffer_size: Number of FIFO buffers with @chunk_size size. If zero,
125 * creates a buffer with BUFLEN size (16 bytes).
126 *
127 * @features: lirc compatible hardware features, like LIRC_MODE_RAW, 124 * @features: lirc compatible hardware features, like LIRC_MODE_RAW,
128 * LIRC_CAN\_\*, as defined at include/media/lirc.h. 125 * LIRC_CAN\_\*, as defined at include/media/lirc.h.
129 * 126 *
127 * @buffer_size: Number of FIFO buffers with @chunk_size size.
128 * Only used if @rbuf is NULL.
129 *
130 * @chunk_size: Size of each FIFO buffer. 130 * @chunk_size: Size of each FIFO buffer.
131 * Only used if @rbuf is NULL.
131 * 132 *
132 * @data: it may point to any driver data and this pointer will 133 * @data: it may point to any driver data and this pointer will
133 * be passed to all callback functions. 134 * be passed to all callback functions.
@@ -162,9 +163,9 @@ struct lirc_driver {
162 char name[40]; 163 char name[40];
163 unsigned int minor; 164 unsigned int minor;
164 __u32 code_length; 165 __u32 code_length;
165 unsigned int buffer_size; /* in chunks holding one code each */
166 __u32 features; 166 __u32 features;
167 167
168 unsigned int buffer_size; /* in chunks holding one code each */
168 unsigned int chunk_size; 169 unsigned int chunk_size;
169 170
170 void *data; 171 void *data;