Re: [PATCH v4 09/25] dmaengine: sdxi: Allocate administrative context

From: Frank Li

Date: Thu Nov 12 2026 - 22:34:53 EST


On Tue, Nov 03, 2026 at 08:49:50PM -0600, Nathan Lynch via B4 Relay wrote:
> From: Nathan Lynch <nathan.lynch@xxxxxxx>
>
> Allocate the administrative context’s control structures and register
> device-managed cleanup.
>
> Co-developed-by: Wei Huang <wei.huang2@xxxxxxx>
> Signed-off-by: Wei Huang <wei.huang2@xxxxxxx>
> Signed-off-by: Nathan Lynch <nathan.lynch@xxxxxxx>
> ---
...
> +
> +DEFINE_FREE(sdxi_cxt, struct sdxi_cxt *, if (_T) sdxi_free_cxt(_T))
> +
> +/* Allocate a context and its control structure hierarchy in memory. */
> +static struct sdxi_cxt *sdxi_alloc_cxt(struct sdxi_dev *sdxi)
> +{
> + struct device *dev = sdxi->dev;
> + struct sdxi_cxt *cxt __free(sdxi_cxt) = kzalloc(sizeof(*cxt), GFP_KERNEL);
> +
> + if (!cxt)
> + return NULL;
> +
> + cxt->sdxi = sdxi;
> +
> + cxt->sq = sdxi_sq_alloc(sdxi, DEFAULT_DESC_RING_ENTRIES);
> + if (!cxt->sq)
> + return NULL;
> +
> + cxt->akey_table = dma_alloc_coherent(dev, sizeof(*cxt->akey_table),
> + &cxt->akey_table_dma, GFP_KERNEL);
> + if (!cxt->akey_table)
> + return NULL;
> +
> + cxt->cxt_ctl = dma_pool_zalloc(sdxi->cxt_ctl_pool, GFP_KERNEL,
> + &cxt->cxt_ctl_dma);
> + if (!cxt->cxt_ctl)
> + return NULL;
> +
> + return_ptr(cxt);
> +}
> +
> +static void free_admin_cxt(void *ptr)
> +{
> + struct sdxi_dev *sdxi = ptr;
> +
> + sdxi_free_cxt(sdxi->admin_cxt);
> +}
> +
> +int sdxi_admin_cxt_init(struct sdxi_dev *sdxi)
> +{
> + struct sdxi_cxt *cxt __free(sdxi_cxt) = sdxi_alloc_cxt(sdxi);
> + if (!cxt)
> + return -ENOMEM;
> +
> + cxt->id = SDXI_ADMIN_CXT_ID;
> + cxt->sq->doorbell = sdxi->dbs + cxt->id * sdxi->db_stride;
> +
> + sdxi->admin_cxt = no_free_ptr(cxt);
> +
> + return devm_add_action_or_reset(sdxi->dev, free_admin_cxt, sdxi);

If sdxi_alloc_cxt() only called by probe, needn't mix cleanup and devm
function

Frank