From: Yi Zeng <yizeng@asrmicro.com>
To: wsa@the-dreams.de, linux-i2c@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Yi Zeng <yizeng@asrmicro.com>
Subject: [PATCH] i2c: dev: prevent adapter retries being set as minus value
Date: Fri, 21 Dec 2018 17:32:06 +0800 [thread overview]
Message-ID: <1545384726-12463-1-git-send-email-yizeng@asrmicro.com> (raw)
If set adapter->retries to minus value from user space via ioctl,
will make __i2c_transfer and __i2c_smbus_xfer jump the calling to
adapter->algo->master_xfer and adapter->algo->smbus_xfer that
registered by the underlying bus drivers, and return value 0 to
all the callers. The bus driver will never be accessed anymore by
all users, besides, the users may still get successful return value
with no any error or information log print out.
Signed-off-by: Yi Zeng <yizeng@asrmicro.com>
---
drivers/i2c/i2c-dev.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 1aca742..c349f58 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -470,6 +470,14 @@ static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
data_arg.data);
}
case I2C_RETRIES:
+ /*
+ * The adapter->retries is defined as int type, and as
+ * the upper limit for times of i2c transfer retry when
+ * get -EAGAIN, it should not be set as minus value.
+ */
+ if ((int)arg < 0)
+ return -EINVAL;
+
client->adapter->retries = arg;
break;
case I2C_TIMEOUT:
--
1.9.1
next reply other threads:[~2018-12-21 9:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-21 9:32 Yi Zeng [this message]
2019-01-03 19:30 ` [PATCH] i2c: dev: prevent adapter retries being set as minus value Wolfram Sang
2019-01-07 12:36 ` Zeng Yi(曾毅)
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=1545384726-12463-1-git-send-email-yizeng@asrmicro.com \
--to=yizeng@asrmicro.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wsa@the-dreams.de \
/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).