Skip to content

Commit 415a02d

Browse files
jwrdegoedegregkh
authored andcommitted
i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
commit c463a15 upstream. acpi_gsb_i2c_write_bytes() returns i2c_transfer()'s return value, which is the number of transfers executed on success, so 1. The ACPI code expects us to store 0 in gsb->status for success, not 1. Specifically this breaks the following code in the Thinkpad 8 DSDT: ECWR = I2CW = ECWR /* \_SB_.I2C1.BAT0.ECWR */ If ((ECST == Zero)) { ECRD = I2CR /* \_SB_.I2C1.I2CR */ } Before this commit we set ECST to 1, causing the read to never happen breaking battery monitoring on the Thinkpad 8. This commit makes acpi_gsb_i2c_write_bytes() return 0 when i2c_transfer() returns 1, so the single write transfer completed successfully, and makes it return -EIO on for other (unexpected) return values >= 0. Cc: stable@vger.kernel.org Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b5b7417 commit 415a02d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

drivers/i2c/i2c-core-acpi.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,16 @@ static int acpi_gsb_i2c_write_bytes(struct i2c_client *client,
475475
msgs[0].buf = buffer;
476476

477477
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
478-
if (ret < 0)
479-
dev_err(&client->adapter->dev, "i2c write failed\n");
480478

481479
kfree(buffer);
482-
return ret;
480+
481+
if (ret < 0) {
482+
dev_err(&client->adapter->dev, "i2c write failed: %d\n", ret);
483+
return ret;
484+
}
485+
486+
/* 1 transfer must have completed successfully */
487+
return (ret == 1) ? 0 : -EIO;
483488
}
484489

485490
static acpi_status

0 commit comments

Comments
 (0)