diff mbox series

[v1,1/2] dmaengine: fsl-edma: change to guard(mutex) within fsl_edma3_xlate()

Message ID 20240621104932.4116137-2-joy.zou@nxp.com (mailing list archive)
State Superseded
Headers show
Series add edma src ID check at request channel | expand

Commit Message

Joy Zou June 21, 2024, 10:49 a.m. UTC
Introduce a scope guard to automatically unlock the mutex within
fsl_edma3_xlate() to simplify the code.

Prepare to add source ID checks in the future.

Signed-off-by: Joy Zou <joy.zou@nxp.com>
---
 drivers/dma/fsl-edma-main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Frank Li June 21, 2024, 2:48 p.m. UTC | #1
On Fri, Jun 21, 2024 at 06:49:31PM +0800, Joy Zou wrote:
> Introduce a scope guard to automatically unlock the mutex within
> fsl_edma3_xlate() to simplify the code.
> 
> Prepare to add source ID checks in the future.
> 
> Signed-off-by: Joy Zou <joy.zou@nxp.com>

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> ---
>  drivers/dma/fsl-edma-main.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
> index c66185c5a199..d4f29ece69f5 100644
> --- a/drivers/dma/fsl-edma-main.c
> +++ b/drivers/dma/fsl-edma-main.c
> @@ -153,7 +153,7 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec,
>  
>  	b_chmux = !!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_CHMUX);
>  
> -	mutex_lock(&fsl_edma->fsl_edma_mutex);
> +	guard(mutex)(&fsl_edma->fsl_edma_mutex);
>  	list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels,
>  					device_node) {
>  
> @@ -177,18 +177,15 @@ static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec,
>  		if (!b_chmux && i == dma_spec->args[0]) {
>  			chan = dma_get_slave_channel(chan);
>  			chan->device->privatecnt++;
> -			mutex_unlock(&fsl_edma->fsl_edma_mutex);
>  			return chan;
>  		} else if (b_chmux && !fsl_chan->srcid) {
>  			/* if controller support channel mux, choose a free channel */
>  			chan = dma_get_slave_channel(chan);
>  			chan->device->privatecnt++;
>  			fsl_chan->srcid = dma_spec->args[0];
> -			mutex_unlock(&fsl_edma->fsl_edma_mutex);
>  			return chan;
>  		}
>  	}
> -	mutex_unlock(&fsl_edma->fsl_edma_mutex);
>  	return NULL;
>  }
>  
> -- 
> 2.37.1
>
diff mbox series

Patch

diff --git a/drivers/dma/fsl-edma-main.c b/drivers/dma/fsl-edma-main.c
index c66185c5a199..d4f29ece69f5 100644
--- a/drivers/dma/fsl-edma-main.c
+++ b/drivers/dma/fsl-edma-main.c
@@ -153,7 +153,7 @@  static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec,
 
 	b_chmux = !!(fsl_edma->drvdata->flags & FSL_EDMA_DRV_HAS_CHMUX);
 
-	mutex_lock(&fsl_edma->fsl_edma_mutex);
+	guard(mutex)(&fsl_edma->fsl_edma_mutex);
 	list_for_each_entry_safe(chan, _chan, &fsl_edma->dma_dev.channels,
 					device_node) {
 
@@ -177,18 +177,15 @@  static struct dma_chan *fsl_edma3_xlate(struct of_phandle_args *dma_spec,
 		if (!b_chmux && i == dma_spec->args[0]) {
 			chan = dma_get_slave_channel(chan);
 			chan->device->privatecnt++;
-			mutex_unlock(&fsl_edma->fsl_edma_mutex);
 			return chan;
 		} else if (b_chmux && !fsl_chan->srcid) {
 			/* if controller support channel mux, choose a free channel */
 			chan = dma_get_slave_channel(chan);
 			chan->device->privatecnt++;
 			fsl_chan->srcid = dma_spec->args[0];
-			mutex_unlock(&fsl_edma->fsl_edma_mutex);
 			return chan;
 		}
 	}
-	mutex_unlock(&fsl_edma->fsl_edma_mutex);
 	return NULL;
 }