From: moinejf@free.fr (Jean-Francois Moine)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 02/23] drm/i2c: tda998x: check more I/O errors
Date: Sun, 2 Feb 2014 18:30:00 +0100 [thread overview]
Message-ID: <20140202183000.1cf9ca9c@armhf> (raw)
In-Reply-To: <20140202162057.GE26684@n2100.arm.linux.org.uk>
On Sun, 2 Feb 2014 16:20:58 +0000
Russell King - ARM Linux <linux@arm.linux.org.uk> wrote:
> On Sat, Jan 25, 2014 at 06:14:45PM +0100, Jean-Francois Moine wrote:
> > This patch adds more error checking inn I2C I/O functions.
> > In case of I/O error, this permits to avoid writing in bad controller
> > pages, a bad chipset detection or looping when getting the EDID.
>
> I've just looked at this again, and spotted something:
>
> > -static uint8_t
> > +static int
> > reg_read(struct tda998x_priv *priv, uint16_t reg)
> > {
> > uint8_t val = 0;
> > - reg_read_range(priv, reg, &val, sizeof(val));
> > + int ret;
> > +
> > + ret = reg_read_range(priv, reg, &val, sizeof(val));
> > + if (ret < 0)
> > + return ret;
>
> So yes, this can return negative numbers.
>
> > @@ -1158,8 +1184,11 @@ tda998x_encoder_init(struct i2c_client *client,
> > tda998x_reset(priv);
> >
> > /* read version: */
> > - priv->rev = reg_read(priv, REG_VERSION_LSB) |
> > - reg_read(priv, REG_VERSION_MSB) << 8;
> > + ret = reg_read(priv, REG_VERSION_LSB) |
> > + (reg_read(priv, REG_VERSION_MSB) << 8);
> > + if (ret < 0)
> > + goto fail;
> > + priv->rev = ret;
>
> Two issues here:
>
> 1. The additional parens are /really/ not required.
> 2. What if reg_read(priv, REG_VERSION_MSB) returns a negative number?
>
> If we're going to the extent of attempting to make the read/write
> functions return errors, we should at least handle errors generated
> by them properly, otherwise it's pointless making them return errors.
>
> ret = reg_read(priv, REG_VERSION_LSB);
> if (ret < 0)
> goto fail;
>
> priv->rev = ret;
>
> ret = reg_read(priv, REG_VERSION_MSB);
> if (ret < 0)
> goto fail;
>
> priv->rev |= ret << 8;
>
> If you want it to look slightly nicer:
>
> int rev_lo, rev_hi;
>
> rev_lo = reg_read(priv, REG_VERSION_LSB);
> rev_hi = reg_read(priv, REG_VERSION_MSB);
> if (rev_lo < 0 || rev_hi < 0) {
> ret = rev_lo < 0 ? rev_lo : rev_hi;
> goto fail;
> }
>
> priv->rev = rev_lo | rev_hi << 8;
>
> I'm happy to commit such a change after this patch to clean it up, or if
> you want to regenerate your patch 2 and post /just/ that incorporating
> this change.
I think that my code works correctly: when there is an error, the
result of reg_read() is minus the error code, and this error code is
always lower than 8388607 (0x7fffff). Then, reg_read() << 8 will always
be negative.
Otherwise, I may redo a patch about the useless parenthesis.
--
Ken ar c'henta? | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
next prev parent reply other threads:[~2014-02-02 17:30 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-29 9:01 [PATCH v5 00/23] Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 17/23] drm/i2c: tda998x: set the PLL division factor in range 0..3 Jean-Francois Moine
2014-01-29 15:16 ` Joe Perches
2014-01-25 17:14 ` [PATCH v5 23/23] drm/i2c: tda998x: adjust the audio clock divider for S/PDIF Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 16/23] drm/i2c: tda998x: fix the ENABLE_SPACE register Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 15/23] drm/i2c: tda998x: add DT documentation Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 14/23] drm/i2c: tda998x: use irq for connection status and EDID read Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 13/23] drm/i2c: tda998x: always enable EDID read IRQ Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 22/23] drm/i2c: tda998x: code optimization Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 21/23] drm/i2c: tda998x: change the frequence in the audio channel Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 18/23] drm/i2c: tda998x: make the audio code more readable Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 19/23] drm/i2c: tda998x: remove the unused variable ca_i2s Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 20/23] drm/i2c: tda998x: add the active aspect in HDMI AVI frame Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 12/23] drm/i2c: tda998x: add DT support Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 08/23] drm/i2c: tda998x: use HDMI constants Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 09/23] drm/i2c: tda998x: don't read write-only registers Jean-Francois Moine
2014-02-02 16:23 ` Russell King - ARM Linux
2014-02-02 17:45 ` Jean-Francois Moine
2014-02-02 17:57 ` Russell King - ARM Linux
2014-01-25 17:14 ` [PATCH v5 10/23] drm/i2c: tda998x: free the CEC device on encoder_destroy Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 11/23] drm/i2c: tda998x: check the CEC device creation Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 07/23] drm/i2c: tda998x: fix bad value in the AIF Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 05/23] drm/i2c: tda998x: don't freeze the system at audio startup time Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 06/23] drm/i2c: tda998x: force the page register at " Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 02/23] drm/i2c: tda998x: check more I/O errors Jean-Francois Moine
2014-02-02 16:20 ` Russell King - ARM Linux
2014-02-02 17:30 ` Jean-Francois Moine [this message]
2014-02-02 17:56 ` Russell King - ARM Linux
2014-01-25 17:14 ` [PATCH v5 03/23] drm/i2c: tda998x: code cleanup Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 04/23] drm/i2c: tda998x: change probe message origin Jean-Francois Moine
2014-01-25 17:14 ` [PATCH v5 01/23] drm/i2c: tda998x: simplify the i2c read/write functions Jean-Francois Moine
2014-02-02 12:43 ` [PATCH v5 00/23] Russell King - ARM Linux
2014-02-02 18:04 ` Russell King - ARM Linux
2014-02-02 19:00 ` Jean-Francois Moine
2014-02-02 18:06 ` Jean-Francois Moine
2014-02-02 18:23 ` Russell King - ARM Linux
2014-02-02 18:41 ` Sebastian Hesselbarth
2014-02-02 18:54 ` Jean-Francois Moine
2014-02-02 19:15 ` Russell King - ARM Linux
2014-02-02 20:07 ` Jean-Francois Moine
2014-02-03 12:46 ` Mark Brown
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=20140202183000.1cf9ca9c@armhf \
--to=moinejf@free.fr \
--cc=linux-arm-kernel@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).