All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function
@ 2015-01-22 14:00 Cristian Stoica
  2015-01-22 14:00 ` [PATCH 2/2] crypto: caam: fix resource clean-up on error path for caam_jr_init Cristian Stoica
  2015-01-26  2:56 ` [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Cristian Stoica @ 2015-01-22 14:00 UTC (permalink / raw)
  To: herbert, davem, linux-crypto; +Cc: kim.phillips, horia.geanta, Cristian Stoica

irq_dispose_mapping is not called on all error paths from caam_jr_init.
This takes care of several clean-up issues by performing resource
clean-up and allocation at the same level.

Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
---
 drivers/crypto/caam/jr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index 9b3ef1bc..bce2959 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -384,8 +384,6 @@ static int caam_jr_init(struct device *dev)
 	if (error) {
 		dev_err(dev, "can't connect JobR %d interrupt (%d)\n",
 			jrp->ridx, jrp->irq);
-		irq_dispose_mapping(jrp->irq);
-		jrp->irq = 0;
 		return -EINVAL;
 	}
 
@@ -484,8 +482,10 @@ static int caam_jr_probe(struct platform_device *pdev)
 
 	/* Now do the platform independent part */
 	error = caam_jr_init(jrdev); /* now turn on hardware */
-	if (error)
+	if (error) {
+		irq_dispose_mapping(jrpriv->irq);
 		return error;
+	}
 
 	jrpriv->dev = jrdev;
 	spin_lock(&driver_data.jr_alloc_lock);
-- 
2.2.0

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

* [PATCH 2/2] crypto: caam: fix resource clean-up on error path for caam_jr_init
  2015-01-22 14:00 [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function Cristian Stoica
@ 2015-01-22 14:00 ` Cristian Stoica
  2015-01-26  2:56 ` [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Cristian Stoica @ 2015-01-22 14:00 UTC (permalink / raw)
  To: herbert, davem, linux-crypto; +Cc: kim.phillips, horia.geanta, Cristian Stoica

Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>
---
 drivers/crypto/caam/jr.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c
index bce2959..b8b5d47 100644
--- a/drivers/crypto/caam/jr.c
+++ b/drivers/crypto/caam/jr.c
@@ -384,28 +384,28 @@ static int caam_jr_init(struct device *dev)
 	if (error) {
 		dev_err(dev, "can't connect JobR %d interrupt (%d)\n",
 			jrp->ridx, jrp->irq);
-		return -EINVAL;
+		goto out_kill_deq;
 	}
 
 	error = caam_reset_hw_jr(dev);
 	if (error)
-		return error;
+		goto out_free_irq;
 
+	error = -ENOMEM;
 	jrp->inpring = dma_alloc_coherent(dev, sizeof(dma_addr_t) * JOBR_DEPTH,
 					  &inpbusaddr, GFP_KERNEL);
+	if (!jrp->inpring)
+		goto out_free_irq;
 
 	jrp->outring = dma_alloc_coherent(dev, sizeof(struct jr_outentry) *
 					  JOBR_DEPTH, &outbusaddr, GFP_KERNEL);
+	if (!jrp->outring)
+		goto out_free_inpring;
 
 	jrp->entinfo = kzalloc(sizeof(struct caam_jrentry_info) * JOBR_DEPTH,
 			       GFP_KERNEL);
-
-	if ((jrp->inpring == NULL) || (jrp->outring == NULL) ||
-	    (jrp->entinfo == NULL)) {
-		dev_err(dev, "can't allocate job rings for %d\n",
-			jrp->ridx);
-		return -ENOMEM;
-	}
+	if (!jrp->entinfo)
+		goto out_free_outring;
 
 	for (i = 0; i < JOBR_DEPTH; i++)
 		jrp->entinfo[i].desc_addr_dma = !0;
@@ -432,6 +432,19 @@ static int caam_jr_init(struct device *dev)
 		  (JOBR_INTC_TIME_THLD << JRCFG_ICTT_SHIFT));
 
 	return 0;
+
+out_free_outring:
+	dma_free_coherent(dev, sizeof(struct jr_outentry) * JOBR_DEPTH,
+			  jrp->outring, outbusaddr);
+out_free_inpring:
+	dma_free_coherent(dev, sizeof(dma_addr_t) * JOBR_DEPTH,
+			  jrp->inpring, inpbusaddr);
+	dev_err(dev, "can't allocate job rings for %d\n", jrp->ridx);
+out_free_irq:
+	free_irq(jrp->irq, dev);
+out_kill_deq:
+	tasklet_kill(&jrp->irqtask);
+	return error;
 }
 
 
-- 
2.2.0

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

* Re: [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function
  2015-01-22 14:00 [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function Cristian Stoica
  2015-01-22 14:00 ` [PATCH 2/2] crypto: caam: fix resource clean-up on error path for caam_jr_init Cristian Stoica
@ 2015-01-26  2:56 ` Herbert Xu
  1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2015-01-26  2:56 UTC (permalink / raw)
  To: Cristian Stoica; +Cc: davem, linux-crypto, kim.phillips, horia.geanta

On Thu, Jan 22, 2015 at 04:00:48PM +0200, Cristian Stoica wrote:
> irq_dispose_mapping is not called on all error paths from caam_jr_init.
> This takes care of several clean-up issues by performing resource
> clean-up and allocation at the same level.
> 
> Signed-off-by: Cristian Stoica <cristian.stoica@freescale.com>

Both patches applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2015-01-26  2:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-22 14:00 [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function Cristian Stoica
2015-01-22 14:00 ` [PATCH 2/2] crypto: caam: fix resource clean-up on error path for caam_jr_init Cristian Stoica
2015-01-26  2:56 ` [PATCH 1/2] crypto: caam: pair irq map and dispose in the same function Herbert Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.