提交 e1512566 编写于 作者: Yansira's avatar Yansira

fix: 解决dmesg -s参数double lock问题

【背景】自研shell或者mksh拉起后使用dmesg -s命令出现自旋锁double lock的问题。

【修改方案】
dmesg -s参数设置dmesg缓冲区过程需要访问UartOutput所访问的全局缓冲区,这意味着两个功能模块
使用了同一把自旋锁,若在dmesg命令执行过程使用了打印,则就可能会导致double lock。因此拆分
了dmesg -s命令过程中自旋锁的使用区域,避开内核中必要的打印。

re #I4HIJK
Signed-off-by: Yansira's avataryansira <yansira@hotmail.com>
Change-Id: Iad74c058c9a8090fd3d9f338caab7d8f2170f9ac
上级 07cab404
......@@ -177,13 +177,17 @@ STATIC INT32 OsCopyToNew(const VOID *addr, UINT32 size)
CHAR *newBuf = (CHAR *)addr + sizeof(DmesgInfo);
UINT32 bufSize = size - sizeof(DmesgInfo);
INT32 ret;
UINT32 intSave;
LOS_SpinLockSave(&g_dmesgSpin, &intSave);
if (g_dmesgInfo->logSize == 0) {
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
return 0;
}
temp = (CHAR *)malloc(g_dmesgInfo->logSize);
if (temp == NULL) {
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
return -1;
}
......@@ -195,21 +199,24 @@ STATIC INT32 OsCopyToNew(const VOID *addr, UINT32 size)
ret = OsDmesgRead(temp, g_dmesgInfo->logSize);
if (ret <= 0) {
PRINT_ERR("%s,%d failed, err:%d!\n", __FUNCTION__, __LINE__, ret);
free(temp);
return -1;
goto FREE_OUT;
}
/* if new buf size smaller than logSize */
ret = memcpy_s(newBuf, bufSize, temp + copyStart, copyLen);
if (ret != EOK) {
PRINT_ERR("%s,%d memcpy_s failed, err:%d!\n", __FUNCTION__, __LINE__, ret);
free(temp);
return -1;
goto FREE_OUT;
}
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
free(temp);
return (INT32)copyLen;
FREE_OUT:
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
PRINT_ERR("%s,%d failed, err:%d!\n", __FUNCTION__, __LINE__, ret);
free(temp);
return -1;
}
STATIC UINT32 OsDmesgResetMem(const VOID *addr, UINT32 size)
......@@ -224,12 +231,13 @@ STATIC UINT32 OsDmesgResetMem(const VOID *addr, UINT32 size)
LOS_SpinLockSave(&g_dmesgSpin, &intSave);
temp = g_dmesgInfo;
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
copyLen = OsCopyToNew(addr, size);
if (copyLen < 0) {
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
return LOS_NOK;
}
LOS_SpinLockSave(&g_dmesgSpin, &intSave);
g_logBufSize = size - sizeof(DmesgInfo);
g_dmesgInfo = (DmesgInfo *)addr;
g_dmesgInfo->logBuf = (CHAR *)addr + sizeof(DmesgInfo);
......@@ -239,12 +247,17 @@ STATIC UINT32 OsDmesgResetMem(const VOID *addr, UINT32 size)
/* if old mem came from malloc */
if (temp == g_mallocAddr) {
g_mallocAddr = NULL;
free(temp);
goto FREE_OUT;
}
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
return LOS_OK;
FREE_OUT:
g_mallocAddr = NULL;
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
free(temp);
return LOS_OK;
}
STATIC UINT32 OsDmesgChangeSize(UINT32 size)
......@@ -265,14 +278,14 @@ STATIC UINT32 OsDmesgChangeSize(UINT32 size)
LOS_SpinLockSave(&g_dmesgSpin, &intSave);
temp = g_dmesgInfo;
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
copyLen = OsCopyToNew(newString, size + sizeof(DmesgInfo));
if (copyLen < 0) {
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
free(newString);
return LOS_NOK;
goto ERR_OUT;
}
LOS_SpinLockSave(&g_dmesgSpin, &intSave);
g_logBufSize = size;
g_dmesgInfo = (DmesgInfo *)newString;
g_dmesgInfo->logBuf = (CHAR *)newString + sizeof(DmesgInfo);
......@@ -281,13 +294,21 @@ STATIC UINT32 OsDmesgChangeSize(UINT32 size)
g_dmesgInfo->logHead = 0;
if (temp == g_mallocAddr) {
g_mallocAddr = NULL;
free(temp);
goto FREE_OUT;
}
g_mallocAddr = newString;
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
return LOS_OK;
ERR_OUT:
free(newString);
return LOS_NOK;
FREE_OUT:
g_mallocAddr = newString;
LOS_SpinUnlockRestore(&g_dmesgSpin, intSave);
free(temp);
return LOS_OK;
}
UINT32 OsCheckConsoleLock(VOID)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册