Skip to contentSkip to conversation

crypto: cesa: allocate engines with main struct

PATCH In review Rosen Penev 2 participants 2 messages Apr 25 – May 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: cesa: allocate engines with main struct

Use a flexible array member to combine and simplify allocation.

Move struct mv_cesa_dev down as flexible array members require full definitions.

---
 drivers/crypto/marvell/cesa/cesa.c | 11 +++-----
 drivers/crypto/marvell/cesa/cesa.h | 42 +++++++++++++++---------------
 2 files changed, 25 insertions(+), 28 deletions(-)
drivers/crypto/marvell/cesa/cesa.c +4 -7
index 8afa3a87e38d..687ed730174d 100644
@@ -416,7 +416,7 @@ static int mv_cesa_probe(struct platform_device *pdev)
 	const struct mbus_dram_target_info *dram;
 	struct device *dev = &pdev->dev;
 	struct mv_cesa_dev *cesa;
-	struct mv_cesa_engine *engines;
+	struct mv_cesa_engine *engine;
 	int irq, ret, i, cpu;
 	u32 sram_size;
 
@@ -431,7 +431,8 @@ static int mv_cesa_probe(struct platform_device *pdev)
 			return -ENOTSUPP;
 	}
 
-	cesa = devm_kzalloc(dev, sizeof(*cesa), GFP_KERNEL);
+	cesa = devm_kzalloc(dev, struct_size(cesa, engines, caps->nengines),
+			GFP_KERNEL);
 	if (!cesa)
 		return -ENOMEM;
 
@@ -445,10 +446,6 @@ static int mv_cesa_probe(struct platform_device *pdev)
 		sram_size = CESA_SA_MIN_SRAM_SIZE;
 
 	cesa->sram_size = sram_size;
-	cesa->engines = devm_kcalloc(dev, caps->nengines, sizeof(*engines),
-				     GFP_KERNEL);
-	if (!cesa->engines)
-		return -ENOMEM;
 
 	spin_lock_init(&cesa->lock);
 
@@ -465,7 +462,7 @@ static int mv_cesa_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, cesa);
 
 	for (i = 0; i < caps->nengines; i++) {
-		struct mv_cesa_engine *engine = &cesa->engines[i];
+		engine = &cesa->engines[i];
 		char res_name[16];
 
 		engine->id = i;
drivers/crypto/marvell/cesa/cesa.h +21 -21

54 lines not on this page · raw message

Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 10 lines · Rosen Penev

Use a flexible array member to combine and simplify allocation.

Move struct mv_cesa_dev down as flexible array members require full definitions.

---
 drivers/crypto/marvell/cesa/cesa.c | 11 +++-----
 drivers/crypto/marvell/cesa/cesa.h | 42 +++++++++++++++---------------
 2 files changed, 25 insertions(+), 28 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt