All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <khali@linux-fr.org>
To: Mauro Carvalho Chehab <mchehab@redhat.com>
Cc: LMML <linux-media@vger.kernel.org>, Steven Toth <stoth@kernellabs.com>
Subject: [PATCH 1/5 v2] cx22702: Clean up register access functions
Date: Fri, 10 Sep 2010 19:03:07 +0200	[thread overview]
Message-ID: <20100910190307.022fca56@hyperion.delvare> (raw)
In-Reply-To: <4C8A4B1C.8010002@redhat.com>

Hi Mauro,

On Fri, 10 Sep 2010 12:13:32 -0300, Mauro Carvalho Chehab wrote:
> Em 10-09-2010 10:27, Jean Delvare escreveu:
> > * Avoid temporary variables.
> > * Optimize success paths.
> > * Make error messages consistently verbose.
> > 
> > Signed-off-by: Jean Delvare <khali@linux-fr.org>
> > Cc: Steven Toth <stoth@kernellabs.com>
> > ---
> >  drivers/media/dvb/frontends/cx22702.c |   23 +++++++++++++----------
> >  1 file changed, 13 insertions(+), 10 deletions(-)
> > 
> > --- linux-2.6.32-rc5.orig/drivers/media/dvb/frontends/cx22702.c	2009-10-16 09:47:14.000000000 +0200
> > +++ linux-2.6.32-rc5/drivers/media/dvb/frontends/cx22702.c	2009-10-16 09:47:45.000000000 +0200
> > @@ -92,33 +92,36 @@ static int cx22702_writereg(struct cx227
> >  
> >  	ret = i2c_transfer(state->i2c, &msg, 1);
> >  
> > -	if (ret != 1)
> > +	if (ret != 1) {
> 
> As a suggestion, if you want to optimize success paths, you should use unlikely() for error
> checks. This tells gcc to optimize the code to avoid cache cleanups for the likely condition:
> 
> 	if (unlikely(ret != 1)) {

Good point. Updated patch follows:

* * * * *

* Avoid temporary variables.
* Optimize success paths.
* Make error messages consistently verbose.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Steven Toth <stoth@kernellabs.com>
---
Changes in v2:
* Use unlikely() to help gcc optimize the success paths.

 drivers/media/dvb/frontends/cx22702.c |   23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

--- linux-2.6.35.orig/drivers/media/dvb/frontends/cx22702.c	2010-09-10 14:22:31.000000000 +0200
+++ linux-2.6.35/drivers/media/dvb/frontends/cx22702.c	2010-09-10 17:39:58.000000000 +0200
@@ -92,33 +92,36 @@ static int cx22702_writereg(struct cx227
 
 	ret = i2c_transfer(state->i2c, &msg, 1);
 
-	if (ret != 1)
+	if (unlikely(ret != 1)) {
 		printk(KERN_ERR
 			"%s: error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
 			__func__, reg, data, ret);
+		return -1;
+	}
 
-	return (ret != 1) ? -1 : 0;
+	return 0;
 }
 
 static u8 cx22702_readreg(struct cx22702_state *state, u8 reg)
 {
 	int ret;
-	u8 b0[] = { reg };
-	u8 b1[] = { 0 };
+	u8 data;
 
 	struct i2c_msg msg[] = {
 		{ .addr = state->config->demod_address, .flags = 0,
-			.buf = b0, .len = 1 },
+			.buf = &reg, .len = 1 },
 		{ .addr = state->config->demod_address, .flags = I2C_M_RD,
-			.buf = b1, .len = 1 } };
+			.buf = &data, .len = 1 } };
 
 	ret = i2c_transfer(state->i2c, msg, 2);
 
-	if (ret != 2)
-		printk(KERN_ERR "%s: readreg error (ret == %i)\n",
-			__func__, ret);
+	if (unlikely(ret != 2)) {
+		printk(KERN_ERR "%s: error (reg == 0x%02x, ret == %i)\n",
+			__func__, reg, ret);
+		return 0;
+	}
 
-	return b1[0];
+	return data;
 }
 
 static int cx22702_set_inversion(struct cx22702_state *state, int inversion)




-- 
Jean Delvare

  reply	other threads:[~2010-09-10 17:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-10 13:19 [PATCH 0/5] Clean-ups to the cx22702 frontend driver Jean Delvare
2010-09-10 13:27 ` [PATCH 1/5] cx22702: Clean up register access functions Jean Delvare
2010-09-10 15:13   ` Mauro Carvalho Chehab
2010-09-10 17:03     ` Jean Delvare [this message]
2010-09-10 13:32 ` [PATCH 2/5] cx22702: Drop useless initializations to 0 Jean Delvare
2010-09-10 13:33 ` [PATCH 3/5] cx22702: Avoid duplicating code in branches Jean Delvare
2010-09-10 13:35 ` [PATCH 4/5] cx22702: Some things never change Jean Delvare
2010-09-10 13:36 ` [PATCH 5/5] cx22702: Simplify cx22702_set_tps() 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=20100910190307.022fca56@hyperion.delvare \
    --to=khali@linux-fr.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@redhat.com \
    --cc=stoth@kernellabs.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 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.