dmaengine: fsl-edma: fix miss mutex unlock at an error return path
authorFrank Li <Frank.Li@nxp.com>
Thu, 11 Apr 2024 20:39:35 +0000 (16:39 -0400)
committerVinod Koul <vkoul@kernel.org>
Wed, 17 Apr 2024 17:09:52 +0000 (22:39 +0530)
Use cleanup to manage mutex. Let compiler to do scope guard automatically.

Fixes: 6aa60f79e679 ("dmaengine: fsl-edma: add safety check for 'srcid'")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202404110915.riwV3ZAC-lkp@intel.com/
Signed-off-by: Frank Li <Frank.Li@nxp.com>
Link: https://lore.kernel.org/r/20240411203935.3137158-1-Frank.Li@nxp.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/dma/fsl-edma-common.c
drivers/dma/fsl-edma-main.c

index f9144b015439647b4b780c6b5cc848b4f5b84f2d..73628eac8aadccfa56c06dcaa59088f909caba14 100644 (file)
@@ -3,6 +3,7 @@
 // Copyright (c) 2013-2014 Freescale Semiconductor, Inc
 // Copyright (c) 2017 Sysam, Angelo Dureghello  <angelo@sysam.it>
 
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/dmapool.h>
 #include <linux/module.h>
index 755a3dc3b0a78a47875570079b015a6f792e5a08..de03148aed0b3ba6205f70bec6f089d0d1ff1a89 100644 (file)
@@ -105,7 +105,8 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec,
        if (dma_spec->args_count != 2)
                return NULL;
 
-       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) {
                if (chan->client_count)
                        continue;
@@ -124,12 +125,10 @@ static struct dma_chan *fsl_edma_xlate(struct of_phandle_args *dma_spec,
 
                                fsl_edma_chan_mux(fsl_chan, fsl_chan->srcid,
                                                true);
-                               mutex_unlock(&fsl_edma->fsl_edma_mutex);
                                return chan;
                        }
                }
        }
-       mutex_unlock(&fsl_edma->fsl_edma_mutex);
        return NULL;
 }