From patchwork Tue Oct 1 16:02:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13818322 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 E36B0CEACE0 for ; Tue, 1 Oct 2024 16:03:57 +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=Dx3qTDk+5kZFD4GOq1eSAnm1U+Q0HZ8Fz5YiJjLaq7A=; b=Onhbk4ALns4lcE+swqMJvZQLCv L4H3BZT7SBFk7nAIaFg/xyTwunvEEoK+kMrDgwR6ID4IkYxtxHAvXCrVroxc7Y7LIxyYRec3x+fOS t6cR79d+UxOu5cBr+Tv1efPlInc/a6u+h2MKW5dUX2RA+wWAwv6Az8NulQ1bX4NkHeNcstNEbH1kI ZAECVDGDq7BSmVvLQyj//ijw6270XkJJq2/6pj2Tm7D5UArU186DnsF58BNDbnD30Q+2TeQ6lHDph jSHTkvGPHduDU62zVC9DqVlsZrYsM47f3u8GQqa8isOHbXsjjq1U8HljWAzZVqdxBO8iRzv9I7bFB Nj7oTKlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svfLx-00000003Pxq-26Ra; Tue, 01 Oct 2024 16:03:57 +0000 Received: from mail-vi1eur05on20629.outbound.protection.outlook.com ([2a01:111:f403:2613::629] helo=EUR05-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svfLv-00000003PvI-31ri for linux-i3c@lists.infradead.org; Tue, 01 Oct 2024 16:03:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CX7JH/69AAEYU85xxdbHUz7zfutJFhkzK4dVtVNxKLDvURXCVBGkAl1QRaGkPkbeHx5zrBYONJ7ytvSlKb2I+yt5IrxdzvRnr8CjDjfwYU8NGl6zoDoWHHsiVzQx+LvZCxBOid3xYYSV3zXmCZ61vXKV5G3/0gfT8LmxtREbxG9JMLPNKCyvX4rITRmWRDkjgOkaFqngojmo7zijm43bPZppuxjAstC5hi54ns1WEhKvdb1Tse4HNIwi+Ni5ViZnY4geNlIytUJkYP4I/fubOcejzqbev0/YuVgM2Mart4PFtQXwTUwEKUDntCRhdm/tzktzKTBoQgTeDDBWbmH9VQ== 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=5cRfK2j38fogPonMcQkqHwej6AD1wb6XToeJuSU7HUk=; b=swipQALJinw05jynUvaosaQuylaulEVHifKmmjCbynuavD42L8mMtqp2HelBJ+RYY5QgE53EvnywTTPd6U4Yde56Ymoa6BmyCeVn5tgjj2ixmdst2Z2gPE63mdYYUs3gOxOD5ScMCej+bmXiAkNc2v07OcLG9izuQe9PJ5P2SAGN/oEN478Rd/eeH4eu92kk4hLsyZR0EV9T2vbnacL7zeob6ldj01W8ENguH1T5fcvCk+dtmWS6wNCXqB9/6FQO8X5NKe12qlYiCRM9fn37fKYuAZhHZjwl3tsaGwSugBp4/TF/27F/13MfdpusGfkNRjZFm2IJHxyebiS/WFmSyg== 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=5cRfK2j38fogPonMcQkqHwej6AD1wb6XToeJuSU7HUk=; b=Iusyqb+hjM/wIDyvF7O+GGlDmACAn6r5Zo9DMmOTtA/EZ5CDxH00I3j47iemPxCzQ1lmjIom1qndPLaXJV+Y6zsbWhXK0B3q2Yg5VvjYGmotZ5NiyorC1gzVr25nUbuwTM5rWHc/RAj2AiYOOlnWa5+I7qkA62TipveQYIWsZ1A1CudX1FQoyatZEwAGKadqCfrldlhRzEBm3luJGcK7683Eo3NawmsQU3ufUL2ItpF9quItOVriy1E2OwKpsee4aIDBIJwqByH6Lr+2+C/8t05TKDEalHCsSp2FcXEQlmDJP9AmCTDB45dsewSOLBBK32cT9OGQ+B8jp96kHWTPVg== 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 VI0PR04MB10437.eurprd04.prod.outlook.com (2603:10a6:800:216::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 16:03:47 +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; Tue, 1 Oct 2024 16:03:47 +0000 From: Frank Li Date: Tue, 01 Oct 2024 12:02:55 -0400 Subject: [PATCH v5 6/6] i3c: master: svc: fix possible assignment of the same address to two devices Message-Id: <20241001-svc-i3c-hj-v5-6-480ab8aed849@nxp.com> References: <20241001-svc-i3c-hj-v5-0-480ab8aed849@nxp.com> In-Reply-To: <20241001-svc-i3c-hj-v5-0-480ab8aed849@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=1727798616; l=3184; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=Lzz1dEezZFI4AwXDduLO9+qDTwqAGzmLOSOsxS0fuR4=; b=TEXoN3k0liEFXoQbSInw+FiOr88enzOfH63V69sf7J/hRdxFHRKNOpX6qM5ZoBKPzNlJpLOAt xLOfabkDbAlAdRypyYDKOEaM4PFYpLyRZOM0vs04xLapuGC51v5u0FW X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SA1P222CA0045.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:2d0::22) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|VI0PR04MB10437:EE_ X-MS-Office365-Filtering-Correlation-Id: e8c6114b-3274-49aa-bc1e-08dce232a1cc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?C305Qg/ZW72UQdXisG4TfnLendPe1SU?= =?utf-8?q?h1HQpH2zTjlWR2RzJb8DtSsKiD0VPpRKR6D8ZnrG3Lg+0IpbGQJLQA3z7wco9xNU7?= =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?q?H8Vgagxl6lgiWBtSxUhFYLOkph49gXld6T4rkx3Dgdbee4tjsQQ8IsCMws13vIkY3?= =?utf-8?q?8987UsuANhgFkZcAAo1hfQ2ut92ABDwONI1LRVSZ01qJo7G+YFMrTlbjmefmvKc/1?= =?utf-8?q?YeGRNAKSjHzEcU0CKoZ0OKCiTn8RHX2yANTVb1OgwCyhTNxo+k4H0lBs6YTIL2MbR?= =?utf-8?q?xskMbBHDPyLupYDLa+odewW1VrQ2Dk6lh01kKP6ipRYiVYUUCnTi8M3Pj6/Y/sZ24?= =?utf-8?q?HjP64vNNG0d46tq6O/aCaKf63Sl+ABiXEsBxrpdnofBrq6JJJcDlAWYWEEgr8OWmS?= =?utf-8?q?ZHXqWmoS9/Okw3LIbs6om5KfNySwKQsT2ZpTJPuzmAqZAY7DgSmLQF8FYoznoduKq?= =?utf-8?q?Vrg5E+/i6c2suA6QbHW7xYugAVpcqRW6KA=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)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?RyCfm40cn0QYXjWepkd9IrgNCA9T?= =?utf-8?q?N/vkLu5wOx3zCIp77CBNeNNuSnlJKKsLeTrC1UU2qKu8MQVaDA1ostP9V4RoXEu7a?= =?utf-8?q?aBOmUKsfRvRSx2RTWoSb376KWpz+WbK9yqvdUupVl+cl6KLS8q/Xog2LL00TschKh?= =?utf-8?q?ArJYg5cbsk7UCVBLqZ0RhcaefkXawOHdZA/tBcTmBAb9/zcnYKFd700l6o+vYeHRY?= =?utf-8?q?PKanKSf0Jg/PJ6Q75zJUuY2CJ+8RVPBqYv/JJ64I/OidsNXl5QOBXj1vXvQy9D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pOrKYIJc19Ny9m9WsU1djoIQ2yunfqA88epX7LQiPqy4tvcdqtIhdx3FXUL?= =?utf-8?q?4ifB+DZeEvVQdGV84JCdLBv7EaU2HqKcWiHNkFh+HHoQWtqAdirA80iUmbArUVTb5?= =?utf-8?q?pk/3x+b08uygYYQkFAmhXDW+Xg2EdP1ykzSZJ4YaW+7sZUn+5KLJLUrUq2wAVwPH3?= =?utf-8?q?Bz6bk2NYtv/ANBRLbPHLUCQZAylePFYr4lhBAjmT/E6oAaK6mB/ukpHEu3SwUxc4d?= =?utf-8?q?0+Vnd22rbccIwmqYgiRlGPYi1R63KwiQw6uwQe9jbkbBJA25JaAN0C2NjaCOZrjCC?= =?utf-8?q?g1y8M57ggFDSo7ABFgT5ZR4VFU5KOSLgwZGmDpptukU/wj/q3mr8v6L8=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8c6114b-3274-49aa-bc1e-08dce232a1cc X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 16:03:47.1323 (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: Ethg2vEHRd6OS0onETZUDnWLTAFeEJH6+QrxXx8RWpOejfhxNDLx5QETYcr4WJNE17NzSJywseWDD1ZYuxt2GQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI0PR04MB10437 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241001_090355_806484_8AD33952 X-CRM114-Status: GOOD ( 15.27 ) 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 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 3388c9af63fcc..7dc52111ee0f1 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);