From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-by2nam03on0134.outbound.protection.outlook.com ([104.47.42.134]:34736 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727270AbeH3WFL (ORCPT ); Thu, 30 Aug 2018 18:05:11 -0400 From: Sasha Levin To: "stable@vger.kernel.org" CC: Hans de Goede , Wolfram Sang , Sasha Levin Subject: [PATCH AUTOSEL 4.18 020/113] i2c: core: ACPI: Make acpi_gsb_i2c_read_bytes() check i2c_transfer return value Date: Thu, 30 Aug 2018 18:01:48 +0000 Message-ID: <20180830180050.35735-20-alexander.levin@microsoft.com> References: <20180830180050.35735-1-alexander.levin@microsoft.com> In-Reply-To: <20180830180050.35735-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Hans de Goede [ Upstream commit 0a30446c0dca3483c384b54a431cc951e15f7e79 ] 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 =3D 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 Acked-by: Mika Westerberg Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/i2c-core-acpi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 start= ing at reg %#x failed, error: %d\n", data_len, client->addr, cmd, ret); - } else { + /* 2 transfers must have completed successfully */ + } else if (ret =3D=3D 2) { memcpy(data, buffer, data_len); + ret =3D 0; + } else { + ret =3D -EIO; } =20 kfree(buffer); @@ -595,8 +599,6 @@ i2c_acpi_space_handler(u32 function, acpi_physical_addr= ess command, if (action =3D=3D ACPI_READ) { status =3D acpi_gsb_i2c_read_bytes(client, command, gsb->data, info->access_length); - if (status > 0) - status =3D 0; } else { status =3D acpi_gsb_i2c_write_bytes(client, command, gsb->data, info->access_length); --=20 2.17.1