public inbox for patches@lists.linux.dev
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Ansuel Smith <ansuelsmth@gmail.com>,
	Jim Wylder <jwylder@google.com>,  Xu Yilun <yilun.xu@intel.com>,
	matthew.gerlach@linux.intel.com,  Mark Brown <broonie@kernel.org>
Cc: stable@kernel.org
Subject: [PATCH 2/2] regmap: Account for register length in SMBus I/O limits
Date: Wed, 12 Jul 2023 12:16:40 +0100	[thread overview]
Message-ID: <20230712-regmap-max-transfer-v1-2-80e2aed22e83@kernel.org> (raw)
In-Reply-To: <20230712-regmap-max-transfer-v1-0-80e2aed22e83@kernel.org>

The SMBus I2C buses have limits on the size of transfers they can do but
do not factor in the register length meaning we may try to do a transfer
longer than our length limit, the core will not take care of this.
Future changes will factor this out into the core but there are a number
of users that assume current behaviour so let's just do something
conservative here.

This does not take account padding bits but practically speaking these
are very rarely if ever used on I2C buses given that they generally run
slowly enough to mean there's no issue.

Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@kernel.org
---
 drivers/base/regmap/regmap-i2c.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regmap-i2c.c b/drivers/base/regmap/regmap-i2c.c
index 980e5ce6a3a3..3ec611dc0c09 100644
--- a/drivers/base/regmap/regmap-i2c.c
+++ b/drivers/base/regmap/regmap-i2c.c
@@ -242,8 +242,8 @@ static int regmap_i2c_smbus_i2c_read(void *context, const void *reg,
 static const struct regmap_bus regmap_i2c_smbus_i2c_block = {
 	.write = regmap_i2c_smbus_i2c_write,
 	.read = regmap_i2c_smbus_i2c_read,
-	.max_raw_read = I2C_SMBUS_BLOCK_MAX,
-	.max_raw_write = I2C_SMBUS_BLOCK_MAX,
+	.max_raw_read = I2C_SMBUS_BLOCK_MAX - 1,
+	.max_raw_write = I2C_SMBUS_BLOCK_MAX - 1,
 };
 
 static int regmap_i2c_smbus_i2c_write_reg16(void *context, const void *data,
@@ -299,8 +299,8 @@ static int regmap_i2c_smbus_i2c_read_reg16(void *context, const void *reg,
 static const struct regmap_bus regmap_i2c_smbus_i2c_block_reg16 = {
 	.write = regmap_i2c_smbus_i2c_write_reg16,
 	.read = regmap_i2c_smbus_i2c_read_reg16,
-	.max_raw_read = I2C_SMBUS_BLOCK_MAX,
-	.max_raw_write = I2C_SMBUS_BLOCK_MAX,
+	.max_raw_read = I2C_SMBUS_BLOCK_MAX - 2,
+	.max_raw_write = I2C_SMBUS_BLOCK_MAX - 2,
 };
 
 static const struct regmap_bus *regmap_get_i2c_bus(struct i2c_client *i2c,

-- 
2.39.2


      parent reply	other threads:[~2023-07-15 11:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12 11:16 [PATCH 0/2] regmap: Redo fixes for raw I/O length restrictions Mark Brown
2023-07-12 11:16 ` [PATCH 1/2] regmap: Drop initial version of maximum transfer length fixes Mark Brown
2023-07-12 11:16 ` Mark Brown [this message]

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=20230712-regmap-max-transfer-v1-2-80e2aed22e83@kernel.org \
    --to=broonie@kernel.org \
    --cc=ansuelsmth@gmail.com \
    --cc=jwylder@google.com \
    --cc=matthew.gerlach@linux.intel.com \
    --cc=stable@kernel.org \
    --cc=yilun.xu@intel.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