SMBusSlave_v5_20 problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

In the code generated for the SMBusSlave_v5_20 component there is an error in the code that validates the buffer length:

   

In the header, the validity of the index is checked as follows:

   

/* Helpers to check if a command size is valid. Greater or equal is used to take
* into account the PEC byte. For example, when the PEC is enabled and a host
* writes to a word command, the correct index value is 2 if the host does not
* send PEC, and 3 if it does. The index value greater than 3 results in a Host
* Sends Too Many Bytes fault and is detected in the ISR.
*/
#define HOST_PMBusSlave_CMD_LEN_VALID                  (HOST_PMBusSlave_bufferIndex >= HOST_PMBusSlave_bufferSize)

   

So the check is valid when the index exceeds the size of the buffer. 

   

Here is the usage of the above check:

   

case HOST_PMBusSlave_MFR_ID:
      if(HOST_PMBusSlave_CMD_LEN_VALID)
      {
               (void)memcpy((void *)HOST_PMBusSlave_cmdDataPtr, (const void *)HOST_PMBusSlave_buffer, (uint32)HOST_PMBusSlave_bufferSize);
       }
       break;

   

The sign in the expression should be changed to "<="

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The term "buffersize" is used in Cypress components to indicate the number of bytes in the buffer, not the maximum count the buffer can hold. As you can see the SMBusSlave_1_bufferSize is an uint8 and not a fixed #define.

   

 

   

Bob

View solution in original post

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The term "buffersize" is used in Cypress components to indicate the number of bytes in the buffer, not the maximum count the buffer can hold. As you can see the SMBusSlave_1_bufferSize is an uint8 and not a fixed #define.

   

 

   

Bob

0 Likes