Skip to content

Commit f27cfb0

Browse files
committed
i2c: i801: Add SMBUS_LEN_SENTINEL
JIRA: https://issues.redhat.com/browse/RHEL-47426 commit 29dae45 Author: Heiner Kallweit <hkallweit1@gmail.com> Date: Fri Feb 2 08:04:06 2024 +0100 i2c: i801: Add SMBUS_LEN_SENTINEL Add a sentinel length value that is used to check whether we should read and use the length value provided by the slave device. This simplifies the currently used checks. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 421e397 commit f27cfb0

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/i2c/busses/i2c-i801.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@
206206
#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR | \
207207
STATUS_ERROR_FLAGS)
208208

209+
#define SMBUS_LEN_SENTINEL (I2C_SMBUS_BLOCK_MAX + 1)
210+
209211
/* Older devices have their ID defined in <linux/pci_ids.h> */
210212
#define PCI_DEVICE_ID_INTEL_COMETLAKE_SMBUS 0x02a3
211213
#define PCI_DEVICE_ID_INTEL_COMETLAKE_H_SMBUS 0x06a3
@@ -543,9 +545,12 @@ static int i801_block_transaction_by_block(struct i801_priv *priv,
543545
static void i801_isr_byte_done(struct i801_priv *priv)
544546
{
545547
if (priv->is_read) {
546-
/* For SMBus block reads, length is received with first byte */
547-
if (((priv->cmd & 0x1c) == I801_BLOCK_DATA) &&
548-
(priv->count == 0)) {
548+
/*
549+
* At transfer start i801_smbus_block_transaction() marks
550+
* the block length as invalid. Check for this sentinel value
551+
* and read the block length from SMBHSTDAT0.
552+
*/
553+
if (priv->len == SMBUS_LEN_SENTINEL) {
549554
priv->len = inb_p(SMBHSTDAT0(priv));
550555
if (priv->len < 1 || priv->len > I2C_SMBUS_BLOCK_MAX) {
551556
dev_err(&priv->pci_dev->dev,
@@ -704,8 +709,12 @@ static int i801_block_transaction_byte_by_byte(struct i801_priv *priv,
704709
if (status)
705710
return status;
706711

707-
if (i == 1 && read_write == I2C_SMBUS_READ
708-
&& command != I2C_SMBUS_I2C_BLOCK_DATA) {
712+
/*
713+
* At transfer start i801_smbus_block_transaction() marks
714+
* the block length as invalid. Check for this sentinel value
715+
* and read the block length from SMBHSTDAT0.
716+
*/
717+
if (len == SMBUS_LEN_SENTINEL) {
709718
len = inb_p(SMBHSTDAT0(priv));
710719
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
711720
dev_err(&priv->pci_dev->dev,
@@ -809,7 +818,8 @@ static int i801_smbus_block_transaction(struct i801_priv *priv, union i2c_smbus_
809818
u8 addr, u8 hstcmd, char read_write, int command)
810819
{
811820
if (read_write == I2C_SMBUS_READ && command == I2C_SMBUS_BLOCK_DATA)
812-
data->block[0] = I2C_SMBUS_BLOCK_MAX;
821+
/* Mark block length as invalid */
822+
data->block[0] = SMBUS_LEN_SENTINEL;
813823
else if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
814824
return -EPROTO;
815825

0 commit comments

Comments
 (0)