linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Zhou,Junde" <junde.zhou@gmail.com>
To: wsa@kernel.org
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	zhoujd@clounix.com
Subject: [PATCH] check parameter for i2c driver interface and improve efficieny for the issues.
Date: Fri,  7 Jan 2022 10:45:24 +0800	[thread overview]
Message-ID: <20220107024524.2293-1-junde.zhou@gmail.com> (raw)

From: "Zhou,Junde" <zhoujd@clounix.com>

do parameter checking in drivers/i2c/i2c-core-smbus.c.

return -EINVAL when input parameter length is equal to 0.

Signed-off-by: Zhou,Junde <zhoujd@clounix.com>
---
 drivers/i2c/i2c-core-smbus.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index e5b2d1465e7e..9fbc96be6958 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -254,6 +254,8 @@ s32 i2c_smbus_write_block_data(const struct i2c_client *client, u8 command,
 
 	if (length > I2C_SMBUS_BLOCK_MAX)
 		length = I2C_SMBUS_BLOCK_MAX;
+	if (length == 0)
+		return -EINVAL;
 	data.block[0] = length;
 	memcpy(&data.block[1], values, length);
 	return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
@@ -271,6 +273,8 @@ s32 i2c_smbus_read_i2c_block_data(const struct i2c_client *client, u8 command,
 
 	if (length > I2C_SMBUS_BLOCK_MAX)
 		length = I2C_SMBUS_BLOCK_MAX;
+	if (length == 0)
+		return -EINVAL;
 	data.block[0] = length;
 	status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
 				I2C_SMBUS_READ, command,
@@ -290,6 +294,8 @@ s32 i2c_smbus_write_i2c_block_data(const struct i2c_client *client, u8 command,
 
 	if (length > I2C_SMBUS_BLOCK_MAX)
 		length = I2C_SMBUS_BLOCK_MAX;
+	if (length == 0)
+		return -EINVAL;
 	data.block[0] = length;
 	memcpy(data.block + 1, values, length);
 	return i2c_smbus_xfer(client->adapter, client->addr, client->flags,
-- 
2.25.1


                 reply	other threads:[~2022-01-07  2:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220107024524.2293-1-junde.zhou@gmail.com \
    --to=junde.zhou@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@kernel.org \
    --cc=zhoujd@clounix.com \
    /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).