From patchwork Wed Jul 26 08:00:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tam Nguyen X-Patchwork-Id: 707257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4498C41513 for ; Wed, 26 Jul 2023 08:09:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232346AbjGZII7 (ORCPT ); Wed, 26 Jul 2023 04:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233276AbjGZIIP (ORCPT ); Wed, 26 Jul 2023 04:08:15 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2094.outbound.protection.outlook.com [40.107.92.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2EC41FC9; Wed, 26 Jul 2023 01:01:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D1e6g/Nym2aSIAFdrUEzQgS98lIeXBdN/ie5hRQP+SsVpL8ocFXHv5xly5qxHtTVMA5N1lt5ZvaaVuOkmf9eserJ5/sdTy1y8/jpdpn2R4FybjcrMSvbkx4BRTSlcWyjO5+c8To5+abyPTltCkUO53gWXYPOETUUlPJPiz3pFPBnTSJK3Hg7Z97akUkd4iQMkma/Mx/hHgE7pROPOu8IzqIyBPl/WQvmp7NC/gOia8+oBq25FEHCiGiJG+yOA/WB/4ZvXez4kmazI+mfn5HMfPsaHvORGX3wX7Cl5drmwZYiN+3+cc5IGtY3ADbnINZcAP/wDZ82neT5GheAfLfIGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yiXpaJ+STegM3GCLwRzoyO2t4P6/8a3dgzlhDwgZPmU=; b=Nm2ve+TSThdj1Kt7v9BN8XznzmSaQAMqjIT8BBWD/ByDb8tVjs7jZC2ccma6cPJ5njVbDfb9lH7a00I6DulhSWlkS/jqihPxharPQiLXn6i10lfPpkW+XmWdWmR9ixNLBNGGZ88OS1zBiaPGV35QfOiC5XvB+X1em4C9IVsEw9yLC1Pa2abiPZ8mr3cDSzSI11o5mOhW1kI2kkfzGKQlyx6fT1amETsGGDwMyThfkncoeEdQ+3dYy2BnFChxBwGbFIdM/EVDzpIge740N3MqdMdfQIo3h7D9KJDLHxARyYwwl93aHXBGcgu9sMIYZqzR1hu+RNkWNRRtBVFs1VlfpQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yiXpaJ+STegM3GCLwRzoyO2t4P6/8a3dgzlhDwgZPmU=; b=AkxWeEbUGV9NQ4EhDy74T0MUqG04GvcyODIO2tfcUNTgkTuBMh3eAXu6j8ObyQpDg3mKk8cvIDTNaX2fFTr9Z69iY7WSK278kuOlKotFjmcJG69jCNh/7AkdZwxYOmhTPUu/AdzY5leLbPMYmPqo/vr+IPvirTnckffM8RBm7DM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SA1PR01MB8131.prod.exchangelabs.com (2603:10b6:806:325::8) by SA3PR01MB7988.prod.exchangelabs.com (2603:10b6:806:304::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.25; Wed, 26 Jul 2023 08:00:33 +0000 Received: from SA1PR01MB8131.prod.exchangelabs.com ([fe80::ad0:68f6:fb88:bf5a]) by SA1PR01MB8131.prod.exchangelabs.com ([fe80::ad0:68f6:fb88:bf5a%7]) with mapi id 15.20.6609.032; Wed, 26 Jul 2023 08:00:33 +0000 From: Tam Nguyen To: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Cc: patches@amperecomputing.com, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jsd@semihalf.com, tamnguyenchi@os.amperecomputing.com, chuong@os.amperecomputing.com, darren@os.amperecomputing.com, Quan Nguyen , stable@vger.kernel.org Subject: [PATCH v2 1/2] i2c: designware: Correct length byte validation logic Date: Wed, 26 Jul 2023 15:00:00 +0700 Message-Id: <20230726080001.337353-2-tamnguyenchi@os.amperecomputing.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230726080001.337353-1-tamnguyenchi@os.amperecomputing.com> References: <20230726080001.337353-1-tamnguyenchi@os.amperecomputing.com> X-ClientProxiedBy: SG3P274CA0014.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::26) To SA1PR01MB8131.prod.exchangelabs.com (2603:10b6:806:325::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR01MB8131:EE_|SA3PR01MB7988:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c9fd108-d6a7-46e8-de9a-08db8dae6369 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H4ySfHAqf7GU3zNi5yYyhvXpM7UIcN37PSRaCZ6AT0CExbcC264dWS4NJEVwCLuDmPRrY44EKKhF0vp0+7EOlBWFFYOlJLX61Ti2sHl4FeD48L4NNOsWZotrI1sBc+0U66JJNCahTUR3ml2CVAeIhKp+2fg5C69qQDD7ci8PXL8ump2Vx+vW9buRHrvTqYy/rgKk1B820mz2e+/wIumbNikGC+BduU8SbOuTa1y9SWBTGGxQ6qAdsYjcYALiwKxFCPFgfbTmjlz+yamUoV53aT4KAxFRwQXNFx9rTCDDUsp2zUl2ML+OnkjrAX/AC++R7pCxg3gQ/M2Qrl0ViLq7Y6Hv7ySS4VZ7o3Y9G+xfwLRCElm5ELvNbMGxrzt1KBrXJAuPhThYs4wqD2/C1qsysakMP+NU5soSWUyRpa2xvYmXzdvB8mBluP50ZtvqwFG0vwGRaLNhpoETOP0sULbMaGM1euf0whsI1U4wCq6Jlu6E9lxYK3iWBZTpWQQ01TJVaaYshH+ojdIZFqidExwIFzu6PLkEKgiCPqUQRgi2AP27uZE21LMAoa212x133d+HbswakxRm+YHIR2SWSa8iSksPsu8gEWRBTVbWd2cLfcM5ZD+UTsHy6D1SR+Ke+IDr X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR01MB8131.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(366004)(39850400004)(396003)(346002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(86362001)(38350700002)(38100700002)(6486002)(6506007)(1076003)(41300700001)(52116002)(66476007)(66946007)(316002)(66556008)(4326008)(186003)(6666004)(26005)(6512007)(8936002)(8676002)(478600001)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NkKP70Wlryf5Wy/ysnOYiyEaQcWQxLJ7/YzX5Uv6DokiOh2Vu4n1aizf6qulSkyuvIfks0t9RGd017zwOfAbtE9QVj+M377YmpnPr+ogiTC8DbVib6ZFvMzBNxfB/8dkU04P5HPxk9v0vFbx+4MY8c9oZFgdB7zERHn9jsS9MWIpd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5WOUc6VC65y5Y12KSni2fsdh6sQkfqyb9ImbQVBnhJbn16ZeVpQ+YjLOJ0bOzTgtyO3HFFVPl+MZwbgUtxTJYbH9k8ddfmyO6in+tPZ1oZ3hrHH16bYZp9Wx8GSsWRmx0HMGFsQBe8ayoPUZLKZz9sV/Ge1Yi3R2I7E+p1trKp+pum3fbJBjk9nlAZwM2F1b63Ww9LrcCqF6A2tzANKCxSMncj4z0tT6SwR8g6tLt7WoKCM1CibNsmhwcuGPny3KCwz7kD07mcBrsWoplfChDrfGFiW815A8eO72AXGss9iKftLEFIhgxvKYKJHHhDHcOZC+wR9hnoOQ26lpbI2aS5dnxPjxdZWFtlKGXi/nTfFNYcBRl3jwq2kC3Fx4KhTHlvq4LxZRLs27rCh20PvfU/w6Skt X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c9fd108-d6a7-46e8-de9a-08db8dae6369 X-MS-Exchange-CrossTenant-AuthSource: SA1PR01MB8131.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 08:00:33.6776 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nmEG/McPC+GQgsrvdZzksRaBkgBt2m1zRNPc7PmFVrbaWcsZBR2ELX6ywJXSH2/KIMxzEcIPhTiwG9ZN9KITpXNDbvx/eSAWzuVX0/lfzU4gFjDWQmrwpqTWDpfn+e9v X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR01MB7988 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Quan Nguyen Commit 0daede80f870 ("i2c: designware: Convert driver to using regmap API") changes the logic to validate the whole 32-bit return value of DW_IC_DATA_CMD register instead of 8-bit LSB without reason. Later, commit f53f15ba5a85 ("i2c: designware: Get right data length"), introduced partial fix but not enough because the "tmp > 0" still test tmp as 32-bit value and is wrong in case the IC_DATA_CMD[11] is set. Revert the logic to just before commit 0daede80f870 ("i2c: designware: Convert driver to using regmap API"). Fixes: f53f15ba5a85 ("i2c: designware: Get right data length") Fixes: 0daede80f870 ("i2c: designware: Convert driver to using regmap API") Cc: stable@vger.kernel.org Signed-off-by: Tam Nguyen Signed-off-by: Quan Nguyen --- drivers/i2c/busses/i2c-designware-master.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index 55ea91a63382..e96276d1b002 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -526,9 +526,10 @@ i2c_dw_read(struct dw_i2c_dev *dev) u32 flags = msgs[dev->msg_read_idx].flags; regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); + tmp &= DW_IC_DATA_CMD_DAT; /* Ensure length byte is a valid value */ if (flags & I2C_M_RECV_LEN && - (tmp & DW_IC_DATA_CMD_DAT) <= I2C_SMBUS_BLOCK_MAX && tmp > 0) { + tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) { len = i2c_dw_recv_len(dev, tmp); } *buf++ = tmp; From patchwork Wed Jul 26 08:00:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tam Nguyen X-Patchwork-Id: 706762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C628C00528 for ; Wed, 26 Jul 2023 08:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232690AbjGZIJL (ORCPT ); Wed, 26 Jul 2023 04:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233298AbjGZIIS (ORCPT ); Wed, 26 Jul 2023 04:08:18 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2094.outbound.protection.outlook.com [40.107.92.94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88587359E; Wed, 26 Jul 2023 01:01:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wrho+CbNwVBQtS6lVEW8H630SeQ6zIVaAkj5AL551VZwK3xg+vgi94NKF0rz3Vzu9aPUzGkRpspAZvq6ss2WFmLmkgpVU/Qnt1PIMuxnfufF88nrX3+mQivzusT7Y/5JxHg0hqGQBx3gM4h1OtpeDYX4E3LcVijS+YaYg20+Avp4VDMQ5f6/lt9fUVqSpcbRj8lI5NzVzLpRwKfXDjxYXB2VRufxdgDxKVNQcN1Jel3wkARGZ3GbsIBTNPcRsUdxBrC6mAAVyI2IEzORlp1NLe2qhIQWbzJJkJ8UlDQn9C2EVYMLNhD2EfDpQehMbXc47uDTGXfOwrBagHbmZlOQTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uaa+ogpgk1cY/Q2s/NNSfWF9UjtDzkEKU4EKKlUMunU=; b=mSRf/kJ792De/7CjBvd6QHkkfiwmz9eYxdfhGIys0u/vbxeEbIHG7ArlEhxbzdQ1paEEi47eVNXiq7hjF1JaJqby8iwcx1AWJXWPpTqdQL05MpcSeLexJDj7yzlKpU6D5tD5yoeISuC2p0cpR7oyyp61AFDRHFX4wnM0Pd8Lo4hr9MXklHlfxrSN00NhngEXacOMXauzlm33YKH9479CbbvcIl56gnhUaH/3wlaOCi7nRKWVswyKBeaiRjj7ptag9HTlJa2EenWkZXItjiApo+kIsw7qVIXtplWTDlbJLX0yHpQPwpIu/uR8OltzV2VbVnVHvirn1vi4Blbifz4DnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uaa+ogpgk1cY/Q2s/NNSfWF9UjtDzkEKU4EKKlUMunU=; b=KUPm9HJ+pE6Epqm/wCH6r9EOWtOH2lvNRaru265vyVN5JSbz6BQNPAi1QQSr4/Fh+HrlGytvbYAQpC5UbGB1IXoIJAhV6luXBikw8NWm/fCemvkpWZEDuvCqhxuRQpz9op5wt/o2lRarKHXjEgwLTpIzV86vjgh5SYUIihb4h2k= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from SA1PR01MB8131.prod.exchangelabs.com (2603:10b6:806:325::8) by SA3PR01MB7988.prod.exchangelabs.com (2603:10b6:806:304::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.25; Wed, 26 Jul 2023 08:00:39 +0000 Received: from SA1PR01MB8131.prod.exchangelabs.com ([fe80::ad0:68f6:fb88:bf5a]) by SA1PR01MB8131.prod.exchangelabs.com ([fe80::ad0:68f6:fb88:bf5a%7]) with mapi id 15.20.6609.032; Wed, 26 Jul 2023 08:00:39 +0000 From: Tam Nguyen To: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Cc: patches@amperecomputing.com, jarkko.nikula@linux.intel.com, andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, jsd@semihalf.com, tamnguyenchi@os.amperecomputing.com, chuong@os.amperecomputing.com, darren@os.amperecomputing.com, stable@vger.kernel.org Subject: [PATCH v2 2/2] i2c: designware: Handle invalid SMBus block data response length value Date: Wed, 26 Jul 2023 15:00:01 +0700 Message-Id: <20230726080001.337353-3-tamnguyenchi@os.amperecomputing.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230726080001.337353-1-tamnguyenchi@os.amperecomputing.com> References: <20230726080001.337353-1-tamnguyenchi@os.amperecomputing.com> X-ClientProxiedBy: SG3P274CA0014.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::26) To SA1PR01MB8131.prod.exchangelabs.com (2603:10b6:806:325::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR01MB8131:EE_|SA3PR01MB7988:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a1820a6-df0b-4b0d-340e-08db8dae667a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z6zMcElSmkg2Utas8OWzEVRrgKK0pXe07KHN3eeHtvn08ryf+mOiesb1ND/VC6GLw8x9kkvCxwgoUL4rmKWRly4zU/vfPBjUjmatHvi0HkkmMCDv3mP8hFNm1jvTdN1RZ3ZZREySus62YSEYnbi6YvCRWFuxjRehHgYblTBqerpVsxLzU04WPjWga9xRKdLa531ees0NhmRN2wMg3Ifn1ckgrDTLm0oW0lt+TyprPWX1lZsn6ubWfiItchrTJ3+1hXnTTwlxCBU/vckRkU1AancPe83j216BzoJEWUMUPr0sjku/616iJxrB+zQ5FD7hZY9aKj34kkyqxP6QHm3ZO9yhPE/nO0xNYo9pwhty1aYu78mWmv9bHducTcL+sjaJWBKb359iKqTwDnbrTqWA2AmjMH+rDA9RirXY8cZ0ZfYzHkZDjNuoZFui6HKw+xRCSdLV1UWqzJFRXsveCFavggVMO6Hqz/cUEI3AioKKOLouXVegxtzMfVlJ04MVX02Mhr3AYQpjBkBEcBdeixmrJXByGApD0iXU29UrJbQ+14fYBxw3uVoEKxLiS+/IUGpIvfEH1PWTwV8d+k2vB5tjmQz/gPyBFY1gJ4TeVJtYtP8vJhyXjwbbkdF8QnIuiuFO X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA1PR01MB8131.prod.exchangelabs.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(366004)(39850400004)(396003)(346002)(136003)(376002)(451199021)(2906002)(83380400001)(2616005)(86362001)(38350700002)(38100700002)(6486002)(6506007)(1076003)(41300700001)(52116002)(66476007)(66946007)(316002)(66556008)(4326008)(186003)(6666004)(26005)(6512007)(8936002)(8676002)(478600001)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZN6Ns5uSPFHfVhP+y1EGxzayEjlkzvWShf4lRYtAH8jdFKsDndHSC3PvwXESg+RLYestnWlJI6E2Y7d08Oj30V5imJjq9bTng5badTOTY9rO/8yMUT473uaUoTC1ykF9qaBA+4xjpvoM5RDPNHL77uh9BRh9fFac6jzHdOoX/jGJi7xWPUU0ocecxgtehbNrnREdc1Qu8JWgn8XRTC0h0eEY1hhFgVsDDqrghi3fEZkTvZgcGmU72DcXDXrVQAX1vU06zXPIlvYX5nVyCODdiu1qK51Cazus/88kh/yCBy7EwTOyhZz+UhpaEN1DUjGdqLJoP2kqH8wBLoyAMHQ9R1iSEB2oc+NGsuQFiY5Ae3kJNr6gRJVnDhZIev31ZHS+OR4+fLBnvllQbeFxXKDsmmC692sA6AIibrdtMB/szBcHz7QhXS104jWJTuXfF4izJsyXzcfuHaLOZK86bigVUPcK1zB36DhnxOHVlxWHSaRXLg0kv8XEMtAwMF08Ut5MWow6wptjlwWnTk7rOgUUzdy4dHgCT3DtHwXXvUZ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1pJ5lPATJUQ/EFCe+9P7zwVZRrMTxPMn X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a1820a6-df0b-4b0d-340e-08db8dae667a X-MS-Exchange-CrossTenant-AuthSource: SA1PR01MB8131.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 08:00:38.9924 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 8JNWAfrHM21i/9P70b1bBbiEY2eDEgDfzaGatOonoWAMFuTygYy5QJF76LDP7Or15Tiru+652wwl8Veiz6XL10Lr2ByVzl2qGQ7L/4+IOcF6p64Lx8jNzQ7TpS2MjOhI X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR01MB7988 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In the I2C_FUNC_SMBUS_BLOCK_DATA case, the invalid length byte value (outside of 1-32) of the SMBus block data response from the Slave device is not correctly handled by the I2C Designware driver. In case IC_EMPTYFIFO_HOLD_MASTER_EN==1, which cannot be detected from the registers, the Master can be disabled only if the STOP bit is set. Without STOP bit set, the Master remains active, holding the bus until receiving a block data response length. This hangs the bus and is unrecoverable. Avoid this by issuing another dump read to reach the stop condition when an invalid length byte is received. Cc: stable@vger.kernel.org Signed-off-by: Tam Nguyen Acked-by: Jarkko Nikula --- drivers/i2c/busses/i2c-designware-master.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-master.c b/drivers/i2c/busses/i2c-designware-master.c index e96276d1b002..c51fc1f4b97e 100644 --- a/drivers/i2c/busses/i2c-designware-master.c +++ b/drivers/i2c/busses/i2c-designware-master.c @@ -528,8 +528,19 @@ i2c_dw_read(struct dw_i2c_dev *dev) regmap_read(dev->map, DW_IC_DATA_CMD, &tmp); tmp &= DW_IC_DATA_CMD_DAT; /* Ensure length byte is a valid value */ - if (flags & I2C_M_RECV_LEN && - tmp <= I2C_SMBUS_BLOCK_MAX && tmp > 0) { + if (flags & I2C_M_RECV_LEN) { + /* + * if IC_EMPTYFIFO_HOLD_MASTER_EN is set, which cannot be + * detected from the registers, the controller can be + * disabled if the STOP bit is set. But it is only set + * after receiving block data response length in + * I2C_FUNC_SMBUS_BLOCK_DATA case. That needs to read + * another byte with STOP bit set when the block data + * response length is invalid to complete the transaction. + */ + if (!tmp || tmp > I2C_SMBUS_BLOCK_MAX) + tmp = 1; + len = i2c_dw_recv_len(dev, tmp); } *buf++ = tmp;