* [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
@ 2018-08-12 10:53 Hans de Goede
2018-08-12 20:39 ` Peter Rosin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Hans de Goede @ 2018-08-12 10:53 UTC (permalink / raw)
To: Wolfram Sang, Mika Westerberg
Cc: Hans de Goede, linux-i2c, linux-acpi, stable
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>
---
Changes in v2:
-Modify the value which acpi_gsb_i2c_write_bytes() returns instead of
checking + modifying the return value in its caller
---
drivers/i2c/i2c-core-acpi.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 7c3b4740b94b..b8f303dea305 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -482,11 +482,16 @@ static int acpi_gsb_i2c_write_bytes(struct i2c_client *client,
msgs[0].buf = buffer;
ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
- if (ret < 0)
- dev_err(&client->adapter->dev, "i2c write failed\n");
kfree(buffer);
- return ret;
+
+ if (ret < 0) {
+ dev_err(&client->adapter->dev, "i2c write failed: %d\n", ret);
+ return ret;
+ }
+
+ /* 1 transfer must have completed successfully */
+ return (ret == 1) ? 0 : -EIO;
}
static acpi_status
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
2018-08-12 10:53 [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes Hans de Goede
@ 2018-08-12 20:39 ` Peter Rosin
2018-08-13 8:44 ` Hans de Goede
2018-08-13 9:38 ` Mika Westerberg
2018-08-20 12:10 ` Wolfram Sang
2 siblings, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2018-08-12 20:39 UTC (permalink / raw)
To: Hans de Goede, Wolfram Sang, Mika Westerberg
Cc: linux-i2c, linux-acpi, stable
On 2018-08-12 12:53, Hans de Goede wrote:
> 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.
I'm wondering if this might be fallout from one of
35cd67a0caf7 ("i2c: viperboard: return message count on master_xfer success")
de9a8634f1cb ("i2c: pmcmsp: return message count on master_xfer success")
But I have no idea what i2c driver these Thinkpads are using, so it is not
unlikely that I'm way off...
Cheers,
Peter
> Cc: stable@vger.kernel.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> Changes in v2:
> -Modify the value which acpi_gsb_i2c_write_bytes() returns instead of
> checking + modifying the return value in its caller
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
2018-08-12 20:39 ` Peter Rosin
@ 2018-08-13 8:44 ` Hans de Goede
0 siblings, 0 replies; 5+ messages in thread
From: Hans de Goede @ 2018-08-13 8:44 UTC (permalink / raw)
To: Peter Rosin, Wolfram Sang, Mika Westerberg; +Cc: linux-i2c, linux-acpi, stable
Hi,
On 12-08-18 22:39, Peter Rosin wrote:
> On 2018-08-12 12:53, Hans de Goede wrote:
>> 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.
>
> I'm wondering if this might be fallout from one of
> 35cd67a0caf7 ("i2c: viperboard: return message count on master_xfer success")
> de9a8634f1cb ("i2c: pmcmsp: return message count on master_xfer success")
No, these are using the designware driver, so these commits are not
the cause, this simply is a long standing bug.
Regards,
Hans
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
2018-08-12 10:53 [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes Hans de Goede
2018-08-12 20:39 ` Peter Rosin
@ 2018-08-13 9:38 ` Mika Westerberg
2018-08-20 12:10 ` Wolfram Sang
2 siblings, 0 replies; 5+ messages in thread
From: Mika Westerberg @ 2018-08-13 9:38 UTC (permalink / raw)
To: Hans de Goede; +Cc: Wolfram Sang, linux-i2c, linux-acpi, stable
On Sun, Aug 12, 2018 at 12:53:20PM +0200, Hans de Goede wrote:
> 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>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes
2018-08-12 10:53 [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes Hans de Goede
2018-08-12 20:39 ` Peter Rosin
2018-08-13 9:38 ` Mika Westerberg
@ 2018-08-20 12:10 ` Wolfram Sang
2 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2018-08-20 12:10 UTC (permalink / raw)
To: Hans de Goede; +Cc: Mika Westerberg, linux-i2c, linux-acpi, stable
[-- Attachment #1: Type: text/plain, Size: 1007 bytes --]
On Sun, Aug 12, 2018 at 12:53:20PM +0200, Hans de Goede wrote:
> 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>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-20 12:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-12 10:53 [PATCH v2 1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes Hans de Goede
2018-08-12 20:39 ` Peter Rosin
2018-08-13 8:44 ` Hans de Goede
2018-08-13 9:38 ` Mika Westerberg
2018-08-20 12:10 ` Wolfram Sang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.