Skip to contentSkip to conversation

crypto: amcc - embed pdr_uinfo as flexible array in crypto4xx_device

PATCH In review Rosen Penev 1 participant 2 messages Jun 13 – Jun 14 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: amcc - embed pdr_uinfo as flexible array in crypto4xx_device

No need to allocate and free separately.

This keeps crypto4xx_destroy_pdr dedicated to dma freeing only.

Assisted-by opencode:big-pickle
---
 drivers/crypto/amcc/crypto4xx_core.c | 12 +-----------
 drivers/crypto/amcc/crypto4xx_core.h |  3 ++-
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/crypto/amcc/crypto4xx_core.c +1 -11
index 001da785af07..ea1e40b3184b 100644
@@ -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;
 
drivers/crypto/amcc/crypto4xx_core.h +2 -1
index 66a95733c86d..bd4a286514a4 100644
@@ -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 {
Signature · 1 line
2.54.0
#1 lore raw
Quoted 2 lines · Rosen Penev

No need to allocate and free separately.

On further review, it makes more sense to change to a static array.

Quoted 68 lines

This keeps crypto4xx_destroy_pdr dedicated to dma freeing only.

Assisted-by opencode:big-pickle
---
 drivers/crypto/amcc/crypto4xx_core.c | 12 +-----------
 drivers/crypto/amcc/crypto4xx_core.h |  3 ++-
 2 files changed, 3 insertions(+), 12 deletions(-)
drivers/crypto/amcc/crypto4xx_core.c +1 -11
index 001da785af07..ea1e40b3184b 100644
@@ -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;
 
drivers/crypto/amcc/crypto4xx_core.h +2 -2
index 66a95733c86d..bd4a286514a4 100644
@@ -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