aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/rc/lirc_dev.c
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 /drivers/media/rc/lirc_dev.c
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>
Diffstat (limited to 'drivers/media/rc/lirc_dev.c')
-rw-r--r--drivers/media/rc/lirc_dev.c26
1 files changed, 13 insertions, 13 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 }