linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: edma: Use common error handling code in three functions
@ 2017-10-22 14:54 SF Markus Elfring
  2017-10-23  8:22 ` Peter Ujfalusi
  2018-03-12 14:40 ` SF Markus Elfring
  0 siblings, 2 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-10-22 14:54 UTC (permalink / raw)
  To: dmaengine, Dan Williams, Peter Ujfalusi, Vinod Koul; +Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 22 Oct 2017 16:46:34 +0200

Add a jump target so that a bit of exception handling can be better reused
at the end of these functions.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/dma/edma.c | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
index a7ea20e7b8e9..c973ea97467f 100644
--- a/drivers/dma/edma.c
+++ b/drivers/dma/edma.c
@@ -1091,10 +1091,9 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
 			echan->slot[i] =
 				edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY);
 			if (echan->slot[i] < 0) {
-				kfree(edesc);
 				dev_err(dev, "%s: Failed to allocate slot\n",
 					__func__);
-				return NULL;
+				goto free_desc;
 			}
 		}
 	}
@@ -1110,10 +1109,8 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
 		ret = edma_config_pset(chan, &edesc->pset[i], src_addr,
 				       dst_addr, burst, dev_width,
 				       sg_dma_len(sg), direction);
-		if (ret < 0) {
-			kfree(edesc);
-			return NULL;
-		}
+		if (ret < 0)
+			goto free_desc;
 
 		edesc->absync = ret;
 		edesc->residue += sg_dma_len(sg);
@@ -1133,6 +1130,10 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
 	edesc->residue_stat = edesc->residue;
 
 	return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
+
+free_desc:
+	kfree(edesc);
+	return NULL;
 }
 
 static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
@@ -1203,10 +1204,8 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
 
 	ret = edma_config_pset(chan, &edesc->pset[0], src, dest, 1,
 			       width, pset_len, DMA_MEM_TO_MEM);
-	if (ret < 0) {
-		kfree(edesc);
-		return NULL;
-	}
+	if (ret < 0)
+		goto free_desc;
 
 	edesc->absync = ret;
 
@@ -1222,10 +1221,9 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
 			echan->slot[1] = edma_alloc_slot(echan->ecc,
 							 EDMA_SLOT_ANY);
 			if (echan->slot[1] < 0) {
-				kfree(edesc);
 				dev_err(dev, "%s: Failed to allocate slot\n",
 					__func__);
-				return NULL;
+				goto free_desc;
 			}
 		}
 		dest += pset_len;
@@ -1234,16 +1232,18 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
 
 		ret = edma_config_pset(chan, &edesc->pset[1], src, dest, 1,
 				       width, pset_len, DMA_MEM_TO_MEM);
-		if (ret < 0) {
-			kfree(edesc);
-			return NULL;
-		}
+		if (ret < 0)
+			goto free_desc;
 
 		edesc->pset[1].param.opt |= ITCCHEN;
 		edesc->pset[1].param.opt |= TCINTEN;
 	}
 
 	return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
+
+free_desc:
+	kfree(edesc);
+	return NULL;
 }
 
 static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
@@ -1334,10 +1334,9 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
 			echan->slot[i] =
 				edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY);
 			if (echan->slot[i] < 0) {
-				kfree(edesc);
 				dev_err(dev, "%s: Failed to allocate slot\n",
 					__func__);
-				return NULL;
+				goto free_desc;
 			}
 		}
 
@@ -1350,10 +1349,8 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
 		ret = edma_config_pset(chan, &edesc->pset[i], src_addr,
 				       dst_addr, burst, dev_width, period_len,
 				       direction);
-		if (ret < 0) {
-			kfree(edesc);
-			return NULL;
-		}
+		if (ret < 0)
+			goto free_desc;
 
 		if (direction == DMA_DEV_TO_MEM)
 			dst_addr += period_len;
@@ -1402,6 +1399,10 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
 		edma_assign_channel_eventq(echan, EVENTQ_0);
 
 	return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
+
+free_desc:
+	kfree(edesc);
+	return NULL;
 }
 
 static void edma_completion_handler(struct edma_chan *echan)
-- 
2.14.2

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

* Re: [PATCH] dmaengine: edma: Use common error handling code in three functions
  2017-10-22 14:54 [PATCH] dmaengine: edma: Use common error handling code in three functions SF Markus Elfring
@ 2017-10-23  8:22 ` Peter Ujfalusi
  2018-03-12 14:40 ` SF Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Ujfalusi @ 2017-10-23  8:22 UTC (permalink / raw)
  To: SF Markus Elfring, dmaengine, Dan Williams, Vinod Koul
  Cc: LKML, kernel-janitors



On 2017-10-22 17:54, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 22 Oct 2017 16:46:34 +0200
> 
> Add a jump target so that a bit of exception handling can be better reused
> at the end of these functions.
> 
> This issue was detected by using the Coccinelle software.

Acked-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  drivers/dma/edma.c | 45 +++++++++++++++++++++++----------------------
>  1 file changed, 23 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
> index a7ea20e7b8e9..c973ea97467f 100644
> --- a/drivers/dma/edma.c
> +++ b/drivers/dma/edma.c
> @@ -1091,10 +1091,9 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
>  			echan->slot[i] =
>  				edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY);
>  			if (echan->slot[i] < 0) {
> -				kfree(edesc);
>  				dev_err(dev, "%s: Failed to allocate slot\n",
>  					__func__);
> -				return NULL;
> +				goto free_desc;
>  			}
>  		}
>  	}
> @@ -1110,10 +1109,8 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
>  		ret = edma_config_pset(chan, &edesc->pset[i], src_addr,
>  				       dst_addr, burst, dev_width,
>  				       sg_dma_len(sg), direction);
> -		if (ret < 0) {
> -			kfree(edesc);
> -			return NULL;
> -		}
> +		if (ret < 0)
> +			goto free_desc;
>  
>  		edesc->absync = ret;
>  		edesc->residue += sg_dma_len(sg);
> @@ -1133,6 +1130,10 @@ static struct dma_async_tx_descriptor *edma_prep_slave_sg(
>  	edesc->residue_stat = edesc->residue;
>  
>  	return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
> +
> +free_desc:
> +	kfree(edesc);
> +	return NULL;
>  }
>  
>  static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
> @@ -1203,10 +1204,8 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
>  
>  	ret = edma_config_pset(chan, &edesc->pset[0], src, dest, 1,
>  			       width, pset_len, DMA_MEM_TO_MEM);
> -	if (ret < 0) {
> -		kfree(edesc);
> -		return NULL;
> -	}
> +	if (ret < 0)
> +		goto free_desc;
>  
>  	edesc->absync = ret;
>  
> @@ -1222,10 +1221,9 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
>  			echan->slot[1] = edma_alloc_slot(echan->ecc,
>  							 EDMA_SLOT_ANY);
>  			if (echan->slot[1] < 0) {
> -				kfree(edesc);
>  				dev_err(dev, "%s: Failed to allocate slot\n",
>  					__func__);
> -				return NULL;
> +				goto free_desc;
>  			}
>  		}
>  		dest += pset_len;
> @@ -1234,16 +1232,18 @@ static struct dma_async_tx_descriptor *edma_prep_dma_memcpy(
>  
>  		ret = edma_config_pset(chan, &edesc->pset[1], src, dest, 1,
>  				       width, pset_len, DMA_MEM_TO_MEM);
> -		if (ret < 0) {
> -			kfree(edesc);
> -			return NULL;
> -		}
> +		if (ret < 0)
> +			goto free_desc;
>  
>  		edesc->pset[1].param.opt |= ITCCHEN;
>  		edesc->pset[1].param.opt |= TCINTEN;
>  	}
>  
>  	return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
> +
> +free_desc:
> +	kfree(edesc);
> +	return NULL;
>  }
>  
>  static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
> @@ -1334,10 +1334,9 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
>  			echan->slot[i] =
>  				edma_alloc_slot(echan->ecc, EDMA_SLOT_ANY);
>  			if (echan->slot[i] < 0) {
> -				kfree(edesc);
>  				dev_err(dev, "%s: Failed to allocate slot\n",
>  					__func__);
> -				return NULL;
> +				goto free_desc;
>  			}
>  		}
>  
> @@ -1350,10 +1349,8 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
>  		ret = edma_config_pset(chan, &edesc->pset[i], src_addr,
>  				       dst_addr, burst, dev_width, period_len,
>  				       direction);
> -		if (ret < 0) {
> -			kfree(edesc);
> -			return NULL;
> -		}
> +		if (ret < 0)
> +			goto free_desc;
>  
>  		if (direction == DMA_DEV_TO_MEM)
>  			dst_addr += period_len;
> @@ -1402,6 +1399,10 @@ static struct dma_async_tx_descriptor *edma_prep_dma_cyclic(
>  		edma_assign_channel_eventq(echan, EVENTQ_0);
>  
>  	return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
> +
> +free_desc:
> +	kfree(edesc);
> +	return NULL;
>  }
>  
>  static void edma_completion_handler(struct edma_chan *echan)
> 

- Péter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

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

* Re: dmaengine: edma: Use common error handling code in three functions
  2017-10-22 14:54 [PATCH] dmaengine: edma: Use common error handling code in three functions SF Markus Elfring
  2017-10-23  8:22 ` Peter Ujfalusi
@ 2018-03-12 14:40 ` SF Markus Elfring
  1 sibling, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2018-03-12 14:40 UTC (permalink / raw)
  To: dmaengine, Dan Williams, Peter Ujfalusi, Vinod Koul; +Cc: LKML, kernel-janitors

> Date: Sun, 22 Oct 2017 16:46:34 +0200
> 
> Add a jump target so that a bit of exception handling can be better reused
> at the end of these functions.

How are the chances to integrate such a change into another Linux repository?
https://lkml.org/lkml/2017/10/22/78
https://patchwork.kernel.org/patch/10021725/
https://lkml.kernel.org/r/<cb8f32ef-14c1-35cb-39aa-d3efa265dccf@users.sourceforge.net>

Regards,
Markus

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

end of thread, other threads:[~2018-03-12 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-22 14:54 [PATCH] dmaengine: edma: Use common error handling code in three functions SF Markus Elfring
2017-10-23  8:22 ` Peter Ujfalusi
2018-03-12 14:40 ` SF Markus Elfring

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).