[alsa-devel] [PATCH] ASoC: sst-firmware: Improve unlocking of a mutex in sst_block_alloc_scratch()
From: Markus Elfring elfring@users.sourceforge.net Date: Sun, 19 Nov 2017 10:45:36 +0100
* Add a jump target so that a call of the function "mutex_unlock" is stored only once in this function implementation.
* Replace three calls by goto statements.
* Increase the lock scope.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring elfring@users.sourceforge.net --- sound/soc/intel/common/sst-firmware.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/sound/soc/intel/common/sst-firmware.c b/sound/soc/intel/common/sst-firmware.c index 79a9fdf94d38..665e66670512 100644 --- a/sound/soc/intel/common/sst-firmware.c +++ b/sound/soc/intel/common/sst-firmware.c @@ -1097,8 +1097,8 @@ int sst_block_alloc_scratch(struct sst_dsp *dsp)
if (dsp->scratch_size == 0) { dev_info(dsp->dev, "no modules need scratch buffer\n"); - mutex_unlock(&dsp->mutex); - return 0; + ret = 0; + goto unlock; }
/* allocate blocks for module scratch buffers */ @@ -1127,21 +1127,21 @@ int sst_block_alloc_scratch(struct sst_dsp *dsp) } if (ret < 0) { dev_err(dsp->dev, "error: can't alloc scratch blocks\n"); - mutex_unlock(&dsp->mutex); - return ret; + goto unlock; }
ret = block_list_prepare(dsp, &dsp->scratch_block_list); if (ret < 0) { dev_err(dsp->dev, "error: scratch block prepare failed\n"); - mutex_unlock(&dsp->mutex); - return ret; + goto unlock; }
/* assign the same offset of scratch to each module */ dsp->scratch_offset = ba.offset; + ret = dsp->scratch_size; +unlock: mutex_unlock(&dsp->mutex); - return dsp->scratch_size; + return ret; } EXPORT_SYMBOL_GPL(sst_block_alloc_scratch);
participants (1)
-
SF Markus Elfring