This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 5a90d299eca drivers/i3c/master.c: fix dynamic address slot leak on 
reattach
5a90d299eca is described below

commit 5a90d299ecafea149d05ecf506ed2c5162545e88
Author: boyangcao <[email protected]>
AuthorDate: Sat Oct 10 11:04:31 2026 +0800

    drivers/i3c/master.c: fix dynamic address slot leak on reattach
    
    Free the old dynamic address slot when reattaching a device.
    
    Signed-off-by: boyangcao <[email protected]>
---
 drivers/i3c/master.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index f4038cf7481..9859de035ed 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -233,6 +233,7 @@ static void i3c_bus_init_addrslots(FAR struct i3c_bus *bus)
 static void i3c_bus_init(FAR struct i3c_bus *i3cbus)
 {
   FAR struct i3c_master_controller *master;
+
   master = i3c_bus_to_i3c_master(i3cbus);
 
   nxmutex_init(&i3cbus->lock);
@@ -299,9 +300,9 @@ static int i3c_bus_set_mode(FAR struct i3c_bus *i3cbus,
 
   if (i3cbus->scl_rate.i3c > I3C_BUS_MAX_I3C_SCL_RATE ||
       i3cbus->scl_rate.i2c > I3C_BUS_I2C_FM_PLUS_SCL_RATE)
-      {
-        return -EINVAL;
-      }
+    {
+      return -EINVAL;
+    }
 
   return 0;
 }
@@ -660,6 +661,7 @@ static int i3c_master_getpid_locked(FAR struct 
i3c_master_controller *master,
   for (i = 0; i < sizeof(getpid->pid); i++)
     {
       int sft = (sizeof(getpid->pid) - i - 1) * 8;
+
       info->pid |= (uint64_t)getpid->pid[i] << sft;
     }
 
@@ -891,6 +893,11 @@ static int i3c_master_reattach_i3c_dev(FAR struct 
i3c_dev_desc *dev,
       i3c_bus_set_addr_slot_status(&master->bus,
                dev->info.dyn_addr,
                I3C_ADDR_SLOT_I3C_DEV);
+      if (old_dyn_addr)
+        {
+          i3c_bus_set_addr_slot_status(&master->bus, old_dyn_addr,
+                      I3C_ADDR_SLOT_FREE);
+        }
     }
 
   if (master->ops->reattach_i3c_dev)
@@ -1690,12 +1697,6 @@ int i3c_master_add_i3c_dev_locked(FAR struct 
i3c_master_controller *master,
       kmm_free(olddev);
     }
 
-  ret = i3c_master_reattach_i3c_dev(newdev, old_dyn_addr);
-  if (ret)
-    {
-      goto err_detach_dev;
-    }
-
   /* Depending on our previous state, the expected dynamic address might
    * differ:
    * - if the device already had a dynamic address assigned, let's try to

Reply via email to