[PATCH v23 1/5] i3c: hub: Fix downstream address reservations on parent bus

sashiko-bot at kernel.org sashiko-bot at kernel.org
Sun Nov 29 01:27:58 PST 2026


Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] i3c: hub: downstream ENTDAA devices miss boardinfo and SETNEWDA
  on parent
- [Medium] i3c: hub: missing address reservation propagation across
  stacked hubs
- [Medium] i3c: hub: missing DT desired-address and error reservation
  for SETAASA
- [Medium] i3c: hub: premature parent_desc.info update in
  i3c_hub_reattach_i3c_dev()
--

commit 811648d9836d42759991dbf59e7ab462b264a3bb
Author: Lakshay Piplani <lakshay.piplani at nxp.com>

i3c: hub: Fix downstream address reservations on parent bus

This commit tracks parent bus address reservations per downstream I3C
device using I3C_ADDR_SLOT_RSVD and marks DT-assigned downstream addresses
as desired on the parent bus with a new i3c_bus_set_addr_slot_desired()
helper.

> diff --git a/drivers/i3c/hub.c b/drivers/i3c/hub.c
> index 5390287680844..c05881895be05 100644
> --- a/drivers/i3c/hub.c
> +++ b/drivers/i3c/hub.c
[ ... ]
> @@ -164,26 +234,70 @@ static int i3c_hub_attach_i3c_dev(struct i3c_dev_desc *dev)
>  	data->parent_desc.common.master = parent;
>  	data->parent_desc.info = dev->info;
>  
> +	/*
> +	 * An existing dynamic address stays in use; otherwise the core is about
> +	 * to apply init_dyn_addr, which for SETAASA is the static address.
> +	 */
> +	addr = dev->info.dyn_addr;
> +	if (!addr && dev->boardinfo)
> +		addr = dev->boardinfo->init_dyn_addr;

[Severity: Medium]
In a stacked hub topology, does this skip reserving init_dyn_addr on
ancestor buses before SETDASA or SETAASA is sent?

When i3c_master_early_i3c_dev_add() attaches a static-address device on a
child hub, dev->info.dyn_addr is still 0 and the target address comes from
dev->boardinfo->init_dyn_addr.  Because data->parent_desc.boardinfo is
left NULL, the parent hub's i3c_hub_attach_i3c_dev(&data->parent_desc)
computes addr == 0 and does not claim the address on the physical root bus
before the command goes on the wire.  Similarly,
i3c_hub_reserve_parent_addrslots_from_dt() only marks desired addresses on
the immediate hubc->parent->bus rather than propagating them up to the
root parent bus where DAA runs.

> +
>  	i3c_bus_maintenance_lock(&parent->bus);
> +	if (addr) {
> +		ret = i3c_hub_claim_parent_addr(parent, addr);
> +		if (ret) {
> +			i3c_bus_maintenance_unlock(&parent->bus);
> +			dev_err(&controller->dev,
> +				"address 0x%02x is already in use on the parent bus\n",
> +				addr);
> +			goto err_free_data;
> +		}
> +	}
> +
>  	ret = i3c_master_attach_i3c_dev_controller_locked(&data->parent_desc);
> -	i3c_bus_maintenance_unlock(&parent->bus);
>  	if (ret) {
> -		mutex_destroy(&data->parent_desc.ibi_lock);
> -		kfree(data);
> -		return ret;
> +		/* Nothing was sent yet, so the address is still unused. */
> +		if (addr)
> +			i3c_hub_release_parent_addr(parent, addr);
> +		i3c_bus_maintenance_unlock(&parent->bus);
> +		goto err_free_data;
>  	}

[Severity: Medium]
If attaching or reattaching a SETAASA device fails during
i3c_master_early_i3c_dev_add(), is it safe to release addr on parent->bus?

i3c_master_bus_init() still broadcasts SETAASA on the virtual controller's
port, so the target hardware will adopt its static address as its dynamic
address on the shared physical bus.  i3c_master_early_i3c_dev_add() marks
boardinfo->static_addr as I3C_ADDR_SLOT_RSVD on the virtual controller's
master->bus for that reason, but releasing it here (or in
i3c_hub_detach_i3c_dev() when reattach fails) leaves the slot free on
parent->bus for parent DAA to hand to another device.

Also, in i3c_hub_reserve_parent_addrslots_from_dt(), SETAASA devices in DT
typically omit assigned-address because i3c_master_add_i3c_boardinfo()
sets init_dyn_addr from static_addr (reg[0]), so skipping child nodes
without assigned-address leaves SETAASA static addresses unmarked on
parent->bus before earlier ports run DAA.

[ ... ]
> @@ -209,6 +323,32 @@ static int i3c_hub_reattach_i3c_dev(struct i3c_dev_desc *dev,
>  	 */
>  	i3c_bus_maintenance_lock(&parent->bus);
>  	data->parent_desc.info = dev->info;
> +
> +	new_addr = dev->info.dyn_addr;
> +	if (new_addr != data->parent_addr) {
> +		if (new_addr)
> +			claim_ret = i3c_hub_claim_parent_addr(parent, new_addr);
> +
> +		if (claim_ret) {
> +			/*
> +			 * The device already answers at new_addr, which is in
> +			 * use on the parent bus. Keep the reservation of the
> +			 * old address and report the conflict.
> +			 */
> +			dev_err(&parent->dev,
> +				"downstream device %llx moved to in-use parent address 0x%02x (%d)\n",
> +				dev->info.pid, new_addr, claim_ret);
> +			i3c_bus_maintenance_unlock(&parent->bus);
> +
> +			return claim_ret;
> +		}
> +
> +		/* Release the old address after reserving the new one. */
> +		if (data->parent_addr)
> +			i3c_hub_release_parent_addr(parent, data->parent_addr);
> +		data->parent_addr = new_addr;
> +	}
> +
>  	ret = i3c_master_reattach_i3c_dev_controller_locked(&data->parent_desc,
>  							    old_dyn_addr);
>  	i3c_bus_maintenance_unlock(&parent->bus);

[Severity: Medium]
Does updating data->parent_desc.info before i3c_hub_claim_parent_addr()
corrupt the parent controller's device state when claiming new_addr fails?

When i3c_hub_claim_parent_addr() returns -EBUSY, the parent controller is
never reattached to new_addr, yet data->parent_desc.info.dyn_addr has
already been overwritten with new_addr.  When the caller unwinds via
i3c_hub_detach_i3c_dev(), i3c_master_detach_i3c_dev_controller_locked()
passes data->parent_desc with new_addr to parent->ops->detach_i3c_dev(),
which in drivers keyed by dev->info.dyn_addr (such as
adi_i3c_master_detach_i3c_dev()) detaches the existing parent-bus device
at new_addr in hardware instead of the failed device's old address.
Likewise, if i3c_master_reattach_i3c_dev_controller_locked() fails,
data->parent_desc.info and data->parent_addr are not rolled back.

[ ... ]
> @@ -780,6 +937,13 @@ EXPORT_SYMBOL_GPL(i3c_hub_init);
>   * would also require tracking ownership of these reservations and releasing
>   * them when a hub is removed.
>   *
> + * Downstream devices with static addresses are configured by their
> + * virtual controllers using the corresponding Device Tree entries.
> + * ENTDAA discovery and boardinfo matching are handled by the parent
> + * controller to simplify address management. For ENTDAA-only devices,
> + * marking an address as desired keeps it unavailable during the first
> + * pass of the parent address allocator.
> + *
>   * Return: 0 on success, or a negative error code.
>   */
>  int i3c_hub_reserve_parent_addrslots_from_dt(struct i3c_hub_controller *hubc,
> @@ -816,9 +980,8 @@ int i3c_hub_reserve_parent_addrslots_from_dt(struct i3c_hub_controller *hubc,
>  		status = i3c_bus_get_addr_slot_status(&parent->bus,
>  						      assigned_addr);
>  		if (status == I3C_ADDR_SLOT_FREE)
> -			i3c_bus_set_addr_slot_status(&parent->bus,
> -						     assigned_addr,
> -						     I3C_ADDR_SLOT_I3C_DEV);
> +			i3c_bus_set_addr_slot_desired(&parent->bus,
> +						      assigned_addr);
>  		i3c_bus_maintenance_unlock(&parent->bus);
>  	}
>  	return 0;

[Severity: High]
How does the parent controller match boardinfo or assign assigned_addr for
downstream ENTDAA devices?

fwnode_populate_i3c_bus() populates the target-port DT child nodes onto
the virtual hub controller's boardinfo.i3c list, not parent->boardinfo.i3c.
When i3c_hub_do_daa() calls i3c_master_do_daa(parent), the parent address
allocator skips assigned_addr during pass 1 because it is marked
I3C_ADDR_SLOT_EXT_DESIRED and hands the device a temporary address, after
which __i3c_master_add_i3c_dev_locked(parent, ...) looks up boardinfo via
i3c_master_attach_boardinfo():

drivers/i3c/master.c:i3c_master_attach_boardinfo() {
	struct i3c_master_controller *master = i3cdev->common.master;
	struct i3c_dev_boardinfo *i3cboardinfo;

	list_for_each_entry(i3cboardinfo, &master->boardinfo.i3c, node) {
    ...
}

Because master is parent, i3c_master_attach_boardinfo() never sees the
virtual controller's boardinfo list.  newdev->boardinfo remains NULL, so
__i3c_master_add_i3c_dev_locked() never issues SETNEWDA to switch the
device to assigned_addr and registers the device on the parent bus without
its DT node.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129090506.101213-1-lakshay.piplani@nxp.com?part=1



More information about the linux-i3c mailing list