121-cpe-api-intern-dynamically-allocate-dump-msg.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --- a/src/drv_mei_cpe_api_intern.c
  2. +++ b/src/drv_mei_cpe_api_intern.c
  3. @@ -421,7 +421,9 @@ IFX_int32_t MEI_InternalMsgSend(
  4. return retVal;
  5. }
  6. -static IFX_void_t MEI_Internal_DumpMessage(
  7. +#define MEI_Internal_DumpMessage_bufSize 10
  8. +
  9. +static IFX_int32_t MEI_Internal_DumpMessage(
  10. MEI_DYN_CNTRL_T *pMeiDynCntrl,
  11. const IFX_uint16_t nMsgId,
  12. const IFX_uint16_t *pData,
  13. @@ -435,15 +437,20 @@ static IFX_void_t MEI_Internal_DumpMessa
  14. IFX_uint8_t i;
  15. const IFX_uint32_t nCommonPayloadSize = 5*nSize/2;
  16. const IFX_uint8_t nInfoSize = 35;
  17. - const IFX_uint8_t nBufSize = 10;
  18. IFX_uint32_t nMsgSize = nCommonPayloadSize + nInfoSize;
  19. IFX_uint32_t nCharsWrittenToBuf = 0;
  20. - char msg[nMsgSize];
  21. - char buf[nBufSize];
  22. + char *msg;
  23. + char buf[MEI_Internal_DumpMessage_bufSize];
  24. if((pData == IFX_NULL) || (nSize < 4))
  25. {
  26. - return ;
  27. + return 0;
  28. + }
  29. +
  30. + msg = kcalloc(nMsgSize, sizeof(*msg), GFP_KERNEL);
  31. + if (!msg)
  32. + {
  33. + return -ENOMEM;
  34. }
  35. pMsg16 = (IFX_uint16_t*)(pData+2);
  36. @@ -464,7 +471,8 @@ static IFX_void_t MEI_Internal_DumpMessa
  37. /* 32-bit payload elements */
  38. for (i=0; i<((nSize-4)/4); i++)
  39. {
  40. - nCharsWrittenToBuf = snprintf(buf, nBufSize, " %08X", pMsg32[i]);
  41. + nCharsWrittenToBuf = snprintf(buf, MEI_Internal_DumpMessage_bufSize,
  42. + " %08X", pMsg32[i]);
  43. strncat(msg, buf, nMsgSize);
  44. nMsgSize -= nCharsWrittenToBuf;
  45. }
  46. @@ -474,7 +482,8 @@ static IFX_void_t MEI_Internal_DumpMessa
  47. /* 16-bit payload elements */
  48. for (i=0; i<((nSize-4)/2); i++)
  49. {
  50. - nCharsWrittenToBuf = snprintf(buf, nBufSize, " %04X", pMsg16[i]);
  51. + nCharsWrittenToBuf = snprintf(buf, MEI_Internal_DumpMessage_bufSize,
  52. + " %04X", pMsg16[i]);
  53. strncat(msg, buf, nMsgSize);
  54. nMsgSize -= nCharsWrittenToBuf;
  55. }
  56. @@ -482,6 +491,10 @@ static IFX_void_t MEI_Internal_DumpMessa
  57. strncat(msg, MEI_DRV_CRLF, nMsgSize);
  58. PRN_DBG_USR_RAW(MEI_MSG_DUMP_API, dbg_level, (msg));
  59. +
  60. + kfree(msg);
  61. +
  62. + return 0;
  63. }
  64. IFX_int32_t MEI_InternalSendMessage(
  65. @@ -503,18 +516,25 @@ IFX_int32_t MEI_InternalSendMessage(
  66. msg.ack_msg.pPayload = (unsigned char *)pDataAck;
  67. msg.ack_msg.paylSize_byte = nLenAck;
  68. - MEI_Internal_DumpMessage(pMeiDynCntrl, msg.write_msg.msgId,
  69. + ret = MEI_Internal_DumpMessage(pMeiDynCntrl, msg.write_msg.msgId,
  70. (IFX_uint16_t *)msg.write_msg.pPayload, msg.write_msg.paylSize_byte,
  71. IFX_FALSE, MEI_DRV_PRN_LEVEL_NORMAL);
  72. + if (ret < 0)
  73. + {
  74. + return ret;
  75. + }
  76. +
  77. ret = MEI_InternalMsgSend(pMeiDynCntrl, &msg);
  78. - if (ret >= 0)
  79. + if (ret < 0)
  80. {
  81. - MEI_Internal_DumpMessage(pMeiDynCntrl, msg.ack_msg.msgId,
  82. + return ret;
  83. + }
  84. +
  85. + ret = MEI_Internal_DumpMessage(pMeiDynCntrl, msg.ack_msg.msgId,
  86. (IFX_uint16_t *)msg.ack_msg.pPayload, msg.ack_msg.paylSize_byte,
  87. IFX_TRUE, MEI_DRV_PRN_LEVEL_NORMAL);
  88. - }
  89. return ret;
  90. }