Skip to content

Commit 839f5ff

Browse files
jwrdegoedeyouling257
authored andcommitted
i2c: core: ACPI: Make acpi_gsb_i2c_read_bytes() check i2c_transfer return value
Currently acpi_gsb_i2c_read_bytes() directly returns i2c_transfer's return value. i2c_transfer returns a value < 0 on error and 2 (for 2 successfully executed transfers) on success. But the ACPI code expects 0 on success, so currently acpi_gsb_i2c_read_bytes()'s caller does: if (status > 0) status = 0; This commit makes acpi_gsb_i2c_read_bytes() return a value which can be directly consumed by the ACPI code, mirroring acpi_gsb_i2c_write_bytes(), this commit also makes acpi_gsb_i2c_read_bytes() explitcly check that i2c_transfer returns 2, rather then accepting any value > 0. 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: youling257 <youling257@gmail.com>
1 parent fcc221d commit 839f5ff

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/i2c/i2c-core.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,12 @@ static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
502502
else
503503
dev_err(&client->adapter->dev, "i2c read %d bytes from client@%#x starting at reg %#x failed, error: %d\n",
504504
data_len, client->addr, cmd, ret);
505-
} else {
505+
/* 2 transfers must have completed successfully */
506+
} else if (ret == 2) {
506507
memcpy(data, buffer, data_len);
508+
ret = 0;
509+
} else {
510+
ret = -EIO;
507511
}
508512

509513
kfree(buffer);
@@ -644,8 +648,6 @@ i2c_acpi_space_handler(u32 function, acpi_physical_address command,
644648
if (action == ACPI_READ) {
645649
status = acpi_gsb_i2c_read_bytes(client, command,
646650
gsb->data, info->access_length);
647-
if (status > 0)
648-
status = 0;
649651
} else {
650652
status = acpi_gsb_i2c_write_bytes(client, command,
651653
gsb->data, info->access_length);

0 commit comments

Comments
 (0)