Hi Pranav — thanks.

On 9/7/2026 5:12 pm, Pranav Tilak wrote:
> [CAUTION: This email is from outside your organization. Unless you trust the 
> sender, do not click on links or open attachments as it may be a fraudulent 
> email attempting to steal your information and/or compromise your computer.]
> 
> i3c_master_add_i3c_dev_locked() incorrectly set master->this to the
> newly discovered slave device, causing i3c_master_attach_i3c_dev()
> to skip the attach_i3c_dev() callback. As a result the slave device
> never got its master_priv (DAT slot index) allocated, free_pos was
> never updated, and the DAT entry was never written.
> 
> Fix by removing the incorrect master->this assignment. Store the
> slave descriptor directly in master->i3cdev[pos] inside
> dw_i3c_master_attach_i3c_dev() where the DAT slot index is already
> known. Also check the return value of i3c_master_add_i3c_dev_locked()
> and skip num_i3cdevs increment on failure, fixing dummy devices shown
> when no slaves are present on the bus.
> 
> Fixes: 1009c96f1590 ("drivers: i3c: Add driver for MIPI DWI3C")
> Signed-off-by: Pranav Tilak <[email protected]>
> ---
>  drivers/i3c/master.c               | 1 -
>  drivers/i3c/master/dw-i3c-master.c | 5 +++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 019167a2dc5..1cf1ffd99cc 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1443,7 +1443,6 @@ int i3c_master_add_i3c_dev_locked(struct 
> i3c_master_controller *master,
>         if (IS_ERR(newdev))
>                 return PTR_ERR(newdev);
> 
> -       master->this = newdev;
>         ret = i3c_master_attach_i3c_dev(master, newdev);
>         if (ret)
>                 goto err_free_dev;
> diff --git a/drivers/i3c/master/dw-i3c-master.c 
> b/drivers/i3c/master/dw-i3c-master.c
> index c6ce54a1d3b..25933adf010 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -671,8 +671,8 @@ static int dw_i3c_master_daa(struct i3c_master_controller 
> *m)
> 
>         for (pos = 0; pos < master->maxdevs; pos++) {
>                 if (newdevs & BIT(pos)) {
> -                       i3c_master_add_i3c_dev_locked(m, master->addrs[pos]);
> -                       master->i3cdev[pos] = m->this;
> +                       if (i3c_master_add_i3c_dev_locked(m, 
> master->addrs[pos]))
> +                               continue;
>                         master->num_i3cdevs++;
>                 }
>         }
> @@ -806,6 +806,7 @@ static int dw_i3c_master_attach_i3c_dev(struct 
> i3c_dev_desc *dev)
>         master->addrs[pos] = dev->info.dyn_addr ? : dev->info.static_addr;
>         master->free_pos &= ~BIT(pos);
>         i3c_dev_set_master_data(dev, data);
> +       master->i3cdev[pos] = dev;
> 
>         writel(DEV_ADDR_TABLE_DYNAMIC_ADDR(master->addrs[pos]),
>                master->regs +
> --
> 2.34.1
> 

The master->this misuse before attach is a real bug (skips attach_i3c_dev for 
every slave).
Removing that assignment and recording i3cdev[] inside 
dw_i3c_master_attach_i3c_dev() looks correct to me.

Reviewed-by: Dinesh Maniyam [email protected]

Reply via email to