From nobody Mon Feb 9 12:44:45 2026 Received: from AM0PR02CU008.outbound.protection.outlook.com (mail-westeuropeazon11013042.outbound.protection.outlook.com [52.101.72.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8891A34321B; Fri, 16 Jan 2026 09:17:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.72.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768555035; cv=fail; b=IMFugG+dnHv7HDV+BkRdxGEyKXfdbL8BDhgjeVEtKc6EsK6Aiu8cByv30WUCyuQjJ8iK0ft3QvQdYprb6UlIRgxzWD3C8mpTvMUAaePSRYb2LleyAwQD31GmfYoKhy6gDT98t8G/5DR2kXAhTM/R5TZJjq3/sqDtZwIuNoc6o/0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768555035; c=relaxed/simple; bh=OaoxgJjSLRqgJNkEF4ebw1iRQI7uXBg45B1D3VW5r6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FHPWRq7sPVgFdY8ygMVO0gHrojBpyiTNJgkuRJnPkpMj8ofS3JcvvtbFvxogkZyCe73KZuesmdDN8MieDC+5EgSwL9DuFIxDwJ1d739pu33mjN6l9q1695w6BWukLjtb8RuIn/rLsF/MADv/qfJFnFpvM2LFvWBqyoLu2RAo9aM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=leica-geosystems.com.cn; spf=fail smtp.mailfrom=leica-geosystems.com.cn; dkim=pass (1024-bit key) header.d=leica-geosystems.com.cn header.i=@leica-geosystems.com.cn header.b=UrpBxp3h; arc=fail smtp.client-ip=52.101.72.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=leica-geosystems.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=leica-geosystems.com.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=leica-geosystems.com.cn header.i=@leica-geosystems.com.cn header.b="UrpBxp3h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XtdDNojOIIuz78u41d78KSV5rcKd3/JA0Q5q/FKJMeqNZjUMCJN2O4vC+C+pmQlosR2rC57ZtCGzYy7+HCltWjOfFRgA9PqCUprqytbJ8ueTZdV36k+CxeSxRknicVG+tVS/pOXWwxNvh+EMHh9Undp1TXgRu0B0IIyt+fS0SQDQ3HhiKjt4Lb5IfxvDuFtl1bciAMMuSUpiHUhPdUkOUGMXEGlKV8Y8e+q9XP8MsEQTzvxf6s3OqR0ArZOpKKavJGWgHD142iu8GEUMcM8HWWcdyjqRlYxr3wEOqd6s0ko2/YPqcX5i9CmsXcYQ9lNAPuXR5W3OHAzGPQRN0DBH3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=rPT97ZO92JF5iijb60KQS1ccCmcahHfYT0GR4HzkkRc=; b=GI+sgiBhZD4AnnElRr2N5fHgfZfNtaHwKLxh2rIaVa8pUuCbFYNnAkHkm7TE8dE87zpRHOv5opjPZsNVi+Dj965gBEcEhFGqawgxJHLaVm/FcAzgfsI8WH+qrKCCaoaFD+YJ2Q9lqy/32cLyXog/ni2i4jzpobqIJkkfCHsqsHcAA/lal8gQ/NsUP68VlLvRnzTx+CIcdSj/KYIHcGAw/oAcx7n7zgr9HOqOAmc7ueNEcO8ie1lOW9mUqzBH1LzNvPsUaGWLxchRueYFDB7cvopG53AeNRjNSBPbR1hucexhQLSUFOavHntV/tT78EEWpaDdxI6emuKAJyt/QFbT5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 193.8.40.99) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=leica-geosystems.com.cn; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=leica-geosystems.com.cn; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leica-geosystems.com.cn; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rPT97ZO92JF5iijb60KQS1ccCmcahHfYT0GR4HzkkRc=; b=UrpBxp3hbsnrK6DxeOjW0KEhUPV+HBI/ewWUW0vqepuf6cCLXGjLNqOEgFGLouZBTTqtU2XO7rUwZz1hYOmlNP4jHYTtSZcAp1qvKYgTkziwPr6U/pJw+KtzasKCwgc/LwMMrGliMJXr+RQddlUp0VnWsOCfrkH34/vGzcuAHXk= Received: from AM0PR02CA0192.eurprd02.prod.outlook.com (2603:10a6:20b:28e::29) by VE1PR06MB7102.eurprd06.prod.outlook.com (2603:10a6:800:1b1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9499.7; Fri, 16 Jan 2026 09:17:07 +0000 Received: from AMS0EPF0000019F.eurprd05.prod.outlook.com (2603:10a6:20b:28e:cafe::cd) by AM0PR02CA0192.outlook.office365.com (2603:10a6:20b:28e::29) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.6 via Frontend Transport; Fri, 16 Jan 2026 09:16:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 193.8.40.99) smtp.mailfrom=leica-geosystems.com.cn; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=leica-geosystems.com.cn; Received-SPF: Pass (protection.outlook.com: domain of leica-geosystems.com.cn designates 193.8.40.99 as permitted sender) receiver=protection.outlook.com; client-ip=193.8.40.99; helo=hexagon.com; pr=C Received: from hexagon.com (193.8.40.99) by AMS0EPF0000019F.mail.protection.outlook.com (10.167.16.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Fri, 16 Jan 2026 09:17:07 +0000 Received: from aherlnxbspsrv01.lgs-net.com ([10.61.228.61]) by hexagon.com with Microsoft SMTPSVC(10.0.17763.1697); Fri, 16 Jan 2026 10:17:06 +0100 From: LI Qingwu To: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: bsp-development.geo@leica-geosystems.com, LI Qingwu Subject: [PATCH V2 1/2] i2c: imx: preserve error state in block data length handler Date: Fri, 16 Jan 2026 09:17:03 +0000 Message-ID: <20260116091704.3399142-2-Qing-wu.Li@leica-geosystems.com.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116091704.3399142-1-Qing-wu.Li@leica-geosystems.com.cn> References: <20260116091704.3399142-1-Qing-wu.Li@leica-geosystems.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 16 Jan 2026 09:17:06.0418 (UTC) FILETIME=[E265DD20:01DC86C8] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF0000019F:EE_|VE1PR06MB7102:EE_ X-MS-Office365-Filtering-Correlation-Id: c1e42b1e-467c-4f86-788a-08de54e00592 X-SET-LOWER-SCL-SCANNER: YES X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|921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RUdFeyU4gdILKy9T0DRuOd0mUK9OxUQLcDGOnIbxJY6iu8wtyrwA?= =?us-ascii?Q?zjU8tHaSU8LUfuO7JOp1R0OeY6/YGCane3HHkvZ+YKd6seosSJm2DQF4VpMd?= =?us-ascii?Q?2G51dqSVg87vd6nb4ysD43XDgv53V7WUQ5MAjnvxQamSP14VUDsytr/wJqT9?= =?us-ascii?Q?lLz5ZNdFxTgglf4iNT3iGbD1FOFehofUvnvjyNgdbZ98qIiN/PKOfib1nzVH?= =?us-ascii?Q?/uXrRXjPytrji2u4nab0oJRD8nzMt49HM8Pz9lsqgNEuajItQjfzbuvhKKM8?= =?us-ascii?Q?qLHZtEUnx6hj1QbsCZXOtUrvuen3Nlwr0cbsz7gQfHq5KGR6ks1NhCwH8CTY?= =?us-ascii?Q?bbosJlBZdIxDZPl5UatVd/k4BBW8qd1wNOn062HnvscHKSx2mT8tLI11n8nO?= =?us-ascii?Q?ncl97BIgOfCl36cNamnpior5Em8+N/QsaqEFwwKyq1fOAWg1usK5VxCOJVls?= =?us-ascii?Q?L/WslEfF4K8tdIpYG9Fd+ykaz22yQ9NeepsjLjP0YET1NZhBzZzDUn9y9qpG?= =?us-ascii?Q?3OD2gMz+3yjMMpDdvN+dNkn6vWUJrTk0Gd/owv5Lb1v5iVooVudOMqv/8Z3b?= =?us-ascii?Q?JnH8iVpxWeqDoQC+vYPBO63/ZK7tHzcpeli1N6zx4koXumTzJw2uenUYFGqP?= =?us-ascii?Q?usHY+4klPqTtkCmhVQOd0K5L6PN1YoO2AnLheD3f//omWSirmx3V7dQ7EvpV?= =?us-ascii?Q?rejumTU5U5uXRFTm2Ra8YlN9lI+AnSMK6pmH4hxmKvZ4XKEOIeXzwC/UZ2fX?= =?us-ascii?Q?z58JEbJ6bhXIS3V+8QeapsGnDP/37GIzh5t8s9Jep1mqHnY8tlzEduCK1G+Q?= =?us-ascii?Q?OLya35IILNzauKzSZmt7j7OLFSY=3D?= X-Forefront-Antispam-Report: CIP:193.8.40.99;CTRY:CH;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:hexagon.com;PTR:ahersrvdom51.leica-geosystems.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: leica-geosystems.com.cn X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2026 09:17:07.5137 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c1e42b1e-467c-4f86-788a-08de54e00592 X-MS-Exchange-CrossTenant-Id: 1b16ab3e-b8f6-4fe3-9f3e-2db7fe549f6a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=1b16ab3e-b8f6-4fe3-9f3e-2db7fe549f6a;Ip=[193.8.40.99];Helo=[hexagon.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF0000019F.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR06MB7102 Content-Type: text/plain; charset="utf-8" When a block read returns an invalid length, zero or >I2C_SMBUS_BLOCK_MAX, the length handler sets the state to IMX_I2C_STATE_FAILED. However, i2c_imx_master_isr() unconditionally overwrites this with IMX_I2C_STATE_READ_CONTINUE, causing an endless read loop that overruns buffers and crashes the system. Guard the state transition to preserve error states set by the length handler. Signed-off-by: LI Qingwu --- drivers/i2c/busses/i2c-imx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index dcce882f3eba..85f554044cf1 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1103,7 +1103,8 @@ static irqreturn_t i2c_imx_master_isr(struct imx_i2c_= struct *i2c_imx, unsigned i =20 case IMX_I2C_STATE_READ_BLOCK_DATA_LEN: i2c_imx_isr_read_block_data_len(i2c_imx); - i2c_imx->state =3D IMX_I2C_STATE_READ_CONTINUE; + if (i2c_imx->state =3D=3D IMX_I2C_STATE_READ_BLOCK_DATA_LEN) + i2c_imx->state =3D IMX_I2C_STATE_READ_CONTINUE; break; =20 case IMX_I2C_STATE_WRITE: --=20 2.43.0 From nobody Mon Feb 9 12:44:45 2026 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010044.outbound.protection.outlook.com [52.101.69.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B446134214A; Fri, 16 Jan 2026 09:17:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768555035; cv=fail; b=tceUCzt8Tql2MAdtvZQP+mULuNvxxxGPMKgEPHqUSjqBnk2XkjNkqe5TiljVv5fuYJWjjmykiD578OK3b4/rTQOGvuoxoofC2dEUoPJNBEjqw6EX7mAuCj6jTV88fFne0UiGhb9c2fCeRyTZmQRchIfe96gwrnhJnyOQDOE6IN4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768555035; c=relaxed/simple; bh=nEUWuJfz8h+XuKHimyqpmW9aC8sbMb4pZObqVC6n11k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YTXnai83hyHvsPtFWhgCJpWzxSej27CK716MlvQoIMZpkAfFTZ3du4s6DkWfyYFVN9Snzd3FfAEb9VogdUAoi6nlw5lzY5Gej3btf/qxsCFrx2s9MbVEsRy5xIs1yKwjV8nIqY288QolC5PzZ9EO0b5BRUGH37aOIkRFIW2ivQI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=leica-geosystems.com.cn; spf=fail smtp.mailfrom=leica-geosystems.com.cn; dkim=pass (1024-bit key) header.d=leica-geosystems.com.cn header.i=@leica-geosystems.com.cn header.b=OpoJsVaf; arc=fail smtp.client-ip=52.101.69.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=leica-geosystems.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=leica-geosystems.com.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=leica-geosystems.com.cn header.i=@leica-geosystems.com.cn header.b="OpoJsVaf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pqKtUwgU1brI1xh/e+Yq9DbJlzBrtCySk9Bwjywmt0i1Jojfj3k0ogf0yjgRo0AzAtkdyKycVIqHc6wjo+4K1B+CUfvx6L+iqq8lnCCiYc8W5giSYgtS/Vd19JzI0GprMGGrOry2FEHyl6iDt9I5gv7Gy6eQGm25oGJUxYXdj3ocENmtvw+wOw2ha/IzJZ54bVIIG28+TXpO3tVTm2tOgPYeF0TNaGq17KYnkbdQJLM8pJbQXv6dJPv5bR4duL7N4mChE1zwjWPnPdAmS/aXCiZtNqXcmInJQMzM37WQFOMajvY4JAw0z8Xg3TnF19CNTdPQr34+UWC77N6QQX+JIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=sDABDkSwpunIdkRyqxG4Q7jtF8dAxzQIhAzsw4Vcg+Q=; b=NQuCM1KdFHivXH3tVaRTxMFZTfW9obO1HBTWS7vuzJFN92U6+iN8lF0jd95IVb6zcRgq2UATA4XPemXrIa/SizEYbFlTaJfwIm1vz57w6UKgHHrzNef6vDEtzyGBIsQQJoozC680vEz92JCqyDtpoc1lPfIOUFQnWslM+tJr1D9480TCfYaVnOwsxTFQ4qn2l9j8o23M34kfg11yhI1BxgYSPk2u1Yqi+q07a0yHPyKuP/2LovvK7F1f+vPDU0xy1yid8GOLkVHvJF+QjoXsPqjY23eEJiZZjSsdrP/ojg9CFJuE7/oAGLH3RU0zAxzu0tsUzRgVKsNTlBHQ2M55hQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 193.8.40.99) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=leica-geosystems.com.cn; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=leica-geosystems.com.cn; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leica-geosystems.com.cn; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sDABDkSwpunIdkRyqxG4Q7jtF8dAxzQIhAzsw4Vcg+Q=; b=OpoJsVafkVO3niIKvIL6ZX+29WHS2bD5ChOJMUNm0xThjZc+iuAgGK9cw6RD/OrsIFAtB/8BfNjTa44AyuVZQAGsC5WBYRHXai6MXDgbOVR40742ao2n88JJ4Jv4sEPtIhvsA9661DISg8bjuTZjSXyjdHrlu3ihKwdyTHaZO9Q= Received: from AM0PR02CA0191.eurprd02.prod.outlook.com (2603:10a6:20b:28e::28) by VI1PR06MB6461.eurprd06.prod.outlook.com (2603:10a6:800:121::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.6; Fri, 16 Jan 2026 09:17:08 +0000 Received: from AMS0EPF0000019F.eurprd05.prod.outlook.com (2603:10a6:20b:28e:cafe::6f) by AM0PR02CA0191.outlook.office365.com (2603:10a6:20b:28e::28) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9520.5 via Frontend Transport; Fri, 16 Jan 2026 09:17:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 193.8.40.99) smtp.mailfrom=leica-geosystems.com.cn; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=leica-geosystems.com.cn; Received-SPF: Pass (protection.outlook.com: domain of leica-geosystems.com.cn designates 193.8.40.99 as permitted sender) receiver=protection.outlook.com; client-ip=193.8.40.99; helo=hexagon.com; pr=C Received: from hexagon.com (193.8.40.99) by AMS0EPF0000019F.mail.protection.outlook.com (10.167.16.251) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9542.4 via Frontend Transport; Fri, 16 Jan 2026 09:17:08 +0000 Received: from aherlnxbspsrv01.lgs-net.com ([10.61.228.61]) by hexagon.com with Microsoft SMTPSVC(10.0.17763.1697); Fri, 16 Jan 2026 10:17:06 +0100 From: LI Qingwu To: o.rempel@pengutronix.de, kernel@pengutronix.de, andi.shyti@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, linux-i2c@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: bsp-development.geo@leica-geosystems.com, LI Qingwu Subject: [PATCH V2 2/2] i2c: imx: add abort path for invalid block length Date: Fri, 16 Jan 2026 09:17:04 +0000 Message-ID: <20260116091704.3399142-3-Qing-wu.Li@leica-geosystems.com.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260116091704.3399142-1-Qing-wu.Li@leica-geosystems.com.cn> References: <20260116091704.3399142-1-Qing-wu.Li@leica-geosystems.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 16 Jan 2026 09:17:06.0418 (UTC) FILETIME=[E265DD20:01DC86C8] X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF0000019F:EE_|VI1PR06MB6461:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c1d0718-36cc-4354-91da-08de54e005e3 X-SET-LOWER-SCL-SCANNER: YES X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|1800799024|376014|921020; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?0gGUfoirM6mERlNEKkREYtzyDd8iQmuvPwxFnYPXgyoBh/EBqxzU1u6l7zZC?= =?us-ascii?Q?7VE1BstGi2fjoLjmY4Guer6kDyjgjTKra4NG+cjnqHr2hFbnK/zosgvWYM/4?= =?us-ascii?Q?Xm+eczZxzHcAoNq02Tg4ye4ooY9U0/VQ7CdAYqVG7NecwqOD7TSMXr81jHLj?= =?us-ascii?Q?iaAIwiPfK+icSR0/tvWRw3Vo7r/mhr7c62JOV9u72Eip+kUN0tVl9QtMqNdQ?= =?us-ascii?Q?UkLT1MhigGxs5iR+vvWjcZdEZVTyoSVAGIaeqp+2ufFQcr8Bo63mfvopR7fO?= =?us-ascii?Q?dyvlc/2NNNc3+BIPbivyTV0V7SKtHqMLq3j4eq7YytDTow0NmZml6OGxj9WM?= =?us-ascii?Q?zCqYqgW5qfEkrIbsd6/0dl0auemk+HXYnkn3/XJ8jD50admrNanEC/RDw7zG?= =?us-ascii?Q?7FsUkK9/hpB5k5mfdQ8uYutwjnAvTkj0llQBNplVV7lTmAtzwFAyVIfslCDA?= =?us-ascii?Q?1iwk3r5I8kKIbrn9XKLEFH/8o+C4k5eTsHqmK/UW/7Tdinsq7KniRpfhHJED?= =?us-ascii?Q?qScaSTUw0D9RBYg5ZSrTCBz3t+qlCEoZiF5bh2iY6X3xYk6+f0wozr3wEus6?= =?us-ascii?Q?ilGrKczDb87cVCYvbJ0NNAW5uQ1Ur7uaG861vghL3Dr0mFjl4VxqI1u2nPHc?= =?us-ascii?Q?3bAeepFQZByZe97woFw1eN4Ai2Fq1vt/A3povMtWfqNDrRrQ5df1GToayOSY?= =?us-ascii?Q?xEPdr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q6aPlzBhM9/lxcnj+o?= =?us-ascii?Q?bS7DncyPVB9ds0FAAZ8PS2yTyk32UZH92nNidhpn937XhJTAJW65c5EcO1vZ?= =?us-ascii?Q?F7+3eqg3rTIoYfeuL5DOVB6K3to=3D?= X-Forefront-Antispam-Report: CIP:193.8.40.99;CTRY:CH;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:hexagon.com;PTR:ahersrvdom51.leica-geosystems.com;CAT:NONE;SFS:(13230040)(36860700013)(82310400026)(1800799024)(376014)(921020);DIR:OUT;SFP:1101; X-OriginatorOrg: leica-geosystems.com.cn X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2026 09:17:08.0384 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c1d0718-36cc-4354-91da-08de54e005e3 X-MS-Exchange-CrossTenant-Id: 1b16ab3e-b8f6-4fe3-9f3e-2db7fe549f6a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=1b16ab3e-b8f6-4fe3-9f3e-2db7fe549f6a;Ip=[193.8.40.99];Helo=[hexagon.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF0000019F.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR06MB6461 Content-Type: text/plain; charset="utf-8" When a block read returns an invalid length (0 or >I2C_SMBUS_BLOCK_MAX), the current implementation leaves the bus hanging with SDA held low, blocking all further I2C communication on the bus. Add a dedicated IMX_I2C_STATE_READ_BLOCK_DATA_ABORT state and ISR handler to properly terminate the transfer when an invalid block length is detected: - Set TXAK and receive the next byte with NACK - On the following interrupt, generate a Stop condition - Read and discard the final byte - Report -EPROTO to the caller This ensures the bus is released correctly and allows other devices on the bus to continue operating normally. Tested on i.MX 8M Plus with continuous block read operations. Signed-off-by: LI Qingwu --- drivers/i2c/busses/i2c-imx.c | 55 ++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 85f554044cf1..71457dbffb7a 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -233,6 +233,7 @@ enum imx_i2c_state { IMX_I2C_STATE_READ_CONTINUE, IMX_I2C_STATE_READ_BLOCK_DATA, IMX_I2C_STATE_READ_BLOCK_DATA_LEN, + IMX_I2C_STATE_READ_BLOCK_DATA_ABORT }; =20 struct imx_i2c_struct { @@ -1054,14 +1055,60 @@ static inline void i2c_imx_isr_read_continue(struct= imx_i2c_struct *i2c_imx) i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] =3D imx_i2c_read_reg(i2c_imx, I= MX_I2C_I2DR); } =20 +static inline void i2c_imx_isr_read_block_data_abort(struct imx_i2c_struct= *i2c_imx) +{ + unsigned int temp =3D imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + + if (i2c_imx->is_lastmsg) { + /* + * Last byte to read. + * + * Ref: IMX8MPRM Rev. 1, 06/2021: 17.1.4.4 Generation of Stop + * + * Ref: IMX8MPRM Rev. 1, 06/2021: 17.1.4.4 Figure 17-5. + * Flowchart of typical I2C interrupt routine + * + * Before the last byte is read, a Stop signal must be generated. + */ + temp =3D imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + if (!(temp & I2CR_MSTA)) + i2c_imx->stopped =3D 1; + temp &=3D ~(I2CR_MSTA | I2CR_MTX); + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); + i2c_imx->state =3D IMX_I2C_STATE_FAILED; + wake_up(&i2c_imx->queue); + } else { + /* + * Next-to-last byte to read. + * + * Ref: IMX8MPRM Rev. 1, 06/2021: 17.1.4.4 Generation of Stop + * + * Ref: IMX8MPRM Rev. 1, 06/2021: 17.1.4.4 Figure 17-5. + * Flowchart of typical I2C interrupt routine + * + * For a master receiver to terminate a data transfer, it must + * inform the slave transmitter by not acknowledging the last + * data byte. This is done by setting the transmit acknowledge + * bit (I2C_I2CR[TXAK]) before reading the next-to-last byte. + */ + temp =3D imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR); + temp |=3D I2CR_TXAK; + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); + imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); + i2c_imx->is_lastmsg =3D true; + } +} + static inline void i2c_imx_isr_read_block_data_len(struct imx_i2c_struct *= i2c_imx) { u8 len =3D imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); =20 if (len =3D=3D 0 || len > I2C_SMBUS_BLOCK_MAX) { i2c_imx->isr_result =3D -EPROTO; - i2c_imx->state =3D IMX_I2C_STATE_FAILED; - wake_up(&i2c_imx->queue); + i2c_imx->state =3D IMX_I2C_STATE_READ_BLOCK_DATA_ABORT; + i2c_imx->is_lastmsg =3D false; + return; } i2c_imx->msg->len +=3D len; i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] =3D len; @@ -1107,6 +1154,10 @@ static irqreturn_t i2c_imx_master_isr(struct imx_i2c= _struct *i2c_imx, unsigned i i2c_imx->state =3D IMX_I2C_STATE_READ_CONTINUE; break; =20 + case IMX_I2C_STATE_READ_BLOCK_DATA_ABORT: + i2c_imx_isr_read_block_data_abort(i2c_imx); + break; + case IMX_I2C_STATE_WRITE: if (i2c_imx_isr_write(i2c_imx)) break; --=20 2.43.0