All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarod Wilson <jarod@redhat.com>
To: Jean Delvare <khali@linux-fr.org>
Cc: linux-media@vger.kernel.org, Andy Walls <awalls@md.metrocast.net>,
	Janne Grunau <j@jannau.net>
Subject: Re: [PATCH] hdpvr: reduce latency of i2c read/write w/recycled buffer
Date: Fri, 14 Jan 2011 16:01:59 -0500	[thread overview]
Message-ID: <20110114210159.GC9849@redhat.com> (raw)
In-Reply-To: <20110114213524.16a74206@endymion.delvare>

On Fri, Jan 14, 2011 at 09:35:24PM +0100, Jean Delvare wrote:
> Hi Jarod,
> 
> On Fri, 14 Jan 2011 15:01:09 -0500, Jarod Wilson wrote:
> > The current hdpvr code kmalloc's a new buffer for every i2c read and
> > write. Rather than do that, lets allocate a buffer in the driver's
> > device struct and just use that every time.
> > 
> > The size I've chosen for the buffer is the maximum size I could
> > ascertain might be used by either ir-kbd-i2c or lirc_zilog, plus a bit
> > of padding (lirc_zilog may use up to 100 bytes on tx, rounded that up
> > to 128).
> 
> Definitely a good move, as discussed on IRC earlier this week.
> 
> > Note that this might also remedy user reports of very sluggish behavior
> > of IR receive with hdpvr hardware.
> 
> Maybe. But the fact that the Zilog is unresponsive during processing of
> sent data certainly contributes to this feeling too.

I believe this was the case even when tx wasn't in use, so I'm hopeful.


> > diff --git a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
> > index c0696c3..7f1a313 100644
> > --- a/drivers/media/video/hdpvr/hdpvr-i2c.c
> > +++ b/drivers/media/video/hdpvr/hdpvr-i2c.c
> > @@ -57,23 +57,18 @@ static int hdpvr_i2c_read(struct hdpvr_device *dev, int bus,
> >  			  unsigned char addr, char *data, int len)
> >  {
> >  	int ret;
> > -	char *buf = kmalloc(len, GFP_KERNEL);
> > -	if (!buf)
> > -		return -ENOMEM;
> >  
> >  	ret = usb_control_msg(dev->udev,
> >  			      usb_rcvctrlpipe(dev->udev, 0),
> >  			      REQTYPE_I2C_READ, CTRL_READ_REQUEST,
> > -			      (bus << 8) | addr, 0, buf, len, 1000);
> > +			      (bus << 8) | addr, 0, &dev->i2c_buf, len, 1000);
> 
> Shouldn't you first ensure that len <= sizeof(dev->i2c_buf)? It should
> hopefully always be the case, but... if it isn't, you'll corrupt your
> data structure and possibly more.
...
> > @@ -81,31 +76,26 @@ static int hdpvr_i2c_write(struct hdpvr_device *dev, int bus,
> >  			   unsigned char addr, char *data, int len)
> >  {
> >  	int ret;
> > -	char *buf = kmalloc(len, GFP_KERNEL);
> > -	if (!buf)
> > -		return -ENOMEM;
> >  
> > -	memcpy(buf, data, len);
> > +	memcpy(&dev->i2c_buf, data, len);
> 
> Same here.

Yeah, while it *shouldn't* happen, making sure seems prudent. v2 in a
moment.

-- 
Jarod Wilson
jarod@redhat.com


  reply	other threads:[~2011-01-14 21:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-14 20:01 [PATCH] hdpvr: reduce latency of i2c read/write w/recycled buffer Jarod Wilson
2011-01-14 20:35 ` Jean Delvare
2011-01-14 21:01   ` Jarod Wilson [this message]
2011-01-14 21:08 ` [PATCH v2] " Jarod Wilson
2011-01-14 21:14   ` Jean Delvare

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=20110114210159.GC9849@redhat.com \
    --to=jarod@redhat.com \
    --cc=awalls@md.metrocast.net \
    --cc=j@jannau.net \
    --cc=khali@linux-fr.org \
    --cc=linux-media@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.