[PATCH V2 07/20] i3c: mipi-i3c-hci: Manage DMA deallocation via devres action
Frank Li
Frank.li at nxp.com
Thu Jan 8 06:56:14 PST 2026
On Thu, Jan 08, 2026 at 10:05:45AM +0200, Adrian Hunter wrote:
> The driver already uses devres for resource management, but the standard
> resource-managed DMA allocation helpers cannot be used because they assume
> the DMA device matches the managed device.
>
> To address this, factor out the deallocation logic from hci_dma_cleanup()
> into a new helper, hci_dma_free(), and register it as a devres action.
>
> Signed-off-by: Adrian Hunter <adrian.hunter at intel.com>
> ---
Reviewed-by: Frank Li <Frank.Li at nxp.com>
>
>
> Changes in V2:
>
> Move hci_dma_free() below hci_dma_cleanup() to make patch look
> better to review
>
> Frank suggested using devm_add_action_and_reset() but it doesn't
> work because the error path needs to call hci_dma_cleanup() before
> hci_dma_free
>
>
> drivers/i3c/master/mipi-i3c-hci/dma.c | 23 +++++++++++++++++++++--
> 1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c
> index 54849aa98fad..4999cf3d9674 100644
> --- a/drivers/i3c/master/mipi-i3c-hci/dma.c
> +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c
> @@ -169,6 +169,22 @@ static void hci_dma_cleanup(struct i3c_hci *hci)
>
> rh_reg_write(CR_SETUP, 0);
> rh_reg_write(IBI_SETUP, 0);
> + }
> +
> + rhs_reg_write(CONTROL, 0);
> +}
> +
> +static void hci_dma_free(void *data)
> +{
> + struct i3c_hci *hci = data;
> + struct hci_rings_data *rings = hci->io_data;
> + struct hci_rh_data *rh;
> +
> + if (!rings)
> + return;
> +
> + for (int i = 0; i < rings->total; i++) {
> + rh = &rings->headers[i];
>
> if (rh->xfer)
> dma_free_coherent(rings->sysdev,
> @@ -190,8 +206,6 @@ static void hci_dma_cleanup(struct i3c_hci *hci)
> kfree(rh->ibi_data);
> }
>
> - rhs_reg_write(CONTROL, 0);
> -
> kfree(rings);
> hci->io_data = NULL;
> }
> @@ -359,10 +373,15 @@ static int hci_dma_init(struct i3c_hci *hci)
> RING_CTRL_RUN_STOP);
> }
>
> + ret = devm_add_action(hci->master.dev.parent, hci_dma_free, hci);
> + if (ret)
> + goto err_out;
> +
> return 0;
>
> err_out:
> hci_dma_cleanup(hci);
> + hci_dma_free(hci);
> return ret;
> }
>
> --
> 2.51.0
>
>
> --
> linux-i3c mailing list
> linux-i3c at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-i3c
More information about the linux-i3c
mailing list