linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] crypto: caam: ctrl: Fix the error handling
@ 2015-08-21 14:49 Fabio Estevam
  2015-08-21 14:49 ` [PATCH 2/4] crypto: caam: ctrl: Propagate the real error code Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Fabio Estevam @ 2015-08-21 14:49 UTC (permalink / raw)
  To: herbert; +Cc: vicki.milhoan, horia.geanta, linux-crypto, Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

In the error path we should disable the resources that were previously
acquired, so fix the error handling accordingly.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/crypto/caam/ctrl.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 81b552d..9c5ca46 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -474,27 +474,27 @@ static int caam_probe(struct platform_device *pdev)
 	ret = clk_prepare_enable(ctrlpriv->caam_ipg);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "can't enable CAAM ipg clock: %d\n", ret);
-		return -ENODEV;
+		return ret;
 	}
 
 	ret = clk_prepare_enable(ctrlpriv->caam_mem);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "can't enable CAAM secure mem clock: %d\n",
 			ret);
-		return -ENODEV;
+		goto disable_caam_ipg;
 	}
 
 	ret = clk_prepare_enable(ctrlpriv->caam_aclk);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "can't enable CAAM aclk clock: %d\n", ret);
-		return -ENODEV;
+		goto disable_caam_mem;
 	}
 
 	ret = clk_prepare_enable(ctrlpriv->caam_emi_slow);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "can't enable CAAM emi slow clock: %d\n",
 			ret);
-		return -ENODEV;
+		goto disable_caam_aclk;
 	}
 
 	/* Get configuration properties from device tree */
@@ -502,7 +502,7 @@ static int caam_probe(struct platform_device *pdev)
 	ctrl = of_iomap(nprop, 0);
 	if (ctrl == NULL) {
 		dev_err(dev, "caam: of_iomap() failed\n");
-		return -ENOMEM;
+		goto disable_caam_emi_slow;
 	}
 	/* Finding the page size for using the CTPR_MS register */
 	comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
@@ -586,8 +586,8 @@ static int caam_probe(struct platform_device *pdev)
 					sizeof(struct platform_device *) * rspec,
 					GFP_KERNEL);
 	if (ctrlpriv->jrpdev == NULL) {
-		iounmap(ctrl);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto iounmap_ctrl;
 	}
 
 	ring = 0;
@@ -627,8 +627,8 @@ static int caam_probe(struct platform_device *pdev)
 	/* If no QI and no rings specified, quit and go home */
 	if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
 		dev_err(dev, "no queues configured, terminating\n");
-		caam_remove(pdev);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto caam_remove;
 	}
 
 	cha_vid_ls = rd_reg32(&ctrl->perfmon.cha_id_ls);
@@ -685,8 +685,7 @@ static int caam_probe(struct platform_device *pdev)
 		} while ((ret == -EAGAIN) && (ent_delay < RTSDCTL_ENT_DLY_MAX));
 		if (ret) {
 			dev_err(dev, "failed to instantiate RNG");
-			caam_remove(pdev);
-			return ret;
+			goto caam_remove;
 		}
 		/*
 		 * Set handles init'ed by this module as the complement of the
@@ -790,6 +789,20 @@ static int caam_probe(struct platform_device *pdev)
 						 &ctrlpriv->ctl_tdsk_wrap);
 #endif
 	return 0;
+
+caam_remove:
+	caam_remove(pdev);
+iounmap_ctrl:
+	iounmap(ctrl);
+disable_caam_emi_slow:
+	clk_disable_unprepare(ctrlpriv->caam_emi_slow);
+disable_caam_aclk:
+	clk_disable_unprepare(ctrlpriv->caam_aclk);
+disable_caam_mem:
+	clk_disable_unprepare(ctrlpriv->caam_mem);
+disable_caam_ipg:
+	clk_disable_unprepare(ctrlpriv->caam_ipg);
+	return ret;
 }
 
 static struct of_device_id caam_match[] = {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] crypto: caam: ctrl: Propagate the real error code
  2015-08-21 14:49 [PATCH 1/4] crypto: caam: ctrl: Fix the error handling Fabio Estevam
@ 2015-08-21 14:49 ` Fabio Estevam
  2015-08-21 14:49 ` [PATCH 3/4] crypto: caam: ctrl: Use the preferred method for devm_kzalloc() Fabio Estevam
  2015-08-21 14:49 ` [PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc() Fabio Estevam
  2 siblings, 0 replies; 5+ messages in thread
From: Fabio Estevam @ 2015-08-21 14:49 UTC (permalink / raw)
  To: herbert; +Cc: vicki.milhoan, horia.geanta, linux-crypto, Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

Instead of propagating a 'fake' error code, just propagate the real
one in the case of caam_drv_identify_clk() failure.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/crypto/caam/ctrl.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 9c5ca46..1153417 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -440,7 +440,7 @@ static int caam_probe(struct platform_device *pdev)
 		ret = PTR_ERR(clk);
 		dev_err(&pdev->dev,
 			"can't identify CAAM ipg clk: %d\n", ret);
-		return -ENODEV;
+		return ret;
 	}
 	ctrlpriv->caam_ipg = clk;
 
@@ -449,7 +449,7 @@ static int caam_probe(struct platform_device *pdev)
 		ret = PTR_ERR(clk);
 		dev_err(&pdev->dev,
 			"can't identify CAAM mem clk: %d\n", ret);
-		return -ENODEV;
+		return ret;
 	}
 	ctrlpriv->caam_mem = clk;
 
@@ -458,7 +458,7 @@ static int caam_probe(struct platform_device *pdev)
 		ret = PTR_ERR(clk);
 		dev_err(&pdev->dev,
 			"can't identify CAAM aclk clk: %d\n", ret);
-		return -ENODEV;
+		return ret;
 	}
 	ctrlpriv->caam_aclk = clk;
 
@@ -467,7 +467,7 @@ static int caam_probe(struct platform_device *pdev)
 		ret = PTR_ERR(clk);
 		dev_err(&pdev->dev,
 			"can't identify CAAM emi_slow clk: %d\n", ret);
-		return -ENODEV;
+		return ret;
 	}
 	ctrlpriv->caam_emi_slow = clk;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] crypto: caam: ctrl: Use the preferred method for devm_kzalloc()
  2015-08-21 14:49 [PATCH 1/4] crypto: caam: ctrl: Fix the error handling Fabio Estevam
  2015-08-21 14:49 ` [PATCH 2/4] crypto: caam: ctrl: Propagate the real error code Fabio Estevam
@ 2015-08-21 14:49 ` Fabio Estevam
  2015-08-21 14:49 ` [PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc() Fabio Estevam
  2 siblings, 0 replies; 5+ messages in thread
From: Fabio Estevam @ 2015-08-21 14:49 UTC (permalink / raw)
  To: herbert; +Cc: vicki.milhoan, horia.geanta, linux-crypto, Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

>From Documentation/CodingStyle:

"The preferred form for passing a size of a struct is the following:

	p = kmalloc(sizeof(*p), ...);"

, so do as suggested.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/crypto/caam/ctrl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 1153417..aab8b2a 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -424,8 +424,7 @@ static int caam_probe(struct platform_device *pdev)
 	int pg_size;
 	int BLOCK_OFFSET = 0;
 
-	ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(struct caam_drv_private),
-				GFP_KERNEL);
+	ctrlpriv = devm_kzalloc(&pdev->dev, sizeof(*ctrlpriv), GFP_KERNEL);
 	if (!ctrlpriv)
 		return -ENOMEM;
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc()
  2015-08-21 14:49 [PATCH 1/4] crypto: caam: ctrl: Fix the error handling Fabio Estevam
  2015-08-21 14:49 ` [PATCH 2/4] crypto: caam: ctrl: Propagate the real error code Fabio Estevam
  2015-08-21 14:49 ` [PATCH 3/4] crypto: caam: ctrl: Use the preferred method for devm_kzalloc() Fabio Estevam
@ 2015-08-21 14:49 ` Fabio Estevam
  2015-08-21 15:42   ` Horia Geantă
  2 siblings, 1 reply; 5+ messages in thread
From: Fabio Estevam @ 2015-08-21 14:49 UTC (permalink / raw)
  To: herbert; +Cc: vicki.milhoan, horia.geanta, linux-crypto, Fabio Estevam

From: Fabio Estevam <fabio.estevam@freescale.com>

>From Documentation/CodingStyle:

"The preferred form for allocating a zeroed array is the following:

	p = kcalloc(n, sizeof(...), ...); "

, so do as suggested.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
 drivers/crypto/caam/ctrl.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index aab8b2a..c9c5892 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -581,9 +581,8 @@ static int caam_probe(struct platform_device *pdev)
 		    of_device_is_compatible(np, "fsl,sec4.0-job-ring"))
 			rspec++;
 
-	ctrlpriv->jrpdev = devm_kzalloc(&pdev->dev,
-					sizeof(struct platform_device *) * rspec,
-					GFP_KERNEL);
+	ctrlpriv->jrpdev = devm_kcalloc(&pdev->dev, rspec,
+					sizeof(*ctrlpriv->jrpdev), GFP_KERNEL);
 	if (ctrlpriv->jrpdev == NULL) {
 		ret = -ENOMEM;
 		goto iounmap_ctrl;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc()
  2015-08-21 14:49 ` [PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc() Fabio Estevam
@ 2015-08-21 15:42   ` Horia Geantă
  0 siblings, 0 replies; 5+ messages in thread
From: Horia Geantă @ 2015-08-21 15:42 UTC (permalink / raw)
  To: Fabio Estevam, herbert; +Cc: vicki.milhoan, linux-crypto, Fabio Estevam

On 8/21/2015 5:49 PM, Fabio Estevam wrote:
> From: Fabio Estevam <fabio.estevam@freescale.com>
> 
>>From Documentation/CodingStyle:
> 
> "The preferred form for allocating a zeroed array is the following:
> 
> 	p = kcalloc(n, sizeof(...), ...); "
> 
> , so do as suggested.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

While here, you could also address the following:
drivers/crypto/caam/caamalg.c:4317
drivers/crypto/caam/caamhash.c:1844
drivers/crypto/caam/caamrng.c:354
drivers/crypto/caam/jr.c:413
drivers/crypto/caam/jr.c:418
drivers/crypto/caam/jr.c:423
drivers/crypto/caam/jr.c:482
(and any other place that I might've missed).

Since related, I guess the changes (3/4, 4/4 and above) could live in a
single patch.

Thanks,
Horia

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-21 15:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-21 14:49 [PATCH 1/4] crypto: caam: ctrl: Fix the error handling Fabio Estevam
2015-08-21 14:49 ` [PATCH 2/4] crypto: caam: ctrl: Propagate the real error code Fabio Estevam
2015-08-21 14:49 ` [PATCH 3/4] crypto: caam: ctrl: Use the preferred method for devm_kzalloc() Fabio Estevam
2015-08-21 14:49 ` [PATCH 4/4] crypto: caam: ctrl: Use devm_kcalloc() Fabio Estevam
2015-08-21 15:42   ` Horia Geantă

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).