From patchwork Mon Aug 19 16:02:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13768550 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11012037.outbound.protection.outlook.com [52.101.66.37]) (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 B77AD188CDE for ; Mon, 19 Aug 2024 16:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.66.37 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724083358; cv=fail; b=to7F2CsrTUgqIZVRzRKLW4AA9AbfWd3AkcSfZTA+5jU7kIsE/CklUlD541DkRbTA/sH9EsnIuDdiRXv8fCVbF8jcsWrRAVEFLc2GJ7wj32yemNLGh6+zfNqEYBCIeZA2IXjG1rsf12mztKcFpRIcuhld2drA50L4iUvOcCyH7yM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724083358; c=relaxed/simple; bh=/kxhYgzUferEekPx9wl+SzvtPGPz+R1s1O4alcaJOX4=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=WiQGkkiMnnsMXT4TWFnG84okkDcpNHL4yTvclq4cnhPX9IxT2wsHAPKP0V3mtLLTGVm8fiyElzghMv5WfQY1Pty/Xe2NA8vhusKVuSNdUNOGW9ODlI8wMKAYArbWFhZmjxn6oC+OLlVC7WQtn3fPQzAqmKCgEiDdaMs2SudIJJk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=iEldBPfo; arc=fail smtp.client-ip=52.101.66.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="iEldBPfo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vKLc4nTtfI/DbNMDwnuLohrU5pmnwU7GQMjeS2pljVD81NyAC3B3S1OmB8tIgbr+eSw2aFYbOBbpBF5/ZzA/pYtTCRIvZqQj2/NQrgSjpVsvCqflUkQyPwDioZVaU7N7SglFiKYnBL0Fym+UBFrf01+nJ9fY5MWQA7/kfwsaoiN3tWtcgLDIRenvLs726Mrsm3dLtThAIWhPTyBKMBxSt004JDcgn7QYOgvKpj3RNpFHgrfUGfBcKj1Zh9rS2xZsmj4fqnOwnn+VT4EplpdyHq4Ju6l8a3Odo+BCsT1a0MFrmDYSu3dnMnFJHq/+U7veXu9GoPpDF7hyulvnM/Bddg== 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=05ymFfDlx3mt6M2jYBSt9COY2d4c3YvJgPLK5JzhTZM=; b=c8ggPmEKgEy1wv5qW5BfHrwXZAw57z0W9+rNLUaDiw8AohfqLEdgLEVZhmFIiFk+wuBxhegpo508L5Gr6p/eTSdjpmFalruT8ZL8/oPa17zEgTnAc5UYJVASbydYlbQOeyfZhm7r5ul2iMx9kS36hyljYKRm8I5mPeS0m1g7RvUPw38HJ7O9OMiZWBt4WyajrY46lfhrsjRRT2qHIgRMO3BYjXODHlJzxJxPb0w8vjrEKdd1t2q/tPW8lWUWia84zmbzMme73y6m7r2/WbcCT3Mh3edjxOD68nc/1kgsJk3uC1H8uTe2rf3Tc5OTRtRmjpqVUcjvGVnPgT2oNSXU/g== 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=05ymFfDlx3mt6M2jYBSt9COY2d4c3YvJgPLK5JzhTZM=; b=iEldBPfoPa4CHZSdvVGSJC8AvryvilnMErkGraQB0Gpp9R72NoxzQZmREsSzn/tyKD/tLAsed5Mxw7hGRplQ93rx+Gt569Mad2lu8HE/+mKJqqFOWngh4RGNvvVYHsqYO1YCGQbtWlnEM0gbtciQCbxJKFCVFBBYWp8Zk+WSoPAWUH1ZREeo7SVsa94T6EXl6alJHQ0YOdzVQCGIqpdB6E/v6xaMudH4MI9splMuV7ennHjKCj1zx9mWodLpY5T5lzPS7+KBjvH1dQ/kfdv8YvPWW7SfZ3ULgFl9uw6jcMGZsthWUXh6428aXT+aOCh1zkAhm5HPFoP8S358U3CZkg== 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 DU0PR04MB9659.eurprd04.prod.outlook.com (2603:10a6:10:320::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.21; Mon, 19 Aug 2024 16:02:33 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%3]) with mapi id 15.20.7875.019; Mon, 19 Aug 2024 16:02:33 +0000 From: Frank Li Date: Mon, 19 Aug 2024 12:02:05 -0400 Subject: [PATCH v3 11/11] i3c: master: svc: fix possible assignment of the same address to two devices Message-Id: <20240819-i3c_fix-v3-11-7d69f7b0a05e@nxp.com> References: <20240819-i3c_fix-v3-0-7d69f7b0a05e@nxp.com> In-Reply-To: <20240819-i3c_fix-v3-0-7d69f7b0a05e@nxp.com> To: Alexandre Belloni , Boris Brezillon , Parshuram Thombare , Greg Kroah-Hartman , Boris Brezillon , Arnd Bergmann , Miquel Raynal , Conor Culhane 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=1724083326; l=1988; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=/kxhYgzUferEekPx9wl+SzvtPGPz+R1s1O4alcaJOX4=; b=MoBziw2awxiRpomGR6mnOWKnvE75LqKwPWuK71bCcQ8Hc23Zqeh2jl5t4nWYM9vQmcK/l3aic coB0VToW6zZCXZoILMjBR1lJt3UwfIyva6aBZpW0DrZQn3rvfZPEUFX X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SA9PR03CA0005.namprd03.prod.outlook.com (2603:10b6:806:20::10) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DU0PR04MB9659:EE_ X-MS-Office365-Filtering-Correlation-Id: aebc813c-6100-4561-9897-08dcc06855ea X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?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oETYsCPhLHXuch6DEjAcLk0tgj?= =?utf-8?q?fLaqva/+zR83CXTD+xAKyRRufG74N/2xtWywkBun+EHJFE1cE8GYc3AvEaeDGd3v3?= =?utf-8?q?ZClBVlghYVSw01ABYDMr7Rx7VKhg3JvLZ3cX5lAJQRGndJOlhRrZV7Sj2Vj6Biql8?= =?utf-8?q?zeg55ZobBeK1xqKb5uZLqwm7I6lubG6HRCw9H9/xwsbfdHu2L1hjGQnY508lXavRu?= =?utf-8?q?KFs5ZvO/JpgJZiqnDZV/8jXPgCzJ8GieXBVBdb1FkSCPjzqupgvTUfOuL4V4urPhs?= =?utf-8?q?/l0o5GWFnLP8l3uYySgNSm5OrF7JTGFkz9Wmx/z+ExxK0swC+v9IZ35wqNHqvAOEq?= =?utf-8?q?3wXYao4/K0GMpEhUJceKmVM8G0xISoDKlI7UWQiMptyXM/pOggANIhV+H3ke6PUKw?= =?utf-8?q?/6ct3L4zrYWRFDeJDQMm82tWGCsbpgVzHbzgS+JZOAspwBGu2H9OUTM6ekCpXuf09?= =?utf-8?q?MwoXY/Ce5dbPaF1SoBLujaTgY+cMAK70uQ=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)(366016)(1800799024)(376014)(7416014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?wMifWAGcKZe83zShB4sBoCZrXyuh?= =?utf-8?q?gX9gZ9D74+EmBdLejH1mc97oWgVRvfxYChsEpAbWiOkoQtsZ1Hd/T5n/+0zqnk1Z6?= =?utf-8?q?f+rVDJYJkIdm7VQsgIkvrv4B1tFJMQwfR7b5vI8kaC8ywbOFJOBgmLv/6R8ZZ1k/7?= =?utf-8?q?ydm9VZQ8Re6zEXebf46jx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gpRVG1f4yh4PMRb38s5lNJz6p+GXR7ycanN?= =?utf-8?q?yItmvLcfd/1XGWcvAaZeh784apFJkFWl2nE/Dlzxt22d0x9reOyIrisLPKuulsg3a?= =?utf-8?q?mbwRJ3+c0auHz+C1r5PadLwbMbZEQoQeFZgPl9MxD9hZ3+UaE3CNOGU/8Yrr0vm9H?= =?utf-8?q?qZBRv5YfsTfGMq/U1WNfOua1uDXytGoqAFL05wDVW6MkYA+4nf6kZjBH99HSxBI+Y?= =?utf-8?q?XygYXL8uYGG+6VXOOhjCSbE/UgLmQjcVkNh3aYwUcUpjUreeoe6vaDFyvKIHtrVKx?= =?utf-8?q?e1mcQUyR4rb9TnctkNIC9fU7uWWAQO1AcPC+kOIM8QYpHaPINrpkGnZBtZVbTAGM2?= =?utf-8?q?ZLyvpphwtS1xuajjp484BrqkxVvuCA5bwBNpHs84TdKyvVB/mkU0YOOpFvmpODetm?= =?utf-8?q?JBR94bIX+FqpR6sQIgSMsp9aVC4X9xnrXjbMjuR0U31neBrSfLY6w8Uou4SSYmH6p?= =?utf-8?q?0XDTCqrK0xX+?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aebc813c-6100-4561-9897-08dcc06855ea X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2024 16:02:33.1025 (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: nZ9A1VMGplZ+/0P8woW+FYV1GXQcZYtTrYYf69CDjnYrEQaxyUWJqVSP2Bzzz8S1PzK3Wm5dZaq9OPFQHaqvaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR04MB9659 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") Signed-off-by: Frank Li Reviewed-by: Miquel Raynal --- drivers/i3c/master/svc-i3c-master.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/i3c/master/svc-i3c-master.c b/drivers/i3c/master/svc-i3c-master.c index 2010495906eb3..003565fddc261 100644 --- a/drivers/i3c/master/svc-i3c-master.c +++ b/drivers/i3c/master/svc-i3c-master.c @@ -1042,11 +1042,8 @@ static int svc_i3c_master_do_daa(struct i3c_master_controller *m) 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; - } + 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);