This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SYSCONFIG: Sysconfig 1.21.2: Potential bug in code generator in Sysconfig 1.21.2

Part Number: SYSCONFIG
Other Parts Discussed in Thread: AM6442,

Tool/software:

Dear TI team,

When using Sysconfig 1.21.2 and MCU+ SDK v10.00.00.02 for AM6442, we get the following behavior:

* In the generated file ti_power_clock_config.c the structure SOC_ModuleClockFrequency is declared in the following way:

typedef struct {

    uint32_t moduleId;
    uint32_t clkId;
    uint32_t clkRate;
    uint32_t clkParentId;
} SOC_ModuleClockFrequency;

Later, in the unction void Module_clockSetFrequency(void) a global variable of the above type is being used in a compare statement:

void Module_clockSetFrequency(void)
{
    int32_t status;
    uint32_t i = 0;

    while(gSocModulesClockFrequency[i].moduleId!=SOC_MODULES_END)
    {
        if (gSocModulesClockFrequency[i].clkParentId != -1)
        {
            /* Set module clock to specified frequency and with a specific parent */
            status = SOC_moduleSetClockFrequencyWithParent(
                        gSocModulesClockFrequency[i].moduleId,
                        gSocModulesClockFrequency[i].clkId,
                        gSocModulesClockFrequency[i].clkParentId,
                        gSocModulesClockFrequency[i].clkRate
                        );
        }
        else
        {
            /* Set module clock to specified frequency */
            status = SOC_moduleSetClockFrequency(
                        gSocModulesClockFrequency[i].moduleId,
                        gSocModulesClockFrequency[i].clkId,
                        gSocModulesClockFrequency[i].clkRate
                        );
        }
        DebugP_assertNoLog(status == SystemP_SUCCESS);
        i++;
    }
}

Apparently, the comparison of the field clkParentId(type uint32_t) with -1  is error-prone and can lead to undefined behavior.

Please comment. 


Thanks and regards!

  • Hi Angel,

    Thanks for your query.

    Apparently, the comparison of the field clkParentId(type uint32_t) with -1  is error-prone and can lead to undefined behavior.

    If you see the gSocModulesClockFrequency schema, it contains clkParentId of type uint32_t which is unsigned in nature. So converting the value -1 to an unsigned integer will result in 0xFFFFFFFF. The value -1 indicates to invalid clkparentId (SOC_MODULES_END). 

    The clkparentId is actually getting compared with the macro SOC_MODULES_END(0xFFFFFFFF) .

    I will create a Jira for this to use the SOC_MODULES_END macro instead of comparing it with -1.

    Hope the above clarifies.

    Regards,

    Tushar

  • Despite that explanation, I still think it is an error-prone code, compiler- and optimization-dependend.