openocd: fix Yoda conditions with checkpatch
[fw/openocd] / src / flash / nor / msp432.c
index b418bf152beb0c87d9fd092a5e9ed1458cc5b055..667349f281c5e55d88dd267d8bee370ed13c5be7 100644 (file)
@@ -209,7 +209,7 @@ static int msp432_wait_return_code(struct target *target)
        int retval = ERROR_OK;
 
        start_ms = timeval_ms();
-       while ((0 == return_code) || (return_code == FLASH_BUSY)) {
+       while ((return_code == 0) || (return_code == FLASH_BUSY)) {
                retval = target_read_u32(target, ALGO_RETURN_CODE_ADDR, &return_code);
                if (retval != ERROR_OK)
                        return retval;
@@ -315,18 +315,18 @@ static int msp432_init(struct flash_bank *bank)
        }
 
        /* Issue warnings if this is a device we may not be able to flash */
-       if (MSP432P401X_GUESS == msp432_bank->device_type ||
-               MSP432P411X_GUESS == msp432_bank->device_type) {
+       if (msp432_bank->device_type == MSP432P401X_GUESS ||
+               msp432_bank->device_type == MSP432P411X_GUESS) {
                /* Explicit device type check failed. Report this. */
                LOG_WARNING(
                        "msp432: Unrecognized MSP432P4 Device ID and Hardware "
                        "Rev (%04" PRIX32 ", %02" PRIX32 ")", msp432_bank->device_id,
                        msp432_bank->hardware_rev);
-       } else if (MSP432P401X_DEPR == msp432_bank->device_type) {
+       } else if (msp432_bank->device_type == MSP432P401X_DEPR) {
                LOG_WARNING(
                        "msp432: MSP432P401x pre-production device (deprecated "
                        "silicon)\n" SUPPORT_MESSAGE);
-       } else if (MSP432E4X_GUESS == msp432_bank->device_type) {
+       } else if (msp432_bank->device_type == MSP432E4X_GUESS) {
                /* Explicit device type check failed. Report this. */
                LOG_WARNING(
                        "msp432: Unrecognized MSP432E4 DID0 and DID1 values "
@@ -335,7 +335,7 @@ static int msp432_init(struct flash_bank *bank)
        }
 
        /* Check for working area to use for flash helper algorithm */
-       if (NULL != msp432_bank->working_area)
+       if (msp432_bank->working_area)
                target_free_working_area(target, msp432_bank->working_area);
        retval = target_alloc_working_area(target, ALGO_WORKING_SIZE,
                                &msp432_bank->working_area);
@@ -343,7 +343,7 @@ static int msp432_init(struct flash_bank *bank)
                return retval;
 
        /* Confirm the defined working address is the area we need to use */
-       if (ALGO_BASE_ADDR != msp432_bank->working_area->address)
+       if (msp432_bank->working_area->address != ALGO_BASE_ADDR)
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
 
        /* Write flash helper algorithm into target memory */
@@ -432,7 +432,7 @@ static int msp432_mass_erase(struct flash_bank *bank, bool all)
 
        int retval;
 
-       if (TARGET_HALTED != target->state) {
+       if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
@@ -489,9 +489,9 @@ COMMAND_HANDLER(msp432_mass_erase_command)
                all = false;
        } else if (2 == CMD_ARGC) {
                /* Check argument for how much to erase */
-               if (0 == strcmp(CMD_ARGV[1], "main"))
+               if (strcmp(CMD_ARGV[1], "main") == 0)
                        all = false;
-               else if (0 == strcmp(CMD_ARGV[1], "all"))
+               else if (strcmp(CMD_ARGV[1], "all") == 0)
                        all = true;
                else
                        return ERROR_COMMAND_SYNTAX_ERROR;
@@ -501,7 +501,7 @@ COMMAND_HANDLER(msp432_mass_erase_command)
 
        msp432_bank = bank->driver_priv;
 
-       if (MSP432E4 == msp432_bank->family_type) {
+       if (msp432_bank->family_type == MSP432E4) {
                /* MSP432E4 does not have main vs info regions, ignore "all" */
                all = false;
        }
@@ -510,7 +510,7 @@ COMMAND_HANDLER(msp432_mass_erase_command)
        if (retval != ERROR_OK)
                return retval;
 
-       if (MSP432E4 == msp432_bank->family_type) {
+       if (msp432_bank->family_type == MSP432E4) {
                /* MSP432E4 does not have main vs info regions */
                LOG_INFO("msp432: Mass erase of flash is complete");
        } else {
@@ -537,15 +537,15 @@ COMMAND_HANDLER(msp432_bsl_command)
 
        msp432_bank = bank->driver_priv;
 
-       if (MSP432E4 == msp432_bank->family_type) {
+       if (msp432_bank->family_type == MSP432E4) {
                LOG_WARNING("msp432: MSP432E4 does not have a BSL region");
                return ERROR_OK;
        }
 
        if (2 == CMD_ARGC) {
-               if (0 == strcmp(CMD_ARGV[1], "lock"))
+               if (strcmp(CMD_ARGV[1], "lock") == 0)
                        msp432_bank->unlock_bsl = false;
-               else if (0 == strcmp(CMD_ARGV[1], "unlock"))
+               else if (strcmp(CMD_ARGV[1], "unlock") == 0)
                        msp432_bank->unlock_bsl = true;
                else
                        return ERROR_COMMAND_SYNTAX_ERROR;
@@ -569,7 +569,7 @@ FLASH_BANK_COMMAND_HANDLER(msp432_flash_bank_command)
 
        /* Create shared private struct for flash banks */
        msp432_bank = malloc(sizeof(struct msp432_bank));
-       if (NULL == msp432_bank)
+       if (!msp432_bank)
                return ERROR_FAIL;
 
        /* Initialize private flash information */
@@ -597,12 +597,12 @@ static int msp432_erase(struct flash_bank *bank, unsigned int first,
        struct msp432_bank *msp432_bank = bank->driver_priv;
        struct msp432_algo_params algo_params;
 
-       bool is_main = FLASH_BASE == bank->base;
-       bool is_info = P4_FLASH_INFO_BASE == bank->base;
+       bool is_main = bank->base == FLASH_BASE;
+       bool is_info = bank->base == P4_FLASH_INFO_BASE;
 
        int retval;
 
-       if (TARGET_HALTED != target->state) {
+       if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
@@ -676,11 +676,11 @@ static int msp432_write(struct flash_bank *bank, const uint8_t *buffer,
        long long start_ms;
        long long elapsed_ms;
 
-       bool is_info = P4_FLASH_INFO_BASE == bank->base;
+       bool is_info = bank->base == P4_FLASH_INFO_BASE;
 
        int retval;
 
-       if (TARGET_HALTED != target->state) {
+       if (target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
                return ERROR_TARGET_NOT_HALTED;
        }
@@ -812,8 +812,8 @@ static int msp432_probe(struct flash_bank *bank)
        uint32_t size;
        unsigned int num_sectors;
 
-       bool is_main = FLASH_BASE == bank->base;
-       bool is_info = P4_FLASH_INFO_BASE == bank->base;
+       bool is_main = bank->base == FLASH_BASE;
+       bool is_info = bank->base == P4_FLASH_INFO_BASE;
 
        int retval;
 
@@ -829,7 +829,7 @@ static int msp432_probe(struct flash_bank *bank)
        if (retval != ERROR_OK)
                return retval;
 
-       if (0 == size) {
+       if (size == 0) {
                /* This is likely an MSP432E4 */
                msp432_bank->family_type = MSP432E4;
 
@@ -864,7 +864,7 @@ static int msp432_probe(struct flash_bank *bank)
        msp432_bank->device_type = msp432_device_type(msp432_bank->family_type,
                msp432_bank->device_id, msp432_bank->hardware_rev);
 
-       if (MSP432P4 == msp432_bank->family_type) {
+       if (msp432_bank->family_type == MSP432P4) {
                /* Set up MSP432P4 specific flash parameters */
                if (is_main) {
                        retval = target_read_u32(target, P4_FLASH_MAIN_SIZE_REG, &size);
@@ -907,7 +907,7 @@ static int msp432_probe(struct flash_bank *bank)
 
        if (num_sectors > 0) {
                bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
-               if (NULL == bank->sectors)
+               if (!bank->sectors)
                        return ERROR_FAIL;
        }
 
@@ -933,7 +933,7 @@ static int msp432_probe(struct flash_bank *bank)
        if (is_main && MSP432P4 == msp432_bank->family_type) {
                /* Create the info flash bank needed by MSP432P4 variants */
                struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
-               if (NULL == info)
+               if (!info)
                        return ERROR_FAIL;
 
                /* Create a name for the info bank, append "_1" to main name */
@@ -960,8 +960,8 @@ static int msp432_auto_probe(struct flash_bank *bank)
 {
        struct msp432_bank *msp432_bank = bank->driver_priv;
 
-       bool is_main = FLASH_BASE == bank->base;
-       bool is_info = P4_FLASH_INFO_BASE == bank->base;
+       bool is_main = bank->base == FLASH_BASE;
+       bool is_info = bank->base == P4_FLASH_INFO_BASE;
 
        int retval = ERROR_OK;
 
@@ -981,7 +981,7 @@ static int msp432_info(struct flash_bank *bank, struct command_invocation *cmd)
 
        switch (msp432_bank->device_type) {
                case MSP432P401X_DEPR:
-                       if (0xFFFF == msp432_bank->device_id) {
+                       if (msp432_bank->device_id == 0xFFFF) {
                                /* Very early pre-production silicon currently deprecated */
                                command_print_sameline(cmd, "MSP432P401x pre-production device (deprecated silicon)\n"
                                        SUPPORT_MESSAGE);
@@ -1030,7 +1030,7 @@ static int msp432_protect_check(struct flash_bank *bank)
 
 static void msp432_flash_free_driver_priv(struct flash_bank *bank)
 {
-       bool is_main = FLASH_BASE == bank->base;
+       bool is_main = bank->base == FLASH_BASE;
 
        /* A single private struct is shared between main and info banks */
        /* Only free it on the call for main bank */