From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 C70881AA1D2 for ; Wed, 27 May 2026 11:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881293; cv=none; b=m5KrHbIICtV79WYvOMFLX16KohZYomiP8ogfo8VUAPNiM+CRHQnBBULWwavXRrVCt1TT9ecenOw/q5KC40QSakpTUEPC2H18cOcmLeg8oHOpGlMAvDvkgdUS1GWKNnJHx9G/1YuRDNmomzL4DZ+5yfS+ItmOObbi27WdcyLybK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881293; c=relaxed/simple; bh=AED9LWUIxYLhM9bfJPCLy77sniwXqpeZtyMxTjvG5Mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qTQSfxfq34OAaHYHDDkpftRRdB0oatuUd8Ql/ud16pspKyrbO5fv408zSCTV1UAud41nQEgCId0lxmdfGpSQjfZI3XIHOr3IsX8W0zICUR70v+9ZoEGci/m7qIrviu2R7qMMJ2UTFrPSd809N1snePf6XsuBPAY5sHzFTjTJWFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Td5KoJpT; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Td5KoJpT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881292; x=1811417292; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AED9LWUIxYLhM9bfJPCLy77sniwXqpeZtyMxTjvG5Mg=; b=Td5KoJpTHMWl0FvjgUEO3AKiT8eSIhZgvrfDxrJxPqOZLW4a0VBNrsjl UpxEhq83VfclQbxWkCuPSK5BYq0vjNjry//ZN2Nq5crdDIM9ISxVe2SXc TMCBHJ//fY6OIUeNv/MUvyyttiHlsck9G8hxp5Ei/JNdQVICkkEwuYGdN 8OQwHfer5o2E0nDSwpJxJOkxZYELsbPxNfxEhjS7x3W4f2o/XmMLvSnx/ prFNaaWDZxWKCTOizaGuTBQpSyS52/8vHIwciuk2YCxqs9g+U/9WT/dEd 8JiXDig9vYJ2IO6NFA1azPNcFvIh2otmSiBuia5Iww1BaMUDm/HH3uk2c w==; X-CSE-ConnectionGUID: 8Q38dwyxQqal2W6gIH9LGA== X-CSE-MsgGUID: aZfmyV0YShK1+SnTvGkEPw== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381705" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381705" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:11 -0700 X-CSE-ConnectionGUID: 0zaioKM7TiCmsBw3CmiiMg== X-CSE-MsgGUID: 3ukmTD2RQp+ZolczDLvXBw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238578" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:10 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/7] i3c: mipi-i3c-hci: Fix race in i3c_hci_addr_to_dev() Date: Wed, 27 May 2026 14:27:52 +0300 Message-ID: <20260527112758.38530-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" i3c_hci_addr_to_dev() walks bus->devs.i3c, which is protected by bus.lock (rwsem). However, it is invoked from the MIPI I3C HCI IRQ handler, which cannot take bus.lock. This allows concurrent device addition/removal in the I3C core to modify the list while it is being traversed, potentially leading to use-after-free or crashes. Remove the dependency on the bus device list and introduce a dedicated lookup table. Add an ibi_devs[] array indexed by DAT entry, maintained under hci->lock. Update the array when IBIs are enabled or disabled, so that it always reflects the set of devices allowed to generate IBIs. Move i3c_hci_addr_to_dev() into core.c, reimplement it using the new array, and add a lockdep assertion to enforce that hci->lock is held by callers. Fixes: 9ad9a52cce282 ("i3c/master: introduce the mipi-i3c-hci driver") Signed-off-by: Adrian Hunter --- drivers/i3c/master/mipi-i3c-hci/core.c | 25 +++++++++++++++++++++++++ drivers/i3c/master/mipi-i3c-hci/hci.h | 1 + drivers/i3c/master/mipi-i3c-hci/ibi.h | 13 +------------ 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 53797841b63f..b19bdff5c5e2 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -22,6 +22,7 @@ #include "ext_caps.h" #include "cmd.h" #include "dat.h" +#include "ibi.h" =20 /* * Host Controller Capabilities and Operation Registers @@ -124,6 +125,7 @@ static void i3c_hci_set_master_dyn_addr(struct i3c_hci = *hci) static int i3c_hci_bus_init(struct i3c_master_controller *m) { struct i3c_hci *hci =3D to_i3c_hci(m); + struct device *dev =3D hci->master.dev.parent; struct i3c_device_info info; int ret; =20 @@ -144,6 +146,10 @@ static int i3c_hci_bus_init(struct i3c_master_controll= er *m) if (ret) return ret; =20 + hci->ibi_devs =3D devm_kcalloc(dev, hci->DAT_entries, sizeof(*hci->ibi_de= vs), GFP_KERNEL); + if (!hci->ibi_devs) + return -ENOMEM; + ret =3D hci->io->init(hci); if (ret) return ret; @@ -647,6 +653,21 @@ static void i3c_hci_free_ibi(struct i3c_dev_desc *dev) hci->io->free_ibi(hci, dev); } =20 +struct i3c_dev_desc *i3c_hci_addr_to_dev(struct i3c_hci *hci, unsigned int= addr) +{ + int dat_idx; + + lockdep_assert_held(&hci->lock); + + for (dat_idx =3D 0; dat_idx < hci->DAT_entries; dat_idx++) { + struct i3c_dev_desc *dev =3D hci->ibi_devs[dat_idx]; + + if (dev && dev->info.dyn_addr =3D=3D addr) + return dev; + } + return NULL; +} + static int i3c_hci_enable_ibi(struct i3c_dev_desc *dev) { struct i3c_master_controller *m =3D i3c_dev_get_master(dev); @@ -654,6 +675,8 @@ static int i3c_hci_enable_ibi(struct i3c_dev_desc *dev) struct i3c_hci_dev_data *dev_data =3D i3c_dev_get_master_data(dev); =20 mipi_i3c_hci_dat_v1.clear_flags(hci, dev_data->dat_idx, DAT_0_SIR_REJECT,= 0); + scoped_guard(spinlock_irqsave, &hci->lock) + hci->ibi_devs[dev_data->dat_idx] =3D dev; return i3c_master_enec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); } =20 @@ -664,6 +687,8 @@ static int i3c_hci_disable_ibi(struct i3c_dev_desc *dev) struct i3c_hci_dev_data *dev_data =3D i3c_dev_get_master_data(dev); =20 mipi_i3c_hci_dat_v1.set_flags(hci, dev_data->dat_idx, DAT_0_SIR_REJECT, 0= ); + scoped_guard(spinlock_irqsave, &hci->lock) + hci->ibi_devs[dev_data->dat_idx] =3D NULL; return i3c_master_disec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); } =20 diff --git a/drivers/i3c/master/mipi-i3c-hci/hci.h b/drivers/i3c/master/mip= i-i3c-hci/hci.h index 41d31a53abd3..b3d9803b1968 100644 --- a/drivers/i3c/master/mipi-i3c-hci/hci.h +++ b/drivers/i3c/master/mipi-i3c-hci/hci.h @@ -65,6 +65,7 @@ struct i3c_hci { unsigned int DAT_entry_size; void *DAT_data; struct dat_words *DAT; + struct i3c_dev_desc **ibi_devs; unsigned int DCT_entries; unsigned int DCT_entry_size; u8 version_major; diff --git a/drivers/i3c/master/mipi-i3c-hci/ibi.h b/drivers/i3c/master/mip= i-i3c-hci/ibi.h index e1f98e264da0..073ca67b7d04 100644 --- a/drivers/i3c/master/mipi-i3c-hci/ibi.h +++ b/drivers/i3c/master/mipi-i3c-hci/ibi.h @@ -26,17 +26,6 @@ #define IBI_DATA_LENGTH GENMASK(7, 0) =20 /* handy helpers */ -static inline struct i3c_dev_desc * -i3c_hci_addr_to_dev(struct i3c_hci *hci, unsigned int addr) -{ - struct i3c_bus *bus =3D i3c_master_get_bus(&hci->master); - struct i3c_dev_desc *dev; - - i3c_bus_for_each_i3cdev(bus, dev) { - if (dev->info.dyn_addr =3D=3D addr) - return dev; - } - return NULL; -} +struct i3c_dev_desc *i3c_hci_addr_to_dev(struct i3c_hci *hci, unsigned int= addr); =20 #endif --=20 2.51.0 From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 7EFC73EEAC6 for ; Wed, 27 May 2026 11:28:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881294; cv=none; b=idmg9C7fmB1RNywxOKSMdEz9x+TH40NgPNk+Oij7sVUHu0L4kU2P2uQxYuDNbGumCzQzsK8+ps+40u+et/VbSTwjtsjrVZC9D241qLgHnp1n0bJU+eGAFDcwzI+YcBWf/0cKm58Lbd+I0s9KFE4IacWiJ7EmpLGx/IiJInPqNrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881294; c=relaxed/simple; bh=gDsxcfg85cTAJxGKjUadiwBxxzUTuggBnRV6qMS3N20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qHSxitmC/n1zVdyTSMmYpLv7lfVlSnH1MrHDMlukidjFlbB4BHNJGU6XuNjbxCzI1YdFDZSfe/ELNl6CQlyjXDlw8EEuyHoxwq7rpYaRTTp7DuArS2DZTm0quJQtWSNyMtQ1a2dsy99zusEL6htHD4umTEd9mU5bp9U550cv7iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Uv7JQZ00; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Uv7JQZ00" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881293; x=1811417293; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gDsxcfg85cTAJxGKjUadiwBxxzUTuggBnRV6qMS3N20=; b=Uv7JQZ00ReakZHEWjihrEjbDukNQaQwVcVAZqf+uDOnrxIwTjiEVkUAP HTBHctvSsLTaA5J4giXb3z2TU9Z3KommTS1RKnPq221DUUxsi1rqRuzf6 iiQ6jtHV7/Yk1kaexa78YtY05eRvTFnlr5Nq6+XOfDHLAcYONWEXT/muU h+swmdFZQMcX/cF6xggM09DitaXLXS2psH1HmVAQEG0RciH10oSoDlHB9 6PDpn4HsM19oXnjWwqcokiGMSr5yvWFHT5OFvTWVcW5L9cN1jdUrDeJI/ rCCYsslYjnJRAiAjd/IeVlLBac7ySifzm46X4sS81udhR/+aT+YecKtte Q==; X-CSE-ConnectionGUID: aHKEXs1IRBuqc4bLaQoi5g== X-CSE-MsgGUID: DilALJqiT0CqgRI67e2xVw== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381710" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381710" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:13 -0700 X-CSE-ConnectionGUID: XuSdtqjdQEaqBZw6PGm7+g== X-CSE-MsgGUID: 0uU54AGTRYi9p0o4XiJOnw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238602" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:12 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/7] i3c: mipi-i3c-hci: Ignore DISEC failures when disabling IBIs Date: Wed, 27 May 2026 14:27:53 +0300 Message-ID: <20260527112758.38530-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Disabling IBIs currently returns the result of the DISEC CCC, causing i3c_hci_disable_ibi() to fail if the transfer errors out. However, the controller has already been programmed to reject IBIs by setting DAT_0_SIR_REJECT, so the target=E2=80=99s IBIs are effectively disa= bled from the host side regardless of the outcome of the DISEC command. At this point, teardown of the IBI infrastructure can safely proceed even if DISEC fails. Note, from then on, the MIPI I3C HCI not only NACKs the target's IBI but automatically sends another DISEC command. Make i3c_hci_disable_ibi() resilient by ignoring the return value of i3c_master_disec_locked() and always returning success. Signed-off-by: Adrian Hunter --- drivers/i3c/master/mipi-i3c-hci/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index b19bdff5c5e2..3ef7faed9957 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -689,7 +689,13 @@ static int i3c_hci_disable_ibi(struct i3c_dev_desc *de= v) mipi_i3c_hci_dat_v1.set_flags(hci, dev_data->dat_idx, DAT_0_SIR_REJECT, 0= ); scoped_guard(spinlock_irqsave, &hci->lock) hci->ibi_devs[dev_data->dat_idx] =3D NULL; - return i3c_master_disec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); + /* + * The DAT entry is now set to NACK and DISEC this target's IBIs, so + * the IBI teardown can proceed even if DISEC below fails, so ignore + * errors. + */ + i3c_master_disec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); + return 0; } =20 static void i3c_hci_recycle_ibi_slot(struct i3c_dev_desc *dev, --=20 2.51.0 From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 A17FB3F6C25 for ; Wed, 27 May 2026 11:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881296; cv=none; b=aFjrUrw1jrvrzhVsCcQ4m1uEKrYBOA5PqzLKwAvFDjxj3fUZIjB2buZOPEGoWP57kmi4mJdj0LyM6dUMEU9SDXYlwIiL8bEa0N6O5DbYBaUFjbdIK4KY6iJvGb/PFUOw3BtbEiu2i9+7Halt1lvYGkLEsusHPSxd6l8PpAurkUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881296; c=relaxed/simple; bh=k6p0xK704uGOe3/KyowiZtFfm7nEdmde+AjkTtVBzWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vBeg31Rac21E/BJ/2iQ6yYpNnI0yhjkIOhFiT23M7JhZXrXI96Jq9KewHmLYVxCqIGHfgnayjBI3NKkikz3f6l3nEQdT/NocgQp8gsr3WKqqCf4wYzxtsVf/B7S/34IWvgklOughcuwvR3/Nc2pnq1kagrX4NBsConHe9tYvQbw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VAHDBtC1; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VAHDBtC1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881296; x=1811417296; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k6p0xK704uGOe3/KyowiZtFfm7nEdmde+AjkTtVBzWE=; b=VAHDBtC1hox5BdA1zN2kvjXtAdl0/RhNL2La3OVy6zRdz5wOBU1rn42r UlRpvoVW+DBWISy1rHq6Q4/y4GyEBAYKh8bCaPxMS3SqlKhSoTTzudaOL aaYa1z2UUe4kZot31tWngdzK2YhBsLGCH7Ishu2KA14kOO1FDz4MnEeys UO7Mr7lXd2+D5LD/w72RM4xKLcO9nuK0hIN0y4U30oqo2vsGcs3he0mG8 gAR6CEcGDg4UiiLexugqzkNi7EGLWohYZgZdd0Yd+5RRO2QtIpV9uHiBK CIdI3LRAqkTvWdtSZD0zDhHFV6eJNHy5UI+34MWucelx/C7QCOdBOG4uw A==; X-CSE-ConnectionGUID: g2UvuE+KSI2/c8mD4yTEfA== X-CSE-MsgGUID: 2VUbIO7/Rn6zW7qsKhZAoA== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381715" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381715" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:15 -0700 X-CSE-ConnectionGUID: C/YsFEH1TeilFsWxfzLWcg== X-CSE-MsgGUID: 9IISkzPOSS6iIUmeALVCAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238613" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:14 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/7] i3c: master: Prevent reuse of dynamic address on device add failure Date: Wed, 27 May 2026 14:27:54 +0300 Message-ID: <20260527112758.38530-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" i3c_master_add_i3c_dev_locked() is called after a device has already been assigned a dynamic address. If the function fails, the address remains marked as free and may be reallocated to another device, leading to address conflicts on the bus. Mark the address as in use even on failure by updating the address slot state to prevent the address from being re-used. Emit an error message to inform of the failure. Signed-off-by: Adrian Hunter --- drivers/i3c/master.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index f87bf0099d3c..7820f58ab4aa 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2345,12 +2345,9 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_= controller *master, bool enable_ibi =3D false; int ret; =20 - if (!master) - return -EINVAL; - newdev =3D i3c_master_alloc_i3c_dev(master, &info); if (IS_ERR(newdev)) - return PTR_ERR(newdev); + goto err_prevent_addr_reuse; =20 ret =3D i3c_master_attach_i3c_dev(master, newdev); if (ret) @@ -2472,6 +2469,14 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_= controller *master, err_free_dev: i3c_master_free_i3c_dev(newdev); =20 +err_prevent_addr_reuse: + /* + * Although the device has not been added, the address has been + * assigned. Prevent the address from being used again. + */ + i3c_bus_set_addr_slot_status(&master->bus, addr, I3C_ADDR_SLOT_I3C_DEV); + dev_err(&master->dev, "Failed to add I3C device at address %u, error %d\n= ", addr, ret); + return ret; } EXPORT_SYMBOL_GPL(i3c_master_add_i3c_dev_locked); --=20 2.51.0 From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 5A0F83E95B5 for ; Wed, 27 May 2026 11:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881298; cv=none; b=HAttmuEX9aAE7WXpbP2Hp/jd5z/rwHrz8G1sxm8eygs4IqBuuTmMiKVCWLbY05PneHrHnbJ0yerPNyyLm/kJFlGNtFJjxG2wOq6GRRdQhODqv5mfbrIku3Xne+ZDRWqQ4AxxmioDCulzMyhSzM5D2ajQg9uKauqplLC9nf32sZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881298; c=relaxed/simple; bh=D+sNiNu3mk4ysboxx0F4qpoHM50NqDvDv7x3LmoHKsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NOn3Aq48E3EN17NmKMPah9kStgj9LrCTIsA9kGTxyhkqhsuypW9sfLIWAT4dEnxkZAHjY/+/JNJZj+s4/JtCr3VJefTJSR9hIr3gUkrq9NAKo9wi+bvThJlozTMN8InL+ym8P2BK2xqaRTGAVF5aIOXk/aeF/zULcwcE14aLoXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MsVv3H4z; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MsVv3H4z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881297; x=1811417297; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D+sNiNu3mk4ysboxx0F4qpoHM50NqDvDv7x3LmoHKsY=; b=MsVv3H4zq1PpPxX+HjrUzrvMz1A2bAq4+DtnwkZnRLZ9UoDeETn9V8g0 D0AD4npGwXe3ZTbAt8wh9s3NKvMqhTqV4DQI9E1UphxQNdQK5Ax2NyLuc /BSP9g8b1kE0shsZ1CCnw+gpT4syJ5QZxOIvcuBE8b1VjdS6X9fnDI8vw JfJvGKLz8FUweOWmTmJk4w1IOvnlle7EFI9NSBEByd4qnA08kFsQe5i9R baTZFYEMRWhs389E7eX2ffaAt7O/BBfRb6HIkI6LuC/ozfDJAmajKnp0c LPlZ2iTdHOpblltH4oMsmvKTCijEIHPrs/f4ePzFdjGbB6M/VJfbdwN7d Q==; X-CSE-ConnectionGUID: 7Mtl7C0xQ5aDYArjAuMOCA== X-CSE-MsgGUID: MpJ61WZKRn65UrNqMoEdeg== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381720" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381720" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:17 -0700 X-CSE-ConnectionGUID: AeHr2tGzTtqhR6eEJu0n4A== X-CSE-MsgGUID: 4yqdNaoISkqSQBNAmlDfAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238634" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:16 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/7] i3c: mipi-i3c-hci: Tolerate i3c_master_add_i3c_dev_locked() failures in DAA Date: Wed, 27 May 2026 14:27:55 +0300 Message-ID: <20260527112758.38530-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" i3c_master_add_i3c_dev_locked() no longer leaves the address marked as free on failure, so aborting the DAA sequence on its error is unnecessary. Failure to register a discovered device does not invalidate the entire Dynamic Address Assignment (DAA) procedure. Align with the behavior of other I3C master drivers by ignoring errors from i3c_master_add_i3c_dev_locked() and continuing enumeration. Signed-off-by: Adrian Hunter --- drivers/i3c/master/mipi-i3c-hci/cmd_v1.c | 4 +--- drivers/i3c/master/mipi-i3c-hci/cmd_v2.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c b/drivers/i3c/master/= mipi-i3c-hci/cmd_v1.c index 75d452d7f6af..3b9345718d27 100644 --- a/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c +++ b/drivers/i3c/master/mipi-i3c-hci/cmd_v1.c @@ -358,9 +358,7 @@ static int hci_cmd_v1_daa(struct i3c_hci *hci) * TODO: Extend the subsystem layer to allow for registering * new device and provide BCR/DCR/PID at the same time. */ - ret =3D i3c_master_add_i3c_dev_locked(&hci->master, next_addr); - if (ret) - break; + i3c_master_add_i3c_dev_locked(&hci->master, next_addr); } =20 if (dat_idx >=3D 0) diff --git a/drivers/i3c/master/mipi-i3c-hci/cmd_v2.c b/drivers/i3c/master/= mipi-i3c-hci/cmd_v2.c index 39eec26a363c..8d93748e858d 100644 --- a/drivers/i3c/master/mipi-i3c-hci/cmd_v2.c +++ b/drivers/i3c/master/mipi-i3c-hci/cmd_v2.c @@ -296,9 +296,7 @@ static int hci_cmd_v2_daa(struct i3c_hci *hci) * TODO: Extend the subsystem layer to allow for registering * new device and provide BCR/DCR/PID at the same time. */ - ret =3D i3c_master_add_i3c_dev_locked(&hci->master, next_addr); - if (ret) - break; + i3c_master_add_i3c_dev_locked(&hci->master, next_addr); } =20 hci_free_xfer(xfer, 2); --=20 2.51.0 From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 49D863F86F4 for ; Wed, 27 May 2026 11:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881300; cv=none; b=dot39hu5VLXqGCZCaU0Yh9NXKTmIfVIxmQVntG9AzyjnrL4JWancw8I5ehGdeqiUWoIH0nkG5l0FLunOR8Jod2y92HTS6zPoVa/XFpf5L7eRkBOpJnY2PeoY9CqPcXoFjEl0HWHcq1d8NqeWXdD2dM8nstm/6VCAGl5AfX6nDvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881300; c=relaxed/simple; bh=2Iq0nkwrTWyxjQPZhGN3MqKxY8ovfTm8N2RMw1tn3sI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q86g0kgxQgw4hjrGyMbyb5efaXhZqcsK3Umw9e0YhxUC1LlzdujJeUHTn4c6DL6yBHcNnACnTnwfYgoy/9fsL9vHZ+4xdO0yzxUJCAL+ub2mFpLcgvVdO5Y2lF79af8KWlyConhhEb4lVnm9kB++9fWFvz9EAIVQH5gSCG+FEGg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EZEFEnEL; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EZEFEnEL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881299; x=1811417299; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2Iq0nkwrTWyxjQPZhGN3MqKxY8ovfTm8N2RMw1tn3sI=; b=EZEFEnELxnDYFirWbkLOpgeXcCrFJGgspvsK9B1Zhdqv6T165yRcPOYA Lt0jeOo7wBZxGI5Hhc6v3vGvlbTQwERsPbMy5VKhmdkv+foBmZDSLaAQS eitKuWn1mDOhEYjMG7fxhUzaAX4GwmiGf2DaQQoGoRxJmAaIXo96SP6d3 1UPCSLMSS+cZw4W+ootNvTnn1RtIqtf0QrOHOcRDAnasoaIFfVLBhykaP 6Sl96wLvIyXnq7cbHDUPoaH/Z8zwZ5P0aC2g4YfK4BPTzg+sX4orgpsIS 8po8wMdG/u6Gia7o956/jLNWLI4YN4gpnKqSQwz2Os17dWTvd3qGwdxqW g==; X-CSE-ConnectionGUID: oELwHbTaRT+ThrTRtiePWQ== X-CSE-MsgGUID: dlpq6QgESEeI9PKa7+P3Fw== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381724" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381724" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:19 -0700 X-CSE-ConnectionGUID: hXeYWTQoR8iMXTCOVNU25Q== X-CSE-MsgGUID: 69/hQMo+QamfvK4r7Cw6UA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238646" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:18 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] i3c: master: Make i3c_master_add_i3c_dev_locked() return void Date: Wed, 27 May 2026 14:27:56 +0300 Message-ID: <20260527112758.38530-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The return value of i3c_master_add_i3c_dev_locked() is not used by any caller, and callers are not in a position to recover from failures in this path. Change the function to return void. Amend the kernel-doc accordingly, fix some grammar and remove a stale paragraph. Signed-off-by: Adrian Hunter --- drivers/i3c/master.c | 17 ++++------------- include/linux/i3c/master.h | 3 +-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 7820f58ab4aa..c1188c5d1f23 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2324,19 +2324,12 @@ i3c_master_search_i3c_dev_duplicate(struct i3c_dev_= desc *refdev) * @master: master used to send frames on the bus * @addr: I3C slave dynamic address assigned to the device * - * This function is instantiating an I3C device object and adding it to the - * I3C device list. All device information are automatically retrieved usi= ng - * standard CCC commands. - * - * The I3C device object is returned in case the master wants to attach - * private data to it using i3c_dev_set_master_data(). + * This function instantiates an I3C device object and adds it to the I3C = device + * list. All device information is retrieved using standard CCC commands. * * This function must be called with the bus lock held in write mode. - * - * Return: a 0 in case of success, an negative error code otherwise. */ -int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, - u8 addr) +void i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, u= 8 addr) { struct i3c_device_info info =3D { .dyn_addr =3D addr }; struct i3c_dev_desc *newdev, *olddev; @@ -2458,7 +2451,7 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_c= ontroller *master, mutex_unlock(&newdev->ibi_lock); } =20 - return 0; + return; =20 err_detach_dev: if (newdev->dev && newdev->dev->desc) @@ -2476,8 +2469,6 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_c= ontroller *master, */ i3c_bus_set_addr_slot_status(&master->bus, addr, I3C_ADDR_SLOT_I3C_DEV); dev_err(&master->dev, "Failed to add I3C device at address %u, error %d\n= ", addr, ret); - - return ret; } EXPORT_SYMBOL_GPL(i3c_master_add_i3c_dev_locked); =20 diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index e2c831fb5354..f73cede87d36 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -615,8 +615,7 @@ int i3c_master_defslvs_locked(struct i3c_master_control= ler *master); int i3c_master_get_free_addr(struct i3c_master_controller *master, u8 start_addr); =20 -int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, - u8 addr); +void i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, u= 8 addr); int i3c_master_do_daa(struct i3c_master_controller *master); int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstda= a); struct i3c_dma *i3c_master_dma_map_single(struct device *dev, void *ptr, --=20 2.51.0 From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 6E9EE3F6C25 for ; Wed, 27 May 2026 11:28:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881303; cv=none; b=sgquBKFj/SUtOh6/zGHjyO0iZdGwfqTalaYMAHDMltIOZURVFSU7HHUFgx1q33Em4/zzt9OrcgH/DXKkp2LGqQFxfd8hB8XvVDPfjOb3cf58ygne14FCLkv4UGEqiKF9UP5jbyNwMwtCRpeoAt1fYZfuMQuaAGZvsc940hE3l4A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881303; c=relaxed/simple; bh=XUzc6ulbVNdnYgoqBi6u1YhjQDUzRLq1VpYaqojUsTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PyG8BWretxjZ+Fmco6xrbTb4eouCm6QusLrib+jrJfKMPlLZaB6xC4iGFCS7PG6HOrb8oL2YJFwZS1u/6nF/BVh2agsLC+RJwqfCmdyIxTiMzD3tV75d+l3/UnV+O3bYopbx1e+j0sWpS2u+Wv5BNB/4XQTsQmMiJMkFvOv6bzI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bKOljVWz; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bKOljVWz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881301; x=1811417301; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XUzc6ulbVNdnYgoqBi6u1YhjQDUzRLq1VpYaqojUsTo=; b=bKOljVWzct/cY+e1dhdQ4SdQ2mEs/SXSqcS2dLV7s9kWiKXyCtlUpiNr qIcwyTd6ubX+Tjh/Z1EUMDcTSH3REFxLpopRqYYChq6BxBHQTmpi4nMhz SbgNWzDzEDooQbYYJedEEtiTaP48bEglpKSxuzZsCRbvzql0RlAPjNl+F XBHHyNvKZTsv7cwlr+IIAY5mFRRQaT3WNdkRgkaDElP3iQjO0aKzNflnZ AEzvXgocyp75dzECIzHq3yml8YJZw2wJaVJpLmL6zWkfb+Rm0yag+WA04 FDa1NO+csA6bZLTbhUbKsk/suCaCW2T2ZVtvqSY3yMDjlxeboxqKbneby A==; X-CSE-ConnectionGUID: d5VEGzfpQUWJLFyyWWJVWw== X-CSE-MsgGUID: OLtEjaKsRpCD8nM9adc1mw== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381735" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381735" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:21 -0700 X-CSE-ConnectionGUID: NhL9fS29QGeRyOKIx693gg== X-CSE-MsgGUID: 81Cr5bmaTe6FjSzjVXXcdQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238652" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:20 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] i3c: master: Move DAA API functions after i3c_master_add_i3c_dev_locked() Date: Wed, 27 May 2026 14:27:57 +0300 Message-ID: <20260527112758.38530-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Relocate i3c_master_do_daa_ext() and i3c_master_do_daa() so they appear after i3c_master_add_i3c_dev_locked(). This ordering is required for upcoming changes where the DAA flow will (indirectly) rely on i3c_master_add_i3c_dev_locked() functionality. Reordering avoids forward dependency issues and keeps related code paths logically arranged. No functional change. Signed-off-by: Adrian Hunter --- drivers/i3c/master.c | 128 +++++++++++++++++++++---------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index c1188c5d1f23..69e19c56f9a5 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1870,70 +1870,6 @@ static void i3c_master_reg_work_fn(struct work_struc= t *work) i3c_bus_normaluse_unlock(&master->bus); } =20 -/** - * i3c_master_do_daa_ext() - Dynamic Address Assignment (extended version) - * @master: controller - * @rstdaa: whether to first perform Reset of Dynamic Addresses (RSTDAA) - * - * Perform Dynamic Address Assignment with optional support for System - * Hibernation (@rstdaa is true). - * - * After System Hibernation, Dynamic Addresses can have been reassigned at= boot - * time to different values. A simple strategy is followed to handle that. - * Perform a Reset of Dynamic Addresses (RSTDAA) followed by the normal DAA - * procedure which has provision for reassigning addresses that differ fro= m the - * previously recorded addresses. - * - * Return: a 0 in case of success, an negative error code otherwise. - */ -int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstda= a) -{ - int rstret =3D 0; - int ret; - - ret =3D i3c_master_rpm_get(master); - if (ret) - return ret; - - i3c_bus_maintenance_lock(&master->bus); - - if (master->shutting_down) { - ret =3D -ENODEV; - } else { - if (rstdaa) - rstret =3D i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR); - ret =3D master->ops->do_daa(master); - } - - i3c_bus_maintenance_unlock(&master->bus); - - if (ret) - goto out; - - queue_work(master->wq, &master->reg_work); -out: - i3c_master_rpm_put(master); - - return rstret ?: ret; -} -EXPORT_SYMBOL_GPL(i3c_master_do_daa_ext); - -/** - * i3c_master_do_daa() - do a DAA (Dynamic Address Assignment) - * @master: master doing the DAA - * - * This function instantiates I3C device objects and adds them to the - * I3C device list. All device information is automatically retrieved using - * standard CCC commands. - * - * Return: a 0 in case of success, an negative error code otherwise. - */ -int i3c_master_do_daa(struct i3c_master_controller *master) -{ - return i3c_master_do_daa_ext(master, false); -} -EXPORT_SYMBOL_GPL(i3c_master_do_daa); - /** * i3c_master_dma_map_single() - Map buffer for single DMA transfer * @dev: device object of a device doing DMA @@ -2472,6 +2408,70 @@ void i3c_master_add_i3c_dev_locked(struct i3c_master= _controller *master, u8 addr } EXPORT_SYMBOL_GPL(i3c_master_add_i3c_dev_locked); =20 +/** + * i3c_master_do_daa_ext() - Dynamic Address Assignment (extended version) + * @master: controller + * @rstdaa: whether to first perform Reset of Dynamic Addresses (RSTDAA) + * + * Perform Dynamic Address Assignment with optional support for System + * Hibernation (@rstdaa is true). + * + * After System Hibernation, Dynamic Addresses can have been reassigned at= boot + * time to different values. A simple strategy is followed to handle that. + * Perform a Reset of Dynamic Addresses (RSTDAA) followed by the normal DAA + * procedure which has provision for reassigning addresses that differ fro= m the + * previously recorded addresses. + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +int i3c_master_do_daa_ext(struct i3c_master_controller *master, bool rstda= a) +{ + int rstret =3D 0; + int ret; + + ret =3D i3c_master_rpm_get(master); + if (ret) + return ret; + + i3c_bus_maintenance_lock(&master->bus); + + if (master->shutting_down) { + ret =3D -ENODEV; + } else { + if (rstdaa) + rstret =3D i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR); + ret =3D master->ops->do_daa(master); + } + + i3c_bus_maintenance_unlock(&master->bus); + + if (ret) + goto out; + + queue_work(master->wq, &master->reg_work); +out: + i3c_master_rpm_put(master); + + return rstret ?: ret; +} +EXPORT_SYMBOL_GPL(i3c_master_do_daa_ext); + +/** + * i3c_master_do_daa() - do a DAA (Dynamic Address Assignment) + * @master: master doing the DAA + * + * This function instantiates I3C device objects and adds them to the + * I3C device list. All device information is automatically retrieved using + * standard CCC commands. + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +int i3c_master_do_daa(struct i3c_master_controller *master) +{ + return i3c_master_do_daa_ext(master, false); +} +EXPORT_SYMBOL_GPL(i3c_master_do_daa); + #define OF_I3C_REG1_IS_I2C_DEV BIT(31) =20 static int --=20 2.51.0 From nobody Mon Jun 8 18:55:22 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 535623F8898 for ; Wed, 27 May 2026 11:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881304; cv=none; b=bxx/HSRPC/DWQfWUwuvHeEVG8WWNPqxBmIpFQWgWqNWHGpgmmbtXOffnnclm92XxBQauij02BV+lIKJINRVS8RUo/xFnxAaLy0t4M4RVPG0E8dxUGXzahBRpyIJoeMAoK+BkvGK4lqz1HsDvlRUY+SFI22Wd3i0M1JeVbpQdke4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779881304; c=relaxed/simple; bh=UdVzoX6TAvkxJCmAld800Acbx2BqoaWKE7AJ/0JgK4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o3PaR291T9u31U8Gzo8P6MBPrNDRZXMho5hKGs/MNs6TbJvlSP6dTaO5hd+yYy423WeqNHq0esdkyMOKwbH9xSuiC4/PHDXzWLxtJAhbMbldDN4RZOF8tSDSFeyJMUfebElAL9XysoHDqJnWD/bte8P3nW80glaK0Wx0298/vE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=C06TWcvB; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="C06TWcvB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1779881303; x=1811417303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UdVzoX6TAvkxJCmAld800Acbx2BqoaWKE7AJ/0JgK4c=; b=C06TWcvBszSgiduYSIVALSLIPmMEw1X1S+V/YTCK4KkixvipKgPaSfl2 Ipr7US/9PplrmITYSaM9zP9TNMoyFwndr/f2nvbV+ZCfcMMDDxH+N3WfV BR0KRX+Rk7pwSmm2NrAsq+hGRhwsxggLxTMZgvg+NIU9zaMzZCbz0QQiW 2wgubdMXD2XpQ0CfDbQJisC2WphbNn5JS15k2HeZAHFWMuRm37wi53AT4 9fudR7TX6FRv3uAGD4DJpVnYKTCZ7Ls7+PfpIWvjMjjmsXXuc76zMqUj3 gKdE/ubJjlFcrsQxcCDv0TVK33gh62PMWvYlfNAEhu6DiblC6YLInD+Gs g==; X-CSE-ConnectionGUID: CxJ/9MYLSxK0hq8shecDAw== X-CSE-MsgGUID: BCXdrni9SoytS6ygNsPq0g== X-IronPort-AV: E=McAfee;i="6800,10657,11798"; a="103381745" X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="103381745" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:23 -0700 X-CSE-ConnectionGUID: R4p11NR6R5+EORFJCibY3Q== X-CSE-MsgGUID: JdJrSb8URbWlMQRAMAEH4w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,171,1774335600"; d="scan'208";a="246238660" Received: from smoticic-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.228]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2026 04:28:21 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/7] i3c: master: Reconcile dynamic addresses after DAA Date: Wed, 27 May 2026 14:27:58 +0300 Message-ID: <20260527112758.38530-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260527112758.38530-1-adrian.hunter@intel.com> References: <20260527112758.38530-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" After Dynamic Address Assignment (DAA), there may be cases where devices have been assigned dynamic addresses on the bus, but are not successfully registered in the device model. This can happen, for example, if errors occur during device addition, leaving the bus state and software state inconsistent. Introduce a reconciliation step to resolve such inconsistencies. Scan all address slots marked as I3C devices by the bus, and compare them against the set of devices currently registered. For any dynamic address that is marked occupied but has no corresponding i3c_dev_desc, probe for device presence using a GETSTATUS CCC. Retry the probe (with exponential backoff delay) to handle transient NACK conditions. If a device responds, register it via i3c_master_add_i3c_dev_locked(). Otherwise, free the address slot so it may be reused in future DAA operations. Note, i3c_master_add_i3c_dev_locked() may fail (again), in which case the dynamic address remains marked as occupied. A future DAA will try again. This also handles a corner case where a device is assigned a dynamic address but not successfully added, and subsequently loses that address (e.g. due to power management). If DAA is run again, the device may receive a new dynamic address while the old one remains marked as occupied. Repeated occurrences of this scenario could eventually exhaust the dynamic address space. The reconciliation step ensures that stale addresses are detected and freed, preventing address leakage. Signed-off-by: Adrian Hunter --- drivers/i3c/master.c | 114 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 69e19c56f9a5..9f91c46b52ef 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include #include #include @@ -1613,6 +1614,56 @@ static int i3c_master_retrieve_dev_info(struct i3c_d= ev_desc *dev) return 0; } =20 +static int i3c_master_getstatus_locked(struct i3c_master_controller *maste= r, + u8 addr, u16 *status) +{ + struct i3c_ccc_getstatus *getstatus; + struct i3c_ccc_cmd_dest dest; + struct i3c_ccc_cmd cmd; + int ret; + + getstatus =3D i3c_ccc_cmd_dest_init(&dest, addr, sizeof(*getstatus)); + if (!getstatus) + return -ENOMEM; + + i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETSTATUS, &dest, 1); + ret =3D i3c_master_send_ccc_cmd_locked(master, &cmd); + if (ret) + goto out; + + if (dest.payload.len !=3D sizeof(*getstatus)) { + ret =3D -EIO; + goto out; + } + + if (status) + *status =3D be16_to_cpu(getstatus->status); +out: + i3c_ccc_cmd_dest_cleanup(&dest); + + return ret; +} + +#define I3C_DEV_PROBE_INITIAL_DELAY_US 20 +#define I3C_DEV_PROBE_DELAY_FACTOR 2 +#define I3C_DEV_PROBE_CNT 5 + +static bool i3c_master_i3c_dev_present(struct i3c_master_controller *maste= r, unsigned int addr) +{ + int delay =3D I3C_DEV_PROBE_INITIAL_DELAY_US; + + for (int i =3D 0; i < I3C_DEV_PROBE_CNT; i++) { + if (i) { + fsleep(delay); + delay *=3D I3C_DEV_PROBE_DELAY_FACTOR; + } + if (!i3c_master_getstatus_locked(master, addr, NULL)) + return true; + } + + return false; +} + static void i3c_master_put_i3c_addrs(struct i3c_dev_desc *dev) { struct i3c_master_controller *master =3D i3c_dev_get_master(dev); @@ -2256,22 +2307,25 @@ i3c_master_search_i3c_dev_duplicate(struct i3c_dev_= desc *refdev) } =20 /** - * i3c_master_add_i3c_dev_locked() - add an I3C slave to the bus + * __i3c_master_add_i3c_dev_locked() - add an I3C slave to the bus * @master: master used to send frames on the bus * @addr: I3C slave dynamic address assigned to the device + * @probe: probe to see if the device is really present at @addr * * This function instantiates an I3C device object and adds it to the I3C = device * list. All device information is retrieved using standard CCC commands. * * This function must be called with the bus lock held in write mode. */ -void i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, u= 8 addr) +static void __i3c_master_add_i3c_dev_locked(struct i3c_master_controller *= master, + u8 addr, bool probe) { struct i3c_device_info info =3D { .dyn_addr =3D addr }; struct i3c_dev_desc *newdev, *olddev; u8 old_dyn_addr =3D addr, expected_dyn_addr; struct i3c_ibi_setup ibireq =3D { }; bool enable_ibi =3D false; + bool no_dev =3D false; int ret; =20 newdev =3D i3c_master_alloc_i3c_dev(master, &info); @@ -2282,6 +2336,18 @@ void i3c_master_add_i3c_dev_locked(struct i3c_master= _controller *master, u8 addr if (ret) goto err_free_dev; =20 + /* + * When a dynamic address is first assigned, there is no need to check + * whether it is still assigned, however, if adding the device fails, + * it will be attempted again later, at which point the address may + * have been lost (e.g. due to power management), so for that case, + * probe to see if the device is still present at the assigned address. + */ + if (probe && !i3c_master_i3c_dev_present(master, addr)) { + no_dev =3D true; + goto err_detach_dev; + } + ret =3D i3c_master_retrieve_dev_info(newdev); if (ret) goto err_detach_dev; @@ -2399,6 +2465,8 @@ void i3c_master_add_i3c_dev_locked(struct i3c_master_= controller *master, u8 addr i3c_master_free_i3c_dev(newdev); =20 err_prevent_addr_reuse: + if (no_dev) + return; /* * Although the device has not been added, the address has been * assigned. Prevent the address from being used again. @@ -2406,8 +2474,45 @@ void i3c_master_add_i3c_dev_locked(struct i3c_master= _controller *master, u8 addr i3c_bus_set_addr_slot_status(&master->bus, addr, I3C_ADDR_SLOT_I3C_DEV); dev_err(&master->dev, "Failed to add I3C device at address %u, error %d\n= ", addr, ret); } + +/** + * i3c_master_add_i3c_dev_locked() - add an I3C slave to the bus + * @master: master used to send frames on the bus + * @addr: I3C slave dynamic address assigned to the device + * + * This function instantiates an I3C device object and adds it to the + * I3C device list. All device information is automatically retrieved using + * standard CCC commands. + * + * This function must be called with the bus lock held in write mode. + */ +void i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, u= 8 addr) +{ + __i3c_master_add_i3c_dev_locked(master, addr, false); +} EXPORT_SYMBOL_GPL(i3c_master_add_i3c_dev_locked); =20 +static void i3c_master_reconcile_dyn_addrs(struct i3c_master_controller *m= aster) +{ + DECLARE_BITMAP(dev_dyn_addrs, I2C_MAX_ADDR + 1); + enum i3c_addr_slot_status status; + struct i3c_dev_desc *desc; + + /* Mark all devices' dynamic addresses in the bitmap */ + bitmap_zero(dev_dyn_addrs, I2C_MAX_ADDR + 1); + i3c_bus_for_each_i3cdev(&master->bus, desc) + __set_bit(desc->info.dyn_addr, dev_dyn_addrs); + /* Reconcile the bitmap with the bus address slot status */ + for (unsigned int addr =3D 0; addr <=3D I2C_MAX_ADDR; addr++) { + status =3D i3c_bus_get_addr_slot_status(&master->bus, addr); + if (status !=3D I3C_ADDR_SLOT_I3C_DEV || test_bit(addr, dev_dyn_addrs)) + continue; + i3c_bus_set_addr_slot_status(&master->bus, addr, I3C_ADDR_SLOT_FREE); + /* Try to add the device, but probe to see if it is really present */ + __i3c_master_add_i3c_dev_locked(master, addr, true); + } +} + /** * i3c_master_do_daa_ext() - Dynamic Address Assignment (extended version) * @master: controller @@ -2441,6 +2546,11 @@ int i3c_master_do_daa_ext(struct i3c_master_controll= er *master, bool rstdaa) if (rstdaa) rstret =3D i3c_master_rstdaa_locked(master, I3C_BROADCAST_ADDR); ret =3D master->ops->do_daa(master); + /* + * Handle cases where a dynamic address was assigned but the + * device was not successfully added. + */ + i3c_master_reconcile_dyn_addrs(master); } =20 i3c_bus_maintenance_unlock(&master->bus); --=20 2.51.0