linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v7 3/4] i2c: add param sanity check to i2c_transfer()
Date: Tue,  3 Apr 2018 21:11:50 +0200	[thread overview]
Message-ID: <20180403191151.14924-4-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20180403191151.14924-1-ard.biesheuvel@linaro.org>

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(+)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index c8bfe008f208..e2ca5c331ecb 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 (WARN_ON(!msgs || num <= 0))
+		return -EINVAL;
+
 	if (adap->quirks && i2c_check_for_quirks(adap, msgs, num))
 		return -EOPNOTSUPP;
 
-- 
2.15.1

  parent reply	other threads:[~2018-04-03 19:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03 19:11 [PATCH v7 0/4] add support for Socionext SynQuacer I2C controller Ard Biesheuvel
2018-04-03 19:11 ` [PATCH v7 1/4] dt-bindings: i2c: add binding for Socionext SynQuacer I2C Ard Biesheuvel
2018-04-04 18:35   ` Wolfram Sang
2018-04-03 19:11 ` [PATCH v7 2/4] i2c: add support for Socionext SynQuacer I2C controller Ard Biesheuvel
2018-04-04 18:35   ` Wolfram Sang
2018-04-03 19:11 ` Ard Biesheuvel [this message]
2018-04-04 18:38   ` [PATCH v7 3/4] i2c: add param sanity check to i2c_transfer() Wolfram Sang
2018-04-04 21:01     ` Ard Biesheuvel
2018-04-03 19:11 ` [PATCH v7 4/4] MAINTAINERS: add Ard as Socionext SynQuacer I2C driver maintainer Ard Biesheuvel
2018-04-04 18:37   ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180403191151.14924-4-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).