Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1331801 > unrolled thread

[PATCH] regulator: ad5398: Fix return value of ad5398_write_reg

Started byAxel Lin <axel.lin@ingics.com>
First post2016-02-11 11:20 +0100
Last post2016-02-11 11:20 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] regulator: ad5398: Fix return value of ad5398_write_reg Axel Lin <axel.lin@ingics.com> - 2016-02-11 11:20 +0100

#1331801 — [PATCH] regulator: ad5398: Fix return value of ad5398_write_reg

FromAxel Lin <axel.lin@ingics.com>
Date2016-02-11 11:20 +0100
Subject[PATCH] regulator: ad5398: Fix return value of ad5398_write_reg
Message-ID<r0WvU-7lG-11@gated-at.bofh.it>
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>
---
 drivers/regulator/ad5398.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index ea50a88..8b0f788 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -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)
-- 
2.1.4

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web