lkml.org 
[lkml]   [2017]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] ASoC: sst-firmware: Improve unlocking of a mutex in sst_block_alloc_scratch()
Date
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);

--
2.15.0
\
 
 \ /
  Last update: 2017-11-19 10:59    [W:0.058 / U:0.204 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site