All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Michael Grzeschik <m.grzeschik@pengutronix.de>,
	linux-media@vger.kernel.org
Subject: Re: [PATCH 1/5] mt9m111: set inital return values to zero
Date: Sun, 17 Jul 2011 18:52:19 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.1107171844150.13485@axis700.grange> (raw)
In-Reply-To: <201107141725.21401.laurent.pinchart@ideasonboard.com>

On Thu, 14 Jul 2011, Laurent Pinchart wrote:

> Hi Michael,
> 
> There's no need to set initial return values to zero if they're assigned to in 
> all code paths.
> 
> [snip]
> 
> > *client) static int mt9m111_enable(struct i2c_client *client)
> >  {
> >  	struct mt9m111 *mt9m111 = to_mt9m111(client);
> > -	int ret;
> > +	int ret = 0;
> > 
> >  	ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE);
> >  	if (!ret)
> 
> This is a clear example, ret will never be used uninitialized. Initializing it 
> to 0 would be a waste of resources (although in this case it will probably be 
> optimized out by the compiler).

Seconded. When I wrote:

> > +static int mt9m111_reg_mask(struct i2c_client *client, const u16 reg,
> > +			    const u16 data, const u16 mask)
> > +{
> > +	int ret;
> > +
> > +	ret = mt9m111_reg_read(client, reg);
> > +	return mt9m111_reg_write(client, reg, (ret & ~mask) | data);
> 
> Ok, I feel ashamed, that I have accepted this driver in this form... It is 
> full of such buggy error handling instances, and this adds just one 
> more... So, I would very appreciate if you could clean them up - before 
> this patch, and handle this error properly too, otherwise I might do this 
> myself some time... And, just noticed - "static int lastpage" from 
> reg_page_map_set() must be moved into struct mt9m111, if this driver shall 
> be able to handle more than one sensor simultaneously, at least in 
> principle...

I didn't mean to init all return codes to 0. I meant, before using a 
result of a reg_read(), you have to check it for error. I.e.,

+	ret = mt9m111_reg_read(client, reg);
+	if (ret >= 0)
+		ret = mt9m111_reg_write(client, reg, (ret & ~mask) | data);
+	return ret;

In principle, after the updated version of your patch "mt9m111: rewrite 
set_pixfmt" all errors, returned by reg_read(), reg_write() and reg_mask() 
are checked, even if some of them I would do a bit differently. E.g., I 
would propagate the error code instead of replacing it with -EIO, etc. But 
in principle all error cases are handled, so, we can live with that for 
now. I'm dropping this patch.

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/

      reply	other threads:[~2011-07-17 16:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-12 15:39 [PATCH 1/5] mt9m111: set inital return values to zero Michael Grzeschik
2011-07-12 15:39 ` [PATCH 2/5] mt9m111: fix missing return value check mt9m111_reg_clear Michael Grzeschik
2011-07-17 16:54   ` Guennadi Liakhovetski
2011-07-12 15:39 ` [PATCH 3/5] mt9m111: move lastpage to struct mt9m111 for multi instances Michael Grzeschik
2011-07-14 15:27   ` Laurent Pinchart
2011-07-17 16:53     ` Guennadi Liakhovetski
2011-07-19 13:26   ` [PATCH v2] " Michael Grzeschik
2011-07-19 14:10     ` Guennadi Liakhovetski
2011-07-12 15:39 ` [PATCH v4 4/5] mt9m111: rewrite set_pixfmt Michael Grzeschik
2011-07-17 17:09   ` Guennadi Liakhovetski
2011-07-22 11:57     ` Michael Grzeschik
2011-07-12 15:39 ` [PATCH 5/5] mt9m111: make use of testpattern Michael Grzeschik
2011-07-17 16:55   ` Guennadi Liakhovetski
2011-07-14 15:25 ` [PATCH 1/5] mt9m111: set inital return values to zero Laurent Pinchart
2011-07-17 16:52   ` Guennadi Liakhovetski [this message]

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=Pine.LNX.4.64.1107171844150.13485@axis700.grange \
    --to=g.liakhovetski@gmx.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=m.grzeschik@pengutronix.de \
    /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.