提交 2fa85a2c 编写于 作者: O openharmony_ci 提交者: Gitee

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

Merge pull request !703 from Kiita/1109_dmesg
......@@ -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.
先完成此消息的编辑!
想要评论请 注册