Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1437600

[PATCH v3 02/15] [media] lirc_dev: allow bufferless driver registration

From Andi Shyti <andi.shyti@samsung.com>
Newsgroups linux.kernel
Subject [PATCH v3 02/15] [media] lirc_dev: allow bufferless driver registration
Date 2016-07-06 11:50 +0200
Message-ID <rRRCW-7w1-27@gated-at.bofh.it> (permalink)
References <rRRCW-7w1-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Transmitters don't necessarily need to have a FIFO managed buffer
for their transfers.

When registering the driver, before allocating the buffer, check
whether the device is a transmitter or receiver. Allocate the
buffer only for receivers.

Signed-off-by: Andi Shyti <andi.shyti@samsung.com>
---
 drivers/media/rc/lirc_dev.c | 40 ++++++++++++++++++++++++++++++----------
 1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 5716978..154e553 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,6 +388,23 @@ out_lock:
 out:
 	return err;
 }
+
+int lirc_register_driver(struct lirc_driver *d)
+{
+	int minor, err = 0;
+
+	minor = lirc_allocate_driver(d);
+	if (minor < 0)
+		return minor;
+
+	if (LIRC_CAN_REC(d->features)) {
+		err = lirc_allocate_buffer(irctls[minor]);
+		if (err)
+			lirc_unregister_driver(minor);
+	}
+
+	return err ? err : minor;
+}
 EXPORT_SYMBOL(lirc_register_driver);
 
 int lirc_unregister_driver(int minor)
-- 
2.8.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v3 00/15] lirc_dev fixes and beautification Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 10/15] [media] lirc_dev: remove compat_ioctl assignment Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 11/15] [media] lirc_dev: fix variable constant comparisons Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 07/15] [media] lirc_dev: simplify if statement in  lirc_add_to_buf Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 03/15] [media] lirc_dev: remove unnecessary debug prints Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 02/15] [media] lirc_dev: allow bufferless driver registration Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 15/15] [media] lirc_dev: use LIRC_CAN_REC() define to check  if the device can receive Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 06/15] [media] lirc_dev: do not use goto to create loops Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 12/15] [media] lirc_dev: fix error return value Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 04/15] [media] lirc_dev: replace printk with pr_* or dev_* Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 01/15] [media] lirc_dev: place buffer allocation on separate  function Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 05/15] [media] lirc_dev: simplify goto paths Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 08/15] [media] lirc_dev: remove double if ... else statement Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200
  [PATCH v3 09/15] [media] lirc_dev: merge three if statements in only  one Andi Shyti <andi.shyti@samsung.com> - 2016-07-06 11:50 +0200

csiph-web