Thread (19 messages) 19 messages, 2 authors, 2018-04-04
STALE2981d
Revisions (6)
  1. v6 current
  2. v6 [diff vs current]
  3. v6 [diff vs current]
  4. v7 [diff vs current]
  5. v7 [diff vs current]
  6. v7 [diff vs current]

[PATCH v6 3/3] i2c: add param sanity check to i2c_transfer()

From: Ard Biesheuvel <hidden>
Date: 2018-03-25 11:07:47
Also in: linux-i2c
Subsystem: i2c subsystem, the rest · Maintainers: Wolfram Sang, Linus Torvalds

The API docs describe i2c_transfer() as taking a pointer to an array
of i2c_msg containing at least 1 entry, but leaves it to the individual
drivers to sanity check the msgs and num parameters. Let's do this in
core code instead.

Signed-off-by: Ard Biesheuvel <redacted>
---
 drivers/i2c/i2c-core-base.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index c8bfe008f208..dfc549cf0ac2 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1845,6 +1845,9 @@ int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	unsigned long orig_jiffies;
 	int ret, try;
 
+	if (!msgs || num < 1)
+		return -EINVAL;
+
 	if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
 		return -EOPNOTSUPP;
 
-- 
2.15.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help