From: Andi Shyti <andi.shyti@samsung.com>
To: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Andi Shyti <andi.shyti@samsung.com>,
Andi Shyti <andi@etezian.org>
Subject: [PATCH 02/15] lirc_dev: allow bufferless driver registration
Date: Wed, 29 Jun 2016 22:20:31 +0900 [thread overview]
Message-ID: <1467206444-9935-3-git-send-email-andi.shyti@samsung.com> (raw)
In-Reply-To: <1467206444-9935-1-git-send-email-andi.shyti@samsung.com>
Some drivers don't necessarily need to have a FIFO managed buffer
for their transfers. Drivers now should call
lirc_register_bufferless_driver in order to handle the buffer
themselves.
The function works exaclty like lirc_register_driver except of
the buffer allocation.
Signed-off-by: Andi Shyti <andi.shyti@samsung.com>
---
drivers/media/rc/lirc_dev.c | 44 ++++++++++++++++++++++++++++++++++----------
include/media/lirc_dev.h | 12 ++++++++++++
2 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 5716978..fa562a3 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -205,12 +205,14 @@ err_out:
static int lirc_allocate_buffer(struct irctl *ir)
{
- int err;
+ int err = 0;
int bytes_in_key;
unsigned int chunk_size;
unsigned int buffer_size;
struct lirc_driver *d = &ir->d;
+ mutex_lock(&lirc_dev_lock);
+
bytes_in_key = BITS_TO_LONGS(d->code_length) +
(d->code_length % 8 ? 1 : 0);
buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key;
@@ -220,21 +222,26 @@ static int lirc_allocate_buffer(struct irctl *ir)
ir->buf = d->rbuf;
} else {
ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL);
- if (!ir->buf)
- return -ENOMEM;
+ if (!ir->buf) {
+ err = -ENOMEM;
+ goto out;
+ }
err = lirc_buffer_init(ir->buf, chunk_size, buffer_size);
if (err) {
kfree(ir->buf);
- return err;
+ goto out;
}
}
ir->chunk_size = ir->buf->chunk_size;
- return 0;
+out:
+ mutex_unlock(&lirc_dev_lock);
+
+ return err;
}
-int lirc_register_driver(struct lirc_driver *d)
+static int lirc_allocate_driver(struct lirc_driver *d)
{
struct irctl *ir;
int minor;
@@ -342,10 +349,6 @@ int lirc_register_driver(struct lirc_driver *d)
/* some safety check 8-) */
d->name[sizeof(d->name)-1] = '\0';
- err = lirc_allocate_buffer(ir);
- if (err)
- goto out_lock;
-
if (d->features == 0)
d->features = LIRC_CAN_REC_LIRCCODE;
@@ -385,8 +388,29 @@ out_lock:
out:
return err;
}
+
+int lirc_register_driver(struct lirc_driver *d)
+{
+ int err, minor;
+
+ minor = lirc_allocate_driver(d);
+ if (minor < 0)
+ return minor;
+
+ err = lirc_allocate_buffer(irctls[minor]);
+ if (err)
+ lirc_unregister_driver(minor);
+
+ return err ? err : minor;
+}
EXPORT_SYMBOL(lirc_register_driver);
+int lirc_register_bufferless_driver(struct lirc_driver *d)
+{
+ return lirc_allocate_driver(d);
+}
+EXPORT_SYMBOL(lirc_register_bufferless_driver);
+
int lirc_unregister_driver(int minor)
{
struct irctl *ir;
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
index 0ab59a5..8bed57a 100644
--- a/include/media/lirc_dev.h
+++ b/include/media/lirc_dev.h
@@ -214,6 +214,18 @@ struct lirc_driver {
*/
extern int lirc_register_driver(struct lirc_driver *d);
+/* int lirc_register_bufferless_driver - allocates a lirc bufferless driver
+ * @d: reference to the lirc_driver to initialize
+ *
+ * The difference between lirc_register_driver and
+ * lirc_register_bufferless_driver is that the latter doesn't allocate any
+ * buffer, which means that the driver using the lirc_driver should take care of
+ * it by itself.
+ *
+ * returns 0 on success or a the negative errno number in case of failure.
+ */
+extern int lirc_register_bufferless_driver(struct lirc_driver *d);
+
/* returns negative value on error or 0 if success
*/
extern int lirc_unregister_driver(int minor);
--
2.8.1
next prev parent reply other threads:[~2016-06-29 13:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-29 13:20 [PATCH 00/15] lirc_dev fixes and beautification Andi Shyti
2016-06-29 13:20 ` [PATCH 01/15] lirc_dev: place buffer allocation on separate function Andi Shyti
2016-06-29 13:20 ` Andi Shyti [this message]
2016-06-29 13:20 ` [PATCH 03/15] lirc_dev: remove unnecessary debug prints Andi Shyti
2016-06-29 13:20 ` [PATCH 04/15] lirc_dev: replace printk with pr_* or dev_* Andi Shyti
2016-06-30 0:27 ` Joe Perches
2016-06-29 13:20 ` [PATCH 05/15] lirc_dev: simplify goto paths Andi Shyti
2016-06-29 13:20 ` [PATCH 06/15] lirc_dev: do not use goto to create loops Andi Shyti
2016-06-29 13:20 ` [PATCH 07/15] lirc_dev: simplify if statement in lirc_add_to_buf Andi Shyti
2016-06-29 13:20 ` [PATCH 08/15] lirc_dev: remove double if ... else statement Andi Shyti
2016-06-29 13:20 ` [PATCH 09/15] lirc_dev: merge three if statements in only one Andi Shyti
2016-06-29 13:20 ` [PATCH 10/15] lirc_dev: remove CONFIG_COMPAT precompiler check Andi Shyti
2016-06-29 13:20 ` [PATCH 11/15] lirc_dev: fix variable constant comparisons Andi Shyti
2016-06-29 13:20 ` [PATCH 12/15] lirc_dev: fix error return value Andi Shyti
2016-06-29 13:20 ` [PATCH 13/15] lirc_dev: extremely trivial comment style fix Andi Shyti
2016-06-29 13:20 ` [PATCH 14/15] lirc_dev: fix potential segfault Andi Shyti
2016-06-29 13:20 ` [PATCH 15/15] include: lirc: add set length and frequency ioctl options Andi Shyti
2016-06-29 22:46 ` Sean Young
2016-06-29 23:35 ` Andi Shyti
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1467206444-9935-3-git-send-email-andi.shyti@samsung.com \
--to=andi.shyti@samsung.com \
--cc=andi@etezian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@osg.samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).