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>
This commit is contained in:
parent
6f47d7ee76
commit
362fdbb91f
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue