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


Groups > linux.kernel > #1614572

[PATCH] i2c: make sure i2c_master_send/recv return negative error codes

From Dmitry Torokhov <dmitry.torokhov@gmail.com>
Newsgroups linux.kernel
Subject [PATCH] i2c: make sure i2c_master_send/recv return negative error codes
Date 2017-04-01 20:00 +0200
Message-ID <trvtD-5Vh-15@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


There is theoretical possibility that i2c_master_send() and
i2c_master_recv() may return non-negative result on error: we pass
return values from i2c_xfer() unmodified to the caller, unless we
transferred exactly 1 message. Let's ensure we always return negative on
error.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/i2c/i2c-core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6efeba42d10b..34b0482333f4 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -2835,7 +2835,10 @@ int i2c_master_send(const struct i2c_client *client, const void *buf, int count)
 	 * If everything went ok (i.e. 1 msg transmitted), return #bytes
 	 * transmitted, else error code.
 	 */
-	return (ret == 1) ? count : ret;
+	if (likely(ret == 1))
+		return count;
+
+	return ret < 0 ? ret : -EIO;
 }
 EXPORT_SYMBOL(i2c_master_send);
 
@@ -2865,7 +2868,10 @@ int i2c_master_recv(const struct i2c_client *client, void *buf, int count)
 	 * If everything went ok (i.e. 1 msg received), return #bytes received,
 	 * else error code.
 	 */
-	return (ret == 1) ? count : ret;
+	if (likely(ret == 1))
+		return count;
+
+	return ret < 0 ? ret : -EIO;
 }
 EXPORT_SYMBOL(i2c_master_recv);
 
-- 
2.12.2.564.g063fe858b8-goog


-- 
Dmitry

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] i2c: make sure i2c_master_send/recv return negative error  codes Dmitry Torokhov <dmitry.torokhov@gmail.com> - 2017-04-01 20:00 +0200

csiph-web