Re: [PATCH 06/17] i3c: mipi-i3c-hci: Fix i3c_hci_enable_ibi() error path
From: Frank Li
Date: Mon Sep 14 2026 - 13:17:11 EST
On Mon, Sep 14, 2026 at 02:29:52PM +0300, Adrian Hunter wrote:
suggested subject:
i3c: mipi-i3c-hci: restore controller state if i3c_hci_enable_ibi() return error
Frank
> i3c_hci_enable_ibi() performs controller-side setup before sending the
> ENEC CCC to enable IBIs on the target. If the ENEC CCC fails, the
> function returns an error but leaves the controller configured as if IBI
> enabling had succeeded.
>
> Fix the error path by undoing the earlier setup when the ENEC CCC fails,
> ensuring the controller state remains consistent with the failed enable
> operation.
>
> Fixes: 9ad9a52cce282 ("i3c/master: introduce the mipi-i3c-hci driver")
> Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> ---
> drivers/i3c/master/mipi-i3c-hci/core.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c
> index 8b3a87d8a8bb..166d9f70f435 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/core.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/core.c
> @@ -703,11 +703,15 @@ static int i3c_hci_enable_ibi(struct i3c_dev_desc *dev)
> struct i3c_master_controller *m = i3c_dev_get_master(dev);
> struct i3c_hci *hci = to_i3c_hci(m);
> struct i3c_hci_dev_data *dev_data = i3c_dev_get_master_data(dev);
> + int ret;
>
> 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] = dev;
> - return i3c_master_enec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR);
> + ret = i3c_master_enec_locked(m, dev->info.dyn_addr, I3C_CCC_EVENT_SIR);
> + if (ret)
> + __i3c_hci_disable_ibi(hci, dev);
> + return ret;
> }
>
> static int i3c_hci_disable_ibi(struct i3c_dev_desc *dev)
> --
> 2.53.0
>