Re: [PATCH 1/5] hwmon: (pmbus/core) Introduce pmbus_read_smbus_i2c_block_data()

Guenter Roeck <[email protected]> Tue, 4 Aug 2026 11:12:31 -0700
Newsgroups org.kernel.vger.linux-hwmon
Message-ID <[email protected]>
On 8/4/26 01:45, Nuno Sá wrote:
...
>> +	/*
>> +	 * If the returned data is valid SMBus block data, the first byte
>> +	 * must be the data length.
>> +	 *
>> +	 * i2c_smbus_read_i2c_block_data() may return an error if the chip
>> +	 * sends NACK before the number of requested bytes is received.
>> +	 * Handle this by reading the data length first, then reading the
>> +	 * entire message up to I2C_SMBUS_BLOCK_MAX bytes. This ensures
>> +	 * that requested number of bytes never exceeds the number of
>> +	 * bytes sent by the chip.
>> +	 */
>> +	pmbus_wait(client);
>> +	ret = i2c_smbus_read_i2c_block_data(client, reg, 1, buf);
>> +	pmbus_update_ts(client, 0);
>> +	if (ret < 0)
>> +		return ret;
>> +	if (ret != 1)
>> +		return -EIO;
>> +
> 
> I think the above is ret != -1 is not really necessary (same for the
> below check. i2c_smbus_read_i2c_block_data() always returns the length passed to it.
> The only case where it doesn't is if we pass something >
> I2C_SMBUS_BLOCK_MAX which would always fail anyways.
> 

Good point. I'll drop the checks.

Thanks,
Guenter