[PATCH 3/5] hwmon: (pmbus/ltc2978) Use pmbus_read_smbus_i2c_block_data for block commands

Guenter Roeck <[email protected]> Mon, 3 Aug 2026 12:35:33 -0700
Newsgroups org.kernel.vger.linux-hwmon
Message-ID <[email protected]>
The driver uses a mix of pmbus_read_smbus_i2c_block_data() and
i2c_smbus_read_i2c_block_data() for PMBus block commands.

Use pmbus_read_smbus_i2c_block_data() instead to enable the driver to work
I2C controllers which do not support both block commands.

Drop the functionality check to simplify the code and to trigger a return
with -EOPNOTSUPP if SMBus block commands are not supported.

As part of this patch, rework detection of LT7170 and LT7171. The return
length of pmbus_read_smbus_i2c_block_data() may be less than the requested
number of bytes, meaning the return length needs to be checked. Also,
checking for "LT7170-1" after checking for "LT7170" and checking for
"LT7171-1" after checking for "LT7171" is pointless since the first check
will already produce a match, so drop the second part of the check.

Cc: Alexis Czezar Torreno <[email protected]>
Cc: Nuno Sá <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
---
 drivers/hwmon/pmbus/ltc2978.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c
index 10877b0867fd..aea7b6c93e74 100644
--- a/drivers/hwmon/pmbus/ltc2978.c
+++ b/drivers/hwmon/pmbus/ltc2978.c
@@ -611,17 +611,13 @@ static int ltc2978_get_id(struct i2c_client *client)
 		u8 buf[I2C_SMBUS_BLOCK_MAX];
 		int ret;
 
-		if (!i2c_check_functionality(client->adapter,
-					     I2C_FUNC_SMBUS_READ_BLOCK_DATA))
-			return -ENODEV;
-
-		ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, buf);
+		ret = pmbus_read_smbus_i2c_block_data(client, PMBUS_MFR_ID, buf);
 		if (ret < 0)
 			return ret;
 		if (ret < 3 || (strncmp(buf, "LTC", 3) && strncmp(buf, "ADI", 3)))
 			return -ENODEV;
 
-		ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, buf);
+		ret = pmbus_read_smbus_i2c_block_data(client, PMBUS_MFR_MODEL, buf);
 		if (ret < 0)
 			return ret;
 		for (id = &ltc2978_id[0]; strlen(id->name); id++) {
@@ -637,16 +633,17 @@ static int ltc2978_get_id(struct i2c_client *client)
 		u8 buf[I2C_SMBUS_BLOCK_MAX];
 		int ret;
 
-		ret = i2c_smbus_read_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
-						    sizeof(buf), buf);
+		ret = pmbus_read_smbus_i2c_block_data(client, PMBUS_IC_DEVICE_ID,
+						      buf);
 		if (ret < 0)
 			return ret;
 
-		if (!strncmp(buf + 1, "LT7170", 6) ||
-		    !strncmp(buf + 1, "LT7170-1", 8))
+		if (ret < 6)
+			return -ENODEV;
+
+		if (!strncmp(buf, "LT7170", 6))
 			return lt7170;
-		if (!strncmp(buf + 1, "LT7171", 6) ||
-		    !strncmp(buf + 1, "LT7171-1", 8))
+		if (!strncmp(buf, "LT7171", 6))
 			return lt7171;
 
 		return -ENODEV;
-- 
2.45.2