summaryrefslogtreecommitdiff
path: root/drivers/char
diff options
context:
space:
mode:
authorRobin Gong <yibin.gong@nxp.com>2020-02-08 03:50:27 +0800
committerJason Liu <jason.hui.liu@nxp.com>2020-02-26 04:17:45 +0800
commitd75952f9939d9be9d9960dacaee89e226b55df52 (patch)
tree3439dc24274a3a6bcd43b888d0de13e722f89ad7 /drivers/char
parent7392a4f58d4da1baab0a01f39ca45da6fd64265c (diff)
LF-857-1: char: imx_amp: imx_sema4: enlarge lock protect
Currently, there is only spin lock added in imx_sema4_mutex_lock(),but sema4 driver assume any mutex should be handled one by one and complain when mutex locked once again before unlocked. Hence, if another lock happens indeed after the last imx_sema4_mutex_lock(),the complains "imx_sema4_ mutex_lock 135 already locked" would come out over again and again as below. So delay lock released into imx_sema4_mutex_unlock() to elimate such race contition. Thread1: Thread2: .... .... ------------------------------------------ imx_sema4_mutex_lock ---->grabbed->|imx_sema4_mutex_lock | |"imx_sema4_mutex_lock 135 already locked"| ------------------------------------------ imx_sema4_mutex_unlock imx_sema4_mutex_unlock .... ..... Signed-off-by: Robin Gong <yibin.gong@nxp.com> Reviewed-by: Anson Huang <anson.huang@nxp.com> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com> (cherry picked from commit 362fdbb91f1c2e386adc6147c07f714be6134907)
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/imx_amp/imx_sema4.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/drivers/char/imx_amp/imx_sema4.c b/drivers/char/imx_amp/imx_sema4.c
index 412202f11cbb..46a178de41f5 100644
--- a/drivers/char/imx_amp/imx_sema4.c
+++ b/drivers/char/imx_amp/imx_sema4.c
@@ -23,6 +23,8 @@
#include <linux/imx_sema4.h>
static struct imx_sema4_mutex_device *imx6_sema4;
+static unsigned long sema4_flags;
+
/*!
* \brief mutex create function.
@@ -203,15 +205,11 @@ EXPORT_SYMBOL(imx_sema4_mutex_trylock);
int imx_sema4_mutex_lock(struct imx_sema4_mutex *mutex_ptr)
{
int ret = 0;
- unsigned long flags;
- spin_lock_irqsave(&imx6_sema4->lock, flags);
+ spin_lock_irqsave(&imx6_sema4->lock, sema4_flags);
ret = _imx_sema4_mutex_lock(mutex_ptr);
- spin_unlock_irqrestore(&imx6_sema4->lock, flags);
while (-EBUSY == ret) {
- spin_lock_irqsave(&imx6_sema4->lock, flags);
ret = _imx_sema4_mutex_lock(mutex_ptr);
- spin_unlock_irqrestore(&imx6_sema4->lock, flags);
if (ret == 0)
break;
}
@@ -259,6 +257,7 @@ int imx_sema4_mutex_unlock(struct imx_sema4_mutex *mutex_ptr)
if (mutex_ptr->gate_val == SEMA4_A9_LOCK)
pr_err("%d ERROR, failed to unlock the mutex.\n", __LINE__);
+ spin_unlock_irqrestore(&imx6_sema4->lock, sema4_flags);
out:
return ret;
}