diff mbox series

[v2,2/2] i2c: core: ACPI: Make acpi_gsb_i2c_read_bytes() check i2c_transfer return value

Message ID 20180812105321.2668-2-hdegoede@redhat.com
State Accepted
Headers show
Series [v2,1/2] i2c: core: ACPI: Properly set status byte to 0 for multi-byte writes | expand

Commit Message

Hans de Goede Aug. 12, 2018, 10:53 a.m. UTC
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>
---
Changes in v2:
-New patch in v2 of this patch-set
---
 drivers/i2c/i2c-core-acpi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Mika Westerberg Aug. 13, 2018, 9:39 a.m. UTC | #1
On Sun, Aug 12, 2018 at 12:53:21PM +0200, Hans de Goede wrote:
> 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>
Wolfram Sang Aug. 20, 2018, 12:10 p.m. UTC | #2
On Sun, Aug 12, 2018 at 12:53:21PM +0200, Hans de Goede wrote:
> 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>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index b8f303dea305..32affd3fa8bd 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -453,8 +453,12 @@  static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
 		else
 			dev_err(&client->adapter->dev, "i2c read %d bytes from client@%#x starting at reg %#x failed, error: %d\n",
 				data_len, client->addr, cmd, ret);
-	} else {
+	/* 2 transfers must have completed successfully */
+	} else if (ret == 2) {
 		memcpy(data, buffer, data_len);
+		ret = 0;
+	} else {
+		ret = -EIO;
 	}
 
 	kfree(buffer);
@@ -595,8 +599,6 @@  i2c_acpi_space_handler(u32 function, acpi_physical_address command,
 		if (action == ACPI_READ) {
 			status = acpi_gsb_i2c_read_bytes(client, command,
 					gsb->data, info->access_length);
-			if (status > 0)
-				status = 0;
 		} else {
 			status = acpi_gsb_i2c_write_bytes(client, command,
 					gsb->data, info->access_length);