lkml.org 
[lkml]   [2010]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 05/12] viafb: fix i2c_transfer error handling
    Date
    viafb: fix i2c_transfer error handling

    i2c_transfer returns negative errno on error and number of messages
    processed on success. Just returning this value would give a poor
    interface as it is not obvious that you must compare with 2 after reading
    1 or n bytes and with 1 after writing 1 byte to determine if it was
    successful. To avoid this error prone interface convert the error code
    of a successful read/write to zero and all other non-negative values to
    an negative error code.
    This fixes a regression introduced by
    via: Rationalize vt1636 detection
    which resulted in no longer detecting a VT1636 chip and therefore has
    broken the output in configurations wich contain this chip.

    Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
    Cc: Joseph Chan <JosephChan@via.com.tw>
    Cc: Jonathan Corbet <corbet@lwn.net>
    ---
    drivers/video/via/via_i2c.c | 27 ++++++++++++++++++++++++---
    1 files changed, 24 insertions(+), 3 deletions(-)

    diff --git a/drivers/video/via/via_i2c.c b/drivers/video/via/via_i2c.c
    index da9e4ca..021112e 100644
    --- a/drivers/video/via/via_i2c.c
    +++ b/drivers/video/via/via_i2c.c
    @@ -114,6 +114,7 @@ static void via_i2c_setsda(void *data, int state)

    int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
    {
    + int ret;
    u8 mm1[] = {0x00};
    struct i2c_msg msgs[2];

    @@ -126,11 +127,18 @@ int viafb_i2c_readbyte(u8 adap, u8 slave_addr, u8 index, u8 *pdata)
    mm1[0] = index;
    msgs[0].len = 1; msgs[1].len = 1;
    msgs[0].buf = mm1; msgs[1].buf = pdata;
    - return i2c_transfer(&via_i2c_par[adap].adapter, msgs, 2);
    + ret = i2c_transfer(&via_i2c_par[adap].adapter, msgs, 2);
    + if (ret == 2)
    + ret = 0;
    + else if (ret >= 0)
    + ret = -EIO;
    +
    + return ret;
    }

    int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data)
    {
    + int ret;
    u8 msg[2] = { index, data };
    struct i2c_msg msgs;

    @@ -140,11 +148,18 @@ int viafb_i2c_writebyte(u8 adap, u8 slave_addr, u8 index, u8 data)
    msgs.addr = slave_addr / 2;
    msgs.len = 2;
    msgs.buf = msg;
    - return i2c_transfer(&via_i2c_par[adap].adapter, &msgs, 1);
    + ret = i2c_transfer(&via_i2c_par[adap].adapter, &msgs, 1);
    + if (ret == 1)
    + ret = 0;
    + else if (ret >= 0)
    + ret = -EIO;
    +
    + return ret;
    }

    int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len)
    {
    + int ret;
    u8 mm1[] = {0x00};
    struct i2c_msg msgs[2];

    @@ -156,7 +171,13 @@ int viafb_i2c_readbytes(u8 adap, u8 slave_addr, u8 index, u8 *buff, int buff_len
    mm1[0] = index;
    msgs[0].len = 1; msgs[1].len = buff_len;
    msgs[0].buf = mm1; msgs[1].buf = buff;
    - return i2c_transfer(&via_i2c_par[adap].adapter, msgs, 2);
    + ret = i2c_transfer(&via_i2c_par[adap].adapter, msgs, 2);
    + if (ret == 2)
    + ret = 0;
    + else if (ret >= 0)
    + ret = -EIO;
    +
    + return ret;
    }

    /*
    --
    1.6.3.2


    \
     
     \ /
      Last update: 2010-09-19 09:25    [W:0.024 / U:32.256 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site