1
0
Fork 0

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)
5.4-rM2-2.2.x-imx-squashed
Robin Gong 2020-02-08 03:50:27 +08:00 committed by Jason Liu
parent 7392a4f58d
commit d75952f993
1 changed files with 4 additions and 5 deletions

View File

@ -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;
}