flash: fix clang static analyzer build errors
[fw/openocd] / src / flash / nor / stmqspi.c
index e8e0061307882a72a558b98e8841840e0ecd355f..8278601db2a104ea25faeea886a3cb4d2dc394d6 100644 (file)
@@ -40,6 +40,7 @@
 #endif
 
 #include "imp.h"
+#include <helper/binarybuffer.h>
 #include <helper/bits.h>
 #include <helper/time_support.h>
 #include <target/algorithm.h>
@@ -225,7 +226,7 @@ FLASH_BANK_COMMAND_HANDLER(stmqspi_flash_bank_command)
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], io_base);
 
        stmqspi_info = malloc(sizeof(struct stmqspi_flash_bank));
-       if (stmqspi_info == NULL) {
+       if (!stmqspi_info) {
                LOG_ERROR("not enough memory");
                return ERROR_FAIL;
        }
@@ -588,18 +589,13 @@ COMMAND_HANDLER(stmqspi_handle_mass_erase_command)
        retval = wait_till_ready(bank, SPI_MASS_ERASE_TIMEOUT);
 
        duration_measure(&bench);
-       if (retval == ERROR_OK) {
-               /* set all sectors as erased */
-               for (sector = 0; sector < bank->num_sectors; sector++)
-                       bank->sectors[sector].is_erased = 1;
-
+       if (retval == ERROR_OK)
                command_print(CMD, "stmqspi mass erase completed in %fs (%0.3f KiB/s)",
                        duration_elapsed(&bench),
                        duration_kbps(&bench, bank->size));
-       } else {
+       else
                command_print(CMD, "stmqspi mass erase not completed even after %fs",
                        duration_elapsed(&bench));
-       }
 
 err:
        /* Switch to memory mapped mode before return to prompt */
@@ -754,7 +750,7 @@ COMMAND_HANDLER(stmqspi_handle_set)
        bank->num_sectors =
                stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
        sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
-       if (sectors == NULL) {
+       if (!sectors) {
                LOG_ERROR("not enough memory");
                return ERROR_FAIL;
        }
@@ -2358,7 +2354,7 @@ static int stmqspi_probe(struct flash_bank *bank)
        /* create and fill sectors array */
        bank->num_sectors = stmqspi_info->dev.size_in_bytes / stmqspi_info->dev.sectorsize;
        sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
-       if (sectors == NULL) {
+       if (!sectors) {
                LOG_ERROR("not enough memory");
                retval = ERROR_FAIL;
                goto err;