diff mbox

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

Message ID 20180325110747.8852-4-ard.biesheuvel@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Ard Biesheuvel March 25, 2018, 11:07 a.m. UTC
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 <ard.biesheuvel@linaro.org>
---
 drivers/i2c/i2c-core-base.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Wolfram Sang April 3, 2018, 3:03 p.m. UTC | #1
> +	if (!msgs || num < 1)
> +		return -EINVAL;

I think this case justifies WARN (or WARN_ON, I always mix them up).
Ard Biesheuvel April 3, 2018, 4:56 p.m. UTC | #2
On 3 April 2018 at 17:03, Wolfram Sang <wsa@the-dreams.de> wrote:
>> +     if (!msgs || num < 1)
>> +             return -EINVAL;
>
> I think this case justifies WARN (or WARN_ON, I always mix them up).
>

OK.
diff mbox

Patch

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;