From nobody Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 8CA9038E8DD for ; Wed, 10 Jun 2026 07:30:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076614; cv=none; b=NKvlWxoZjQNxmsmeQ++ibw/qB5SN0Byv8gQ8Pz3UDOZSOK6JJby63mfl2KfHnUWl8keUTzm+8bHjOh4linzZOZQCB0MO8xEzhCc8+UUWJlsdJo1crPVS0fKq2GYAr5gQy0AhXgtE34gzoqwKCf2Az8ec10+UMPiGfnX8iS9mnWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076614; c=relaxed/simple; bh=q0c2bQqPKdMUDQJks5Kc4HAzA+gxLx6mnJpIIu24xqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZMwpoj7lt+osVTOD+bLinWWb1mPt9q3CHCsE4sGVNkW3ecA5ieXzJgENWwBCeboBn4Ylf5As44jBUQh1CS74d9zw629WxkAJulA7MG6NT8aS4ZweHWfz95e0UQQFpf2Hdy35xFLowptP4SCxJZhoeqDsTYAaj4TgL6E57Le1Gao= 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=LlzSXv9/; arc=none smtp.client-ip=192.198.163.19 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="LlzSXv9/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076612; x=1812612612; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q0c2bQqPKdMUDQJks5Kc4HAzA+gxLx6mnJpIIu24xqM=; b=LlzSXv9/Ak3tR3C2zzXNmyx61wImTtzYugEQ8BkFidLRBMJsG0+cphuB EVkUMR8dhHJVVEEQZnFmRx8eOW7QAWWMgcwgiGO1T6P7lmCZVswe27L9d VO6JO46y9qu+y+/cm7Y8GqYD4uMGPOYIKGV2sE9OatAiXg7angiRg6ej7 HGLPEhs6gfh9/fPujAqgwQKp7bCPA9aTTO3fcKUlhk/H9KQeqzwf9Sz/6 yvp6IwauCWd824tUWarIHxkFzEgb5u3Xlp54PW66QLr5sH5vWM0oDS3Zh cRZwdn7umGz3zZo/Mv3tNQwrJXQLb2pWUXS3NwymehOcfcZVef09u4elA A==; X-CSE-ConnectionGUID: XaUmPEdZQl+rbgLUecKyDQ== X-CSE-MsgGUID: VL/EGPiwRmK51IALioafXQ== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878400" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878400" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:10 -0700 X-CSE-ConnectionGUID: zjSL8ZzhR3CenHybivwFPA== X-CSE-MsgGUID: ADb3O5/pTrWKkKyx8Cldmw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103438" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:07 -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 V3 1/7] i3c: mipi-i3c-hci: Fix race in i3c_hci_addr_to_dev() Date: Wed, 10 Jun 2026 10:28:46 +0300 Message-ID: <20260610072852.36934-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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. Also update when IBIs are freed, to cover the corner case when an IBI is freed without first being disabled (e.g. oldedev in i3c_master_add_i3c_dev_locked()). 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. Demote a message in PIO and DMA IBI handling, from an error to a debug message, because there is a race window when the condition can arise normally. Fixes: 9ad9a52cce282 ("i3c/master: introduce the mipi-i3c-hci driver") Signed-off-by: Adrian Hunter Reviewed-by: Frank Li --- Changes in V3: Add Frank's Rev'd-by Changes in V2: Factor out __i3c_hci_disable_ibi() to facilitate also clearing ibi_devs[dat_idx] upon IBI free, and update commit message accordingly. Demote a message in PIO and DMA IBI handling, and update commit message accordingly. drivers/i3c/master/mipi-i3c-hci/core.c | 37 ++++++++++++++++++++++++-- drivers/i3c/master/mipi-i3c-hci/dma.c | 7 +++-- drivers/i3c/master/mipi-i3c-hci/hci.h | 1 + drivers/i3c/master/mipi-i3c-hci/ibi.h | 13 +-------- drivers/i3c/master/mipi-i3c-hci/pio.c | 7 +++-- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mi= pi-i3c-hci/core.c index 53797841b63f..1e1f05aff092 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; @@ -639,14 +645,40 @@ static int i3c_hci_request_ibi(struct i3c_dev_desc *d= ev, return hci->io->request_ibi(hci, dev, req); } =20 +static void __i3c_hci_disable_ibi(struct i3c_hci *hci, struct i3c_dev_desc= *dev) +{ + struct i3c_hci_dev_data *dev_data =3D i3c_dev_get_master_data(dev); + + 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; +} + static void i3c_hci_free_ibi(struct i3c_dev_desc *dev) { struct i3c_master_controller *m =3D i3c_dev_get_master(dev); struct i3c_hci *hci =3D to_i3c_hci(m); =20 + /* Must ensure the IBI has been disabled */ + __i3c_hci_disable_ibi(hci, 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 +686,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 @@ -661,9 +695,8 @@ static int i3c_hci_disable_ibi(struct i3c_dev_desc *dev) { struct i3c_master_controller *m =3D i3c_dev_get_master(dev); struct i3c_hci *hci =3D to_i3c_hci(m); - 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= ); + __i3c_hci_disable_ibi(hci, dev); return i3c_master_disec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR); } =20 diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mip= i-i3c-hci/dma.c index 87622d6f817e..0672ed1132f8 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -967,8 +967,11 @@ static void hci_dma_process_ibi(struct i3c_hci *hci, s= truct hci_rh_data *rh) =20 dev =3D i3c_hci_addr_to_dev(hci, ibi_addr); if (!dev) { - dev_err(&hci->master.dev, - "IBI for unknown device %#x\n", ibi_addr); + /* + * Either an IBI received just before IBI's were disabled, or + * the controller is broken. Assume the former. + */ + dev_dbg(&hci->master.dev, "IBI when not enabled at address %#x\n", ibi_a= ddr); goto done; } =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 diff --git a/drivers/i3c/master/mipi-i3c-hci/pio.c b/drivers/i3c/master/mip= i-i3c-hci/pio.c index b5ae1cfaa9e0..ff2657ee220b 100644 --- a/drivers/i3c/master/mipi-i3c-hci/pio.c +++ b/drivers/i3c/master/mipi-i3c-hci/pio.c @@ -869,8 +869,11 @@ static bool hci_pio_prep_new_ibi(struct i3c_hci *hci, = struct hci_pio_data *pio) =20 dev =3D i3c_hci_addr_to_dev(hci, ibi->addr); if (!dev) { - dev_err(&hci->master.dev, - "IBI for unknown device %#x\n", ibi->addr); + /* + * Either an IBI received just before IBI's were disabled, or + * the controller is broken. Assume the former. + */ + dev_dbg(&hci->master.dev, "IBI when not enabled at address %#x\n", ibi->= addr); return true; } =20 --=20 2.51.0 From nobody Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 2C90E39150D for ; Wed, 10 Jun 2026 07:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076624; cv=none; b=vGJT3XfmbmSFYpDZ2VLVTUu5HNsMzlb/gXf4b09pO7CevxzlYRKgx/c28aoGcGudjXfHD46EKp4GkjG+zleSIp5FNg3JDHhofY44YiCAvEmwkJURjaPgeYii0pMUTfa4pEb6cjZQTDOVa4WONFONfTxfSrRct2FZiu557+w44Wk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076624; c=relaxed/simple; bh=Iil2ocVoAMeQzOA2FXTuLwD1NAdo6EBe1TOz5vHqZ68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aJPpUUXQ3pjQlgpzV4jS94y989BhNTSGcXRyIH7FBfAtvsgMRdPV/CmZA0s6JpBIfYlLJONhJD5Vc8lDn45k2DfONmMb80k5EbAH0w+U8wJ0hEo86z6c1B7+UJAFINLFaHK3CVVxzV4krQ95vEALatIAEw2CUnr4DpR/WI7RdkM= 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=dd+LA3wB; arc=none smtp.client-ip=192.198.163.19 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="dd+LA3wB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076621; x=1812612621; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Iil2ocVoAMeQzOA2FXTuLwD1NAdo6EBe1TOz5vHqZ68=; b=dd+LA3wBo8SroeiirsK8DQgzKx8gqDnlyW/XyKjWu09DI+Arol5XtuKR eHeP5K6R4+CD0NiX01ooQAt3W3wJhckoNbdBupquKLJz7hsZ20nFLVRB4 BgPOaSGXwjQIUQrgeXpXW7yngJ+qEXRuWeLEsm2T2eirSMikU1KBmVO22 lz9QqozdM6Nx+XaFZOv4jJI/grLElloAiwRMsFBEAwVdWRPwnmV9ES/sv yLbGdbaoBvgGP1kgDifJiwDMuTEROH0Na+JjQLljhQXQ9J8mUcV8IKPpT 9ZOgT4SUpgv73SQp3NYAQ1VxPLF42wK687aOUItZ2PYXh3PgS7/Da6chF w==; X-CSE-ConnectionGUID: 4MX6dWXiQxikgTyWhj7xqg== X-CSE-MsgGUID: I+pvWD3TRfulbw0lKXmzAA== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878411" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878411" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:11 -0700 X-CSE-ConnectionGUID: j11I+wTGQe+lehkty0MWvQ== X-CSE-MsgGUID: cNkLaBDFS/m97YU5ZVSUpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103443" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:09 -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 V3 2/7] i3c: mipi-i3c-hci: Ignore DISEC failures when disabling IBIs Date: Wed, 10 Jun 2026 10:28:47 +0300 Message-ID: <20260610072852.36934-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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 Reviewed-by: Frank Li --- Changes in V3: Add Frank's Rev'd-by Changes in V2: Re-base due to changes in previous patch. 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 1e1f05aff092..fffbc1775ef9 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -697,7 +697,13 @@ static int i3c_hci_disable_ibi(struct i3c_dev_desc *de= v) struct i3c_hci *hci =3D to_i3c_hci(m); =20 __i3c_hci_disable_ibi(hci, dev); - 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 Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 C37A217A309 for ; Wed, 10 Jun 2026 07:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076628; cv=none; b=aV+ulOTwnmznohktb0yUURjPdyoxjEdBzpxswKhf3OO2OUTtm2yHTzc5LYgUuXp18FIHJrFAgcFCBrXPP8FPNIaL1rYXRwCsItZT1abfjgC2cbBRLLmkVxvjbA11kFesmp2U0awWe2LaWBySBwgI1AWC3saNJ1xg+WDiTWI6NIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076628; c=relaxed/simple; bh=5eBs9mdqcoBy37Ne1LxATcEyfoSrgm4NfDJwLYCncEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XHygkZjhw7dYpct/pDS6ZfZqBQyEbqEKZHyeq0JV7QG9Tm62qV3Hw5U2v8YfB02Q7DpxPLhvkCtIBUjRF5pEqFfj46aa0EDHi2RkN1Pl7IXaHAs6gFpnnd+3ycZv4BxNgmalLu8/caiRrIC6JMjyJFRJMj5GV4qFva7jXpDVbnQ= 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=ZkWpkZDN; arc=none smtp.client-ip=192.198.163.19 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="ZkWpkZDN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076625; x=1812612625; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5eBs9mdqcoBy37Ne1LxATcEyfoSrgm4NfDJwLYCncEA=; b=ZkWpkZDNZb1Ch1bfU4vbwEphKDH3QumoRbFTaTut7xY1kQJ0lLSJXY9W bagvZ0/hLqj1F5yyUuCFI0g4/VdT7/rYLdLydEnsjt25emxoMPqlPvqGX yddD9WxtqMoINuwe+T1j39wYqZBgaUziI+llLH+grH3V+YNxTbdFXLguY VYiDQqAJSrykGXWmjm53jfQ8G3NeaXEnkc9KRpyrysG/0aoCWh+bfo238 8et4sFkgD0j1v0WB2Pdc0GPExHHohmyfPu9Cgg2aiW6H599/JAaPv/ENF plzxxwzsTLCMN2BCEghiZrEvLK9LwGW2CaQ7zHgA5aDMQxQoNfYl/MZQC Q==; X-CSE-ConnectionGUID: bGAQeHfTRwOgs69LXi450A== X-CSE-MsgGUID: i2BsrZODQCm2+n8KDIItbw== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878416" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878416" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:14 -0700 X-CSE-ConnectionGUID: m0EYzFSCRKWzhM+35usXzA== X-CSE-MsgGUID: VSRUR3RiT329sxIJ7BN44Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103447" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:11 -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 V3 3/7] i3c: master: Prevent reuse of dynamic address on device add failure Date: Wed, 10 Jun 2026 10:28:48 +0300 Message-ID: <20260610072852.36934-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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. Ensure the address is not marked as free 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. Opportunistically remove the !master check because it is impossible. Note, directly resetting the device's dynamic address is no longer an option, since Direct RSTDAA was deprecated from I3C starting from version 1.1 and v1.1 (or later) target devices are meant to NACK it. Fixes: 3a379bbcea0af ("i3c: Add core I3C infrastructure") Signed-off-by: Adrian Hunter --- Changes in V3: Add note to commit message about Direct RSTDAA deprecation Changes in V2: Fix 'if (IS_ERR(newdev)' error path. Be defensive and do not change the addr_slot_status if it is not free, and update commit message accordingly. Amend commit message to note removal of unnecesary 'if (!master)' check. Add Fixes tag. drivers/i3c/master.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index f87bf0099d3c..7b60b0c7f646 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2345,12 +2345,11 @@ 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); + if (IS_ERR(newdev)) { + ret =3D PTR_ERR(newdev); + goto err_prevent_addr_reuse; + } =20 ret =3D i3c_master_attach_i3c_dev(master, newdev); if (ret) @@ -2472,6 +2471,16 @@ 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. + */ + if (i3c_bus_get_addr_slot_status(&master->bus, addr) =3D=3D I3C_ADDR_SLOT= _FREE) + 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 Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 B6C57391E76 for ; Wed, 10 Jun 2026 07:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076630; cv=none; b=WFlx6lf36kZDvfBcGaGvZS4jgK1v63ZqmASQ2HszKV3OEJvMuD0J5P1NjJwEVgKQF6FdO1IWHP+SDRXKahrtlNzUHQZ2ez7tTVnnK83iGaSKg0RrCE7ZInigxxVAGpBwlVxJd4WcpKs9w96Xo6revrKMlYebK7UeaAsdiEKqo4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076630; c=relaxed/simple; bh=wQbGQYvGdWkBSwq6p0sFNZ0ic8rxEzin36muudEUeSk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SkHhGOfQ17CIKEO+lX10Oj37tHGwlIWGAOJy1vHFofMQAc0fFWnSqK54pzWXsTOthjJJ8C1g0HvLXRcv5DA/4FdAodavNpZ5VBSY+l2HyvuJcd3nRx7/sxOYCgSqzf/NEr7UcEOPsjuZYrYQLW4JK97lCmP1U7HXOuMcl447cow= 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=lu2H3R5U; arc=none smtp.client-ip=192.198.163.19 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="lu2H3R5U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076628; x=1812612628; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wQbGQYvGdWkBSwq6p0sFNZ0ic8rxEzin36muudEUeSk=; b=lu2H3R5UebLeiKQ5pnKhGo3iUINr3XsglSrxxMZ8RXQZe6qUZxrpffxO 0BWcPwSUQe0JI4AZbUOLKw478yurLfGvB6bI+CES5gxhKo1aIebhaF3Mh PS46T1Osm+88ZK6wKz0yds57nQESBzHROM8RnbvTgsyoqyIcahF7uEcD8 mcvGnh3/0ZyU45L0YWy/7/iBVw5MPQZaS7U+JV4EZLO6SxpijymYKhe/H 5HeEP6yYeKE7OMvF+rZypzcD9/NGVGDhW40V7RzUfXKUHtCPR6RwHPXGf WvezyhkFeUGE30H/DFeYeyPYL/dcOiuvXXdTHogkeINgMWeGh1zSQ4Uvo g==; X-CSE-ConnectionGUID: ycXT5fz/QBiZTPtv85B6Tw== X-CSE-MsgGUID: 2JJrNB0HTSGe1maRJVB+tA== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878423" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878423" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:14 -0700 X-CSE-ConnectionGUID: aBvA2gy5RPSJMaR1SUe3lw== X-CSE-MsgGUID: ADZLGl3bQMaZmVBaIMTU9A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103451" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:13 -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 V3 4/7] i3c: mipi-i3c-hci: Tolerate i3c_master_add_i3c_dev_locked() failures in DAA Date: Wed, 10 Jun 2026 10:28:49 +0300 Message-ID: <20260610072852.36934-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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 Reviewed-by: Frank Li --- Changes in V3: Add Frank's Rev'd-by Changes in V2: None 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 Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 C59EB3921FA for ; Wed, 10 Jun 2026 07:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076630; cv=none; b=Xq62TXefJ1r+GjsMpum3nxPN4UWaLf3Vt2oPyBx7txU2jwLVPj4MgtgnNmeafXk37ZJdC+X2t84LPsWSTDW6F07mBbkaLiq240AoCaJFga+lvYFPRAWEA+2hyRVgasTX8+YTpFIdXph70kTfbs5hAesPqdAMscJdYHz51VE63GY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076630; c=relaxed/simple; bh=dsu1ctZ70EilEQnoW4bUeFQgTLsDl9ljkjgC9tN1PQA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jOFf0rjBgiO3CVJp6k8GRwifL3OT+VxLUKnMldFfRo+UPfgf3NtCwrk5yGK2/nzdkrM6VQmGrYLqO17b/GiPiNfwlXgH8NjShMMoTOfQd4oF06r/k9NHH9jLDfGCFxk/nXm849/kjCpBNZ+iaW0onIm3v2qEjeOTVP1G9ZhlJZg= 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=eszXBlB7; arc=none smtp.client-ip=192.198.163.19 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="eszXBlB7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076629; x=1812612629; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dsu1ctZ70EilEQnoW4bUeFQgTLsDl9ljkjgC9tN1PQA=; b=eszXBlB7kM0+p9Zxh/dyYExHXKZx0Hcw+zaLPTbnGQgJKVnAqc+izVeI W9LM8RRCfr3E/niUZuPZgqtT9NMC0F4hE3Wi4YOkK41jWo1ZMFlfyWSUL 6rjXSxzX088DXDI/pgTCITHTWH2UVEvwlORXpbG4yzXk+7hZr4ws0FuKk 35ZfdEppBHPeiTplefCdmj1p0V8HPGupU4wUbbG2baiioPq4mLCmnbdqa KIONNzFiMy9XFrZ0sLY1IMLg3RjfRR64Wx6+bP2gQUsJi2ekFcBU1nbqD g+uf0a3+N/CVAY/oEnY4HmvF6/UDGQOSo/KiX/Ift4JfBSOAQcvab/tAZ w==; X-CSE-ConnectionGUID: mwUFcdDHR1ayzS1bvcwKhA== X-CSE-MsgGUID: SvlaTMEvSmmsqoDCKEEJkw== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878429" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878429" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:16 -0700 X-CSE-ConnectionGUID: oQPr6+EbREiYciZpxb0G6A== X-CSE-MsgGUID: Uoe+C2TcRmuv3nTaHuJ4Zw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103460" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29: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 V3 5/7] i3c: master: Make i3c_master_add_i3c_dev_locked() return void Date: Wed, 10 Jun 2026 10:28:50 +0300 Message-ID: <20260610072852.36934-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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 Reviewed-by: Frank Li --- Changes in V3: Add Frank's Rev'd-by Changes in V2: Re-base due to changes in previous patches. 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 7b60b0c7f646..57857a3351c7 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; @@ -2460,7 +2453,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) @@ -2480,8 +2473,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); =20 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 Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 3B888385D82 for ; Wed, 10 Jun 2026 07:30:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076664; cv=none; b=AKkVtvfHAU80DIDmtswgtRnJ3mmX3VS5a+Yk4mDKhsOhaKq5kj9ajND1dRM2rFoOD/bz9f2Q/t0OlcdfAwXexC6BmLQoHVlamiUH2jNxRNjTTNAdigTzWD0xsuJiuu7MY6eFZAzS23jBSBEe2/GYU06MpYq4+7JO+NMWI6XUYRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076664; c=relaxed/simple; bh=C3IpJhIXMrV0+xcASvxTJ9g5MQtNxuyDVHm85QB4uj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QKnbyFuUZVq29u25zal6mHQ1S0InZWxAMqeDAETMsP6L3dERYEPXwOrvhXAOyT7nAxPtEdkEmj+GmKY4uEhSHL+JbxQBhUjcj5oS5n4kO3Ee1hYDOeGL58WMuWVwxvJKDbKQRJIPapYdGopCyBxZkU3cHwPOcRkd9fI/9xoqlGE= 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=K3SUvB/9; arc=none smtp.client-ip=192.198.163.19 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="K3SUvB/9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076662; x=1812612662; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C3IpJhIXMrV0+xcASvxTJ9g5MQtNxuyDVHm85QB4uj4=; b=K3SUvB/9ajTV1dwMqJTyZULZibQTT567kFKg3Hyb46OBJYXmF8JAqRfa KO2gCkKUg90Y3lDWGdv7x+9vDgsR5j5WHjU4ZJ/cSey5p2XvSh9CFXG8s is2upwcIjmvlyC02IXLGHGtcdpWd4lAoAfvxo3SBkKo6LQO34OvEo0xgE I3F6qy/or1iF6oPi1s440jP4BK/VSr7QB1b+Af/8XmKtc9taohuJNmIle 0Cl68GXz3Ns0zWdUW3uNM1jZ/mlYNjFximuXvC/3AV9AwMFznCojDFeZe U8mQheyHcxN8I5btFtQT7xlhF1b+TGecID9t/QuNOkpsuh9MsLwHv9vF8 A==; X-CSE-ConnectionGUID: U4YvHROqS1yi8N09CVxdSw== X-CSE-MsgGUID: OK9HQY3rQfq/RP24RhnwNQ== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878437" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878437" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:18 -0700 X-CSE-ConnectionGUID: Q/fHU64WRIOp89Xe/Vxrog== X-CSE-MsgGUID: QSX+nhSTQaOjZwQZF2c20w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103486" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29: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 V3 6/7] i3c: master: Move DAA API functions after i3c_master_add_i3c_dev_locked() Date: Wed, 10 Jun 2026 10:28:51 +0300 Message-ID: <20260610072852.36934-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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 Reviewed-by: Frank Li --- Changes in V3: Add Frank's Rev'd-by Changes in V2: None 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 57857a3351c7..5021d25b718a 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 @@ -2476,6 +2412,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 Thu Jun 11 00:03:35 2026 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (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 5823F3921F6 for ; Wed, 10 Jun 2026 07:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076667; cv=none; b=bY8xuys/gKYsc8xhidHyT6wV9jlZRcqGGtTNpjETTV0RYZd4cn8uheh4yTwmd4FA0QiLx12E9ulQXQ1Xt139oqs/Es8ctTrt/UWCXai3zIcC8nFvx39JH34L9tEZrZ9e2A5AaOO3dEOA13P9SRX6fgXOlUCKG2bXhC39v2Cximk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781076667; c=relaxed/simple; bh=k42iJN0x/JU2YmSQpr+aLwWp1U6k8l482wmBhkIL+bE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VjLr+hAPakT3zLR6HnbcXvLDADr1YFHy6vsCl4SZhHXkAJ1UCE9hHOiCrB+vHdauRdBbfJO7CCw8cfbQCfalutH+5mRGDMjSOc+dZTb2WKvfp2mvbvqd3cAhmSaChCaoUjYY7ht4h0o4efLTf8jMMCL8sVcyY0a0+O9qpMt5TO0= 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=ey8YpgBH; arc=none smtp.client-ip=192.198.163.19 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="ey8YpgBH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1781076665; x=1812612665; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=k42iJN0x/JU2YmSQpr+aLwWp1U6k8l482wmBhkIL+bE=; b=ey8YpgBHyPfpyCmNZNsrxaDw50w3zUBlOuw45cTliM4L8lVo5J+/dvW8 KPgxbgRRnRKm9WRO17rWs5ZMjNItGL2MyIaKBNxqgEDwBx7SeoOv9MYyX AxZ8bSbKSdh5T7tJUtlfeyruwPnSoqhBESG6TZVSIjhfXrtAFep/RTDj5 pN0gk5USh19Oqi/el4dU56WTa2sp+2gOk8gjaSpSTy0BqOVoInYWc83dF U3zRa6UPBBRO8ceNeiftwzEsvtCFhRdx2DBNJMl9s9zVcgVlIckNNT80e KVlDs6ROOGQTEjC1Oqfwn96pv662/y9gUpPNdhP300Jk0BrybiG6Uz+JL A==; X-CSE-ConnectionGUID: B0QEw+WUSWKeTmGor/zLBA== X-CSE-MsgGUID: t+r6nNHIQBSwbepmoVA2uw== X-IronPort-AV: E=McAfee;i="6800,10657,11812"; a="80878442" X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="80878442" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29:21 -0700 X-CSE-ConnectionGUID: ro8YA2TZQqaG8Nejz3bpCQ== X-CSE-MsgGUID: NLoaSMfbSc6TcezbdrvnXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,197,1774335600"; d="scan'208";a="270103496" Received: from mkosciow-mobl1.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.245.210]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2026 00:29: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 V3 7/7] i3c: master: Reconcile dynamic addresses after DAA Date: Wed, 10 Jun 2026 10:28:52 +0300 Message-ID: <20260610072852.36934-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260610072852.36934-1-adrian.hunter@intel.com> References: <20260610072852.36934-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 --- Changes in V3: Add comment about the source of I3C_DEV_PROBE_* macro values. Also account for static_addr in i3c_master_reconcile_dyn_addrs() Changes in V2: Add bitmap.h include for bitmap_zero() etc. Re-base due to changes in previous patches. drivers/i3c/master.c | 119 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 5021d25b718a..367e0d6d4a64 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -6,7 +6,9 @@ */ =20 #include +#include #include +#include #include #include #include @@ -1613,6 +1615,57 @@ 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; +} + +/* Values are chosen to give the device plenty of opportunities to respond= */ +#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 +2309,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); @@ -2284,6 +2340,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; @@ -2401,6 +2469,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. @@ -2410,8 +2480,48 @@ void i3c_master_add_i3c_dev_locked(struct i3c_master= _controller *master, u8 addr =20 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 and static addresses in the bitmap */ + bitmap_zero(dev_dyn_addrs, I2C_MAX_ADDR + 1); + i3c_bus_for_each_i3cdev(&master->bus, desc) { + if (desc->info.static_addr) + __set_bit(desc->info.static_addr, dev_dyn_addrs); + __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 @@ -2445,6 +2555,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