lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8f0f98be-fc6b-cdce-acf6-22852fda02a1@ti.com>
Date:   Mon, 23 Oct 2017 11:22:34 +0300
From:   Peter Ujfalusi <peter.ujfalusi@...com>
To:     SF Markus Elfring <elfring@...rs.sourceforge.net>,
        <dmaengine@...r.kernel.org>,
        Dan Williams <dan.j.williams@...el.com>,
        Vinod Koul <vinod.koul@...el.com>
CC:     LKML <linux-kernel@...r.kernel.org>,
        <kernel-janitors@...r.kernel.org>
Subject: Re: [PATCH] dmaengine: edma: Use common error handling code in three
 functions



On 2017-10-22 17:54, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@...rs.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@...com>

> Signed-off-by: Markus Elfring <elfring@...rs.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ