Re: [PATCH] crypto: amcc - embed pdr_uinfo as flexible array in crypto4xx_device
From: Rosen Penev
Date: Sat Jun 13 2026 - 21:28:08 EST
On Sat, Jun 13, 2026 at 4:46 PM Rosen Penev <rosenp@xxxxxxxxx> wrote:
>
> No need to allocate and free separately.
On further review, it makes more sense to change to a static array.
>
> This keeps crypto4xx_destroy_pdr dedicated to dma freeing only.
>
> Assisted-by: opencode:big-pickle
> Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
> ---
> drivers/crypto/amcc/crypto4xx_core.c | 12 +-----------
> drivers/crypto/amcc/crypto4xx_core.h | 3 ++-
> 2 files changed, 3 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
> index 001da785af07..ea1e40b3184b 100644
> --- a/drivers/crypto/amcc/crypto4xx_core.c
> +++ b/drivers/crypto/amcc/crypto4xx_core.c
> @@ -171,14 +171,6 @@ static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev)
> if (!dev->pdr)
> return -ENOMEM;
>
> - dev->pdr_uinfo = kzalloc_objs(struct pd_uinfo, PPC4XX_NUM_PD);
> - if (!dev->pdr_uinfo) {
> - dma_free_coherent(dev->core_dev->device,
> - sizeof(struct ce_pd) * PPC4XX_NUM_PD,
> - dev->pdr,
> - dev->pdr_pa);
> - return -ENOMEM;
> - }
> dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device,
> sizeof(union shadow_sa_buf) * PPC4XX_NUM_PD,
> &dev->shadow_sa_pool_pa,
> @@ -226,8 +218,6 @@ static void crypto4xx_destroy_pdr(struct crypto4xx_device *dev)
> dma_free_coherent(dev->core_dev->device,
> sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
> dev->shadow_sr_pool, dev->shadow_sr_pool_pa);
> -
> - kfree(dev->pdr_uinfo);
> }
>
> static u32 crypto4xx_get_pd_from_pdr_nolock(struct crypto4xx_device *dev)
> @@ -1247,7 +1237,7 @@ static int crypto4xx_probe(struct platform_device *ofdev)
> dev_set_drvdata(dev, core_dev);
> core_dev->ofdev = ofdev;
> core_dev->dev = devm_kzalloc(
> - &ofdev->dev, sizeof(struct crypto4xx_device), GFP_KERNEL);
> + &ofdev->dev, struct_size(core_dev->dev, pdr_uinfo, PPC4XX_NUM_PD), GFP_KERNEL);
> if (!core_dev->dev)
> return -ENOMEM;
>
> diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h
> index 66a95733c86d..bd4a286514a4 100644
> --- a/drivers/crypto/amcc/crypto4xx_core.h
> +++ b/drivers/crypto/amcc/crypto4xx_core.h
> @@ -93,11 +93,12 @@ struct crypto4xx_device {
> u32 gdr_head;
> u32 sdr_tail;
> u32 sdr_head;
> - struct pd_uinfo *pdr_uinfo;
> struct list_head alg_list; /* List of algorithm supported
> by this device */
> struct ratelimit_state aead_ratelimit;
> bool is_revb;
> +
> + struct pd_uinfo pdr_uinfo[];
> };
>
> struct crypto4xx_core_device {
> --
> 2.54.0
>