From patchwork Wed Oct 2 14:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13819876 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AAA1FCF6D35 for ; Wed, 2 Oct 2024 14:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Cc:To:In-Reply-To: References:Message-Id:Subject:Date:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3YWxQFGJdigrMlzaK0m2w9MTLz1GxfqxTQt41pekJSg=; b=Am02wvBC9wLineVc+KUPpeveBO wps9KTMbMHZ49uRsPmdUVnZluj8U5DIiEQvOi+GWqLDtaPHkpTbePOpWADcbV3bcB4F9OJbPqxeg4 RB0gbBtHLfr8sENxdvqJiYndDHEZ1b+pVgY2WK6qvXfetWXDl6NPqBzHiLtcKXfLny0EJW0+j7Cw/ t4vF2/wkwfF7DjVYzp1sftJFN1OlHpXZwGUOD/m3mJv+PG/2coF+StcKUfJr9iNCOthEpjFuvpP4t gZEjUA1sQuk2bfzDgWZFej1eBLOUfSG9sc1ks/QqRfur9h/+C47QkQCV+ZcEotXXJwHFDH0+fFsMw wV2MPJ3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sw0hr-00000006SxH-1gHQ; Wed, 02 Oct 2024 14:51:59 +0000 Received: from mail-am6eur05on20610.outbound.protection.outlook.com ([2a01:111:f403:2612::610] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sw0h5-00000006Sin-1tTE for linux-i3c@lists.infradead.org; Wed, 02 Oct 2024 14:51:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KDpFlRKOfqscIwMUlv7EmR0JPzXfERhf5kzhGgvzgfuglacLItBOphybdR2wGm9qnLTqQBF+WaWDEN76TAUhVmpKyWj7KRRnwWGtFUZ/ZsQLaD4FF2i2/REGYQVziBEb5VSAavARVHM96xq4E7Zb6KoEPugMYQsNVMjYNiFjFUOUHeBLurd+A6Jr+LdpYYffnMaQDO33Kmnc8K8L0VSNMyE6gDvVDQTAo0iK8HAsitvwFqt4EtlkQxWX5Cm37+hJeS346FTXlbejNeSeRPs0BeJQOONJvZ8QfXIB4dBiQfzNasknDfLGGrfhhopALeKtmwAZadeNtUH/cZri1x/Evw== 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=pG/i8HsPY7XlHxdpjxt1xiQs79KpN78+7TFWBBmUyn4=; b=jxEEVW8MphB3BXTuBR8FpkTTR+mWupxlrp3fQri/sBjRbd1Ks/IWJay7FkFRKf/dN/++Rtnoxf3usMfkGKhFbhFN0GgcBtrpQAmJuJMTk4+RoH/Y+QeLNzI1A9DybRwgDbfIwV67ccA3tNbPf0OUdDhuNiWjhtTjrLygrbXcGdr9znxYlEhLlrD1T0VavfUR7b70A5c5B8V4pP9qv/je2zi4AUVOPw1mGVp3FN8528Oi/96roDzmO4TyHjhJ/1+7gjE0Tkx5UeLfGxGH9jfmb3AanHoMYYPvzc+HgiPI+hJhJYwKsKsUuHvvisqFew7v16VmMaKOgzECH7zmCUpo5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pG/i8HsPY7XlHxdpjxt1xiQs79KpN78+7TFWBBmUyn4=; b=L0G+Cpc5QKvJ7BH2Kn8+2DTYUrWO731v3SHmSCgxqZw9gliH8iSJhwJNad0x208PGFvIOWJvH8rMLEPuwZWdm40/0aqIK6+UgAle03nAx+BTN/GM0abssWPlHvcqvEqmW6Xw8hkQeiY/T+VvLEvZ5Xu712au3YIclXRgtxEKObLUDd6OOx+60PNgjZpttXlT3C0eS8H4m+Y8+mrPB0OzL4GhSQMhVqXWhBIy76te5XmvOC/o+04Cx9h9/2FV7M6wh2nn/bA4JH5twsFAFvehVsHzItIlsj0GNIwNGEjAXpagvdXhaf1a7w22+sy6yxLyVJrcJhMtoddS6ZAuMT2jkg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS1PR04MB9699.eurprd04.prod.outlook.com (2603:10a6:20b:482::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Wed, 2 Oct 2024 14:51:06 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8005.024; Wed, 2 Oct 2024 14:51:06 +0000 From: Frank Li Date: Wed, 02 Oct 2024 10:50:38 -0400 Subject: [PATCH v6 6/6] i3c: master: svc: fix possible assignment of the same address to two devices Message-Id: <20241002-svc-i3c-hj-v6-6-7e6e1d3569ae@nxp.com> References: <20241002-svc-i3c-hj-v6-0-7e6e1d3569ae@nxp.com> In-Reply-To: <20241002-svc-i3c-hj-v6-0-7e6e1d3569ae@nxp.com> To: Miquel Raynal , Conor Culhane , Alexandre Belloni Cc: linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Frank Li , stable@kernel.org X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1727880649; l=3214; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=mTP2BQfrL2ajg1eLnU3vD3yNZnTqEe/2FbB25MGO4Kg=; b=/j4Z1kpOPNXOtRhpr8OSpnJ12IrkyS73HdhZikRFyEIZYibXeJA60RWSmusqukin5vvXGJLfy O4s91/3DMDaDl4843Cf4eMchhEJFNT4Zbg9ubDnITeTjYzQ9qwBkgQC X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR13CA0177.namprd13.prod.outlook.com (2603:10b6:a03:2c7::32) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS1PR04MB9699:EE_ X-MS-Office365-Filtering-Correlation-Id: 4417582f-8a88-49e5-3935-08dce2f1a4a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|52116014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?FjubGUGi3uJOepWT3rC46PHUmICIqMS?= =?utf-8?q?JQ5/kaQtJpFRjRJ36xvCbxKMME+h4TujE8ZZ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p1Pm2wBwxFKS1ojdsssVN0AOC?= =?utf-8?q?YSzQBKTLH+l7xHBxV+03M71qHLSrAHNh/vL4w7qm0QieMJ3MNYGfJ3bEpltvmiPqS?= =?utf-8?q?xPWykHSzDmO75FiJ7BWnydQ2a/LHLfdCJ5KeplJgTLTWj2PeM4WEp8tTD54i1A/ea?= =?utf-8?q?HE5WBCORZpxd9cpU513ZraAgINxQBEJUIqhhkCQ5TPSAWe8C6yXY2xragADV2x1ep?= =?utf-8?q?iBauUhlwlm6Lx1D2eSxWTNM4GUb/XrjzRRPKrVwEucDS6CAZgWxs5luCQbP5p66xJ?= =?utf-8?q?uFupwr2wzUf0IGJ0Rtck4unUqfGUDU/NOr1qu0sh8XXtJe1fF9/5087kba7b65dEF?= =?utf-8?q?HCdu3W/eTiUg4pC8x4fmhzJAkVgKb5XVqZw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?EZQU6cP24CUVUBhgidL1Pw0aA0j9?= =?utf-8?q?gCe9E00+eRM291d0oHXYpo/h9t6adMS3DZDI40kmlmcRqOgZ8yNKWvXukV/vAX5pN?= =?utf-8?q?+iRMSWNfDQCgjlsv0Y9/Z/h0dZOohnJUW6n2OCStN3Vlb5ejxuyoj9gyd+BPI2X7W?= =?utf-8?q?QGkUBx7Zrh0Tv0WN0RqLEZivjRGxUI3womyN36HsRCdqjx9maloRiEBUF7NVe3t5o?= =?utf-8?q?W5mi9rvpYDgNnK8EZ3W0EAblOCbvwnGQgoqRkV1eP76pLWMMsKaagpDPa1mfzIeAD?= =?utf-8?q?Lysn+bYK3YmDb8o7n3Zongq5MLedb0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TazNegc8QtcYvIvPUb2NHOA2?= =?utf-8?q?85wm2RMaoCj6Uy60rhMI2zZjP7i0ntyTG7nR6cdt70aaR25PnMQq18tsH+9hoYT9Y?= =?utf-8?q?7OUPvIAczmO7GwzytxLdCMuuuwB+KjaORBbimozRRS9uRK+gtMlBS+l1IjHRoaZv8?= =?utf-8?q?WeFQ0KA2Ggo9dZtHcWm8KB3TzJlURo17uzLU1fjx8SgXehTHdLf+rE8vohnxMc6oa?= =?utf-8?q?DkPw/PtG0vTp9FcLZJGnBWJ2DY/IjfXelLz8vUL9rN9AmqB9L6/rRKm21AsSWjYTJ?= =?utf-8?q?6jdx0wLagTcWWU5excWeANMs2gTlAbfV3LhryUjfP9wJUCkX7guR5jmbObwqv9MWj?= =?utf-8?q?y52iTudqCP9n?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4417582f-8a88-49e5-3935-08dce2f1a4a1 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2024 14:51:05.7505 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BUUt7pytChGHV8EOUenVS2yxr5bhQsjm5AXpNcVWdH0WiuzfH80YMGHg4NyqFa7R4lqd9wJPSD/XjOytB84qgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9699 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241002_075111_534643_8493CAF7 X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org svc_i3c_master_do_daa() { ... for (i = 0; i < dev_nb; i++) { ret = i3c_master_add_i3c_dev_locked(m, addrs[i]); if (ret) goto rpm_out; } } If two devices (A and B) are detected in DAA and address 0xa is assigned to device A and 0xb to device B, a failure in i3c_master_add_i3c_dev_locked() for device A (addr: 0xa) could prevent device B (addr: 0xb) from being registered on the bus. The I3C stack might still consider 0xb a free address. If a subsequent Hotjoin occurs, 0xb might be assigned to Device A, causing both devices A and B to use the same address 0xb, violating the I3C specification. The return value for i3c_master_add_i3c_dev_locked() should not be checked because subsequent steps will scan the entire I3C bus, independent of whether i3c_master_add_i3c_dev_locked() returns success. If device A registration fails, there is still a chance to register device B. i3c_master_add_i3c_dev_locked() can reset DAA if a failure occurs while retrieving device information. Cc: stable@kernel.org Fixes: 317bacf960a4 ("i3c: master: add enable(disable) hot join in sys entry") Reviewed-by: Miquel Raynal Signed-off-by: Frank Li --- change from v4 to v6 - none change from v3 to v4 - add comments about not check return value - add miquel's review tag --- drivers/i3c/master/svc-i3c-master.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 7ef7e50b4b916..e9c8e340d861b 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -1103,12 +1103,27 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m) if (ret) goto rpm_out; - /* Register all devices who participated to the core */ - for (i = 0; i < dev_nb; i++) { - ret = i3c_master_add_i3c_dev_locked(m, addrs[i]); - if (ret) - goto rpm_out; - } + /* + * Register all devices who participated to the core + * + * If two devices (A and B) are detected in DAA and address 0xa is assigned to + * device A and 0xb to device B, a failure in i3c_master_add_i3c_dev_locked() + * for device A (addr: 0xa) could prevent device B (addr: 0xb) from being + * registered on the bus. The I3C stack might still consider 0xb a free + * address. If a subsequent Hotjoin occurs, 0xb might be assigned to Device A, + * causing both devices A and B to use the same address 0xb, violating the I3C + * specification. + * + * The return value for i3c_master_add_i3c_dev_locked() should not be checked + * because subsequent steps will scan the entire I3C bus, independent of + * whether i3c_master_add_i3c_dev_locked() returns success. + * + * If device A registration fails, there is still a chance to register device + * B. i3c_master_add_i3c_dev_locked() can reset DAA if a failure occurs while + * retrieving device information. + */ + for (i = 0; i < dev_nb; i++) + i3c_master_add_i3c_dev_locked(m, addrs[i]); /* Configure IBI auto-rules */ ret = svc_i3c_update_ibirules(master);