public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: Andi Shyti <andi.shyti@samsung.com>
Cc: Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
	Joe Perches <joe@perches.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Andi Shyti <andi@etezian.org>
Subject: Re: [PATCH v2 02/15] [media] lirc_dev: allow bufferless driver registration
Date: Sat, 2 Jul 2016 18:10:47 +0100	[thread overview]
Message-ID: <20160702171047.GA13539@gofer.mess.org> (raw)
In-Reply-To: <1467360098-12539-3-git-send-email-andi.shyti@samsung.com>

On Fri, Jul 01, 2016 at 05:01:25PM +0900, Andi Shyti wrote:
> 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.

Indeed transmit-only devices don't need an input buffer, which is
just a waste of memory. However can't lirc_register_driver() figure
out from the features if the driver is capable of receiving, i.e.

int lirc_register_driver(struct lirc_driver *d)
{
	int err, minor;

	minor = lirc_allocate_driver(d);
	if (minor < 0)
		return minor;

	if (d->features & LIRC_CAN_REC_MODE2) {
		err = lirc_allocate_buffer(irctls[minor]);
		if (err)
			lirc_unregister_driver(minor);
	}

	return err ? err : minor;
}


Sean

> 
> 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

  reply	other threads:[~2016-07-02 17:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-01  8:01 [PATCH v2 00/15] lirc_dev fixes and beautification Andi Shyti
2016-07-01  8:01 ` [PATCH v2 01/15] [media] lirc_dev: place buffer allocation on separate function Andi Shyti
2016-07-01  8:01 ` [PATCH v2 02/15] [media] lirc_dev: allow bufferless driver registration Andi Shyti
2016-07-02 17:10   ` Sean Young [this message]
2016-07-01  8:01 ` [PATCH v2 03/15] [media] lirc_dev: remove unnecessary debug prints Andi Shyti
2016-07-01  8:01 ` [PATCH v2 04/15] [media] lirc_dev: replace printk with pr_* or dev_* Andi Shyti
2016-07-01  8:01 ` [PATCH v2 05/15] [media] lirc_dev: simplify goto paths Andi Shyti
2016-07-01  8:01 ` [PATCH v2 06/15] [media] lirc_dev: do not use goto to create loops Andi Shyti
2016-07-01  8:01 ` [PATCH v2 07/15] [media] lirc_dev: simplify if statement in lirc_add_to_buf Andi Shyti
2016-07-01  8:01 ` [PATCH v2 08/15] [media] lirc_dev: remove double if ... else statement Andi Shyti
2016-07-01  8:01 ` [PATCH v2 09/15] [media] lirc_dev: merge three if statements in only one Andi Shyti
2016-07-01  8:01 ` [PATCH v2 10/15] [media] lirc_dev: remove CONFIG_COMPAT precompiler check Andi Shyti
2016-07-04 11:39   ` Hans Verkuil
2016-07-01  8:01 ` [PATCH v2 11/15] [media] lirc_dev: fix variable constant comparisons Andi Shyti
2016-07-01  8:01 ` [PATCH v2 12/15] [media] lirc_dev: fix error return value Andi Shyti
2016-07-04 11:42   ` Hans Verkuil
2016-07-01  8:01 ` [PATCH v2 13/15] [media] lirc_dev: extremely trivial comment style fix Andi Shyti
2016-07-01  8:01 ` [PATCH v2 14/15] [media] lirc_dev: fix potential segfault Andi Shyti
2016-07-01  8:01 ` [PATCH v2 15/15] [media] include: lirc: add LIRC_GET_LENGTH command Andi Shyti
2016-07-01  9:27   ` Sean Young

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=20160702171047.GA13539@gofer.mess.org \
    --to=sean@mess.org \
    --cc=andi.shyti@samsung.com \
    --cc=andi@etezian.org \
    --cc=joe@perches.com \
    --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