regulator: ad5398: Fix return value of ad5398_write_reg
authorAxel Lin <axel.lin@ingics.com>
Thu, 11 Feb 2016 10:17:03 +0000 (18:17 +0800)
committerMark Brown <broonie@kernel.org>
Fri, 19 Feb 2016 16:02:34 +0000 (01:02 +0900)
i2c_master_send() returns the number of bytes written on success.
So current code returns 2 if ad5398_write_reg() success.
This return value is propagated to .set_current_limit, .enable and .disable
callbacks of regulator_ops. This can be a problem, for example, if the
users test if the return value of regulator_set_current_limit() is 0.
Fix it by making ad5398_write_reg() return 0 on success.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Acked-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/ad5398.c

index ea50a886ba6397f9dd185125d99f19e238357e6a..8b0f788a9bbb61afb97390097b83458681e6c94c 100644 (file)
@@ -58,10 +58,12 @@ static int ad5398_write_reg(struct i2c_client *client, const unsigned short data
 
        val = cpu_to_be16(data);
        ret = i2c_master_send(client, (char *)&val, 2);
-       if (ret < 0)
+       if (ret != 2) {
                dev_err(&client->dev, "I2C write error\n");
+               return ret < 0 ? ret : -EIO;
+       }
 
-       return ret;
+       return 0;
 }
 
 static int ad5398_get_current_limit(struct regulator_dev *rdev)