openocd: fix SPDX tag format for files .c
[fw/openocd] / src / svf / svf.c
index e12fbce23cc5913eac488da9614c5045b06b3603..a5374316eafa5f8b6a9d2e026feaca295b9a7a73 100644 (file)
@@ -1,19 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
 /***************************************************************************
  *    Copyright (C) 2009 by Simon Qian                                     *
  *    SimonQian@SimonQian.com                                              *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 /* The specification for SVF is available here:
@@ -460,25 +449,25 @@ COMMAND_HANDLER(handle_svf_command)
                }
 
                /* HDR %d TDI (0) */
-               if (ERROR_OK != svf_set_padding(&svf_para.hdr_para, header_dr_len, 0)) {
+               if (svf_set_padding(&svf_para.hdr_para, header_dr_len, 0) != ERROR_OK) {
                        LOG_ERROR("failed to set data header");
                        return ERROR_FAIL;
                }
 
                /* HIR %d TDI (0xFF) */
-               if (ERROR_OK != svf_set_padding(&svf_para.hir_para, header_ir_len, 0xFF)) {
+               if (svf_set_padding(&svf_para.hir_para, header_ir_len, 0xFF) != ERROR_OK) {
                        LOG_ERROR("failed to set instruction header");
                        return ERROR_FAIL;
                }
 
                /* TDR %d TDI (0) */
-               if (ERROR_OK != svf_set_padding(&svf_para.tdr_para, trailer_dr_len, 0)) {
+               if (svf_set_padding(&svf_para.tdr_para, trailer_dr_len, 0) != ERROR_OK) {
                        LOG_ERROR("failed to set data trailer");
                        return ERROR_FAIL;
                }
 
                /* TIR %d TDI (0xFF) */
-               if (ERROR_OK != svf_set_padding(&svf_para.tir_para, trailer_ir_len, 0xFF)) {
+               if (svf_set_padding(&svf_para.tir_para, trailer_ir_len, 0xFF) != ERROR_OK) {
                        LOG_ERROR("failed to set instruction trailer");
                        return ERROR_FAIL;
                }
@@ -492,7 +481,7 @@ COMMAND_HANDLER(handle_svf_command)
                }
                rewind(svf_fd);
        }
-       while (ERROR_OK == svf_read_command_from_file(svf_fd)) {
+       while (svf_read_command_from_file(svf_fd) == ERROR_OK) {
                /* Log Output */
                if (svf_quiet) {
                        if (svf_progress_enabled) {
@@ -510,7 +499,7 @@ COMMAND_HANDLER(handle_svf_command)
                                LOG_USER_N("%s", svf_read_line);
                }
                /* Run Command */
-               if (ERROR_OK != svf_run_command(CMD_CTX, svf_command_buffer)) {
+               if (svf_run_command(CMD_CTX, svf_command_buffer) != ERROR_OK) {
                        LOG_ERROR("fail to run command at line %d", svf_line_number);
                        ret = ERROR_FAIL;
                        break;
@@ -518,9 +507,9 @@ COMMAND_HANDLER(handle_svf_command)
                command_num++;
        }
 
-       if ((!svf_nil) && (ERROR_OK != jtag_execute_queue()))
+       if ((!svf_nil) && (jtag_execute_queue() != ERROR_OK))
                ret = ERROR_FAIL;
-       else if (ERROR_OK != svf_check_tdo())
+       else if (svf_check_tdo() != ERROR_OK)
                ret = ERROR_FAIL;
 
        /* print time */
@@ -587,7 +576,7 @@ static int svf_getline(char **lineptr, size_t *n, FILE *stream)
 #define MIN_CHUNK 16   /* Buffer is increased by this size each time as required */
        size_t i = 0;
 
-       if (*lineptr == NULL) {
+       if (!*lineptr) {
                *n = MIN_CHUNK;
                *lineptr = malloc(*n);
                if (!*lineptr)
@@ -761,10 +750,10 @@ static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_
 {
        int new_byte_len = (new_bit_len + 7) >> 3;
 
-       if ((NULL == *arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) {
+       if ((!*arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) {
                free(*arr);
                *arr = calloc(1, new_byte_len);
-               if (NULL == *arr) {
+               if (!*arr) {
                        LOG_ERROR("not enough memory");
                        return ERROR_FAIL;
                }
@@ -790,7 +779,7 @@ static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_l
        int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
        uint8_t ch = 0;
 
-       if (ERROR_OK != svf_adjust_array_length(bin, orig_bit_len, bit_len)) {
+       if (svf_adjust_array_length(bin, orig_bit_len, bit_len) != ERROR_OK) {
                LOG_ERROR("fail to adjust length of array");
                return ERROR_FAIL;
        }
@@ -893,9 +882,9 @@ static int svf_add_check_para(uint8_t enabled, int buffer_offset, int bit_len)
 
 static int svf_execute_tap(void)
 {
-       if ((!svf_nil) && (ERROR_OK != jtag_execute_queue()))
+       if ((!svf_nil) && (jtag_execute_queue() != ERROR_OK))
                return ERROR_FAIL;
-       else if (ERROR_OK != svf_check_tdo())
+       else if (svf_check_tdo() != ERROR_OK)
                return ERROR_FAIL;
 
        svf_buffer_index = 0;
@@ -923,7 +912,7 @@ static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str)
        /* flag padding commands skipped due to -tap command */
        int padding_command_skipped = 0;
 
-       if (ERROR_OK != svf_parse_cmd_string(cmd_str, strlen(cmd_str), argus, &num_of_argu))
+       if (svf_parse_cmd_string(cmd_str, strlen(cmd_str), argus, &num_of_argu) != ERROR_OK)
                return ERROR_FAIL;
 
        /* NOTE: we're a bit loose here, because we ignore case in
@@ -963,7 +952,7 @@ static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str)
                                LOG_ERROR("invalid parameter of %s", argus[0]);
                                return ERROR_FAIL;
                        }
-                       if (1 == num_of_argu) {
+                       if (num_of_argu == 1) {
                                /* TODO: set jtag speed to full speed */
                                svf_para.frequency = 0;
                        } else {
@@ -971,7 +960,7 @@ static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str)
                                        LOG_ERROR("HZ not found in FREQUENCY command");
                                        return ERROR_FAIL;
                                }
-                               if (ERROR_OK != svf_execute_tap())
+                               if (svf_execute_tap() != ERROR_OK)
                                        return ERROR_FAIL;
                                svf_para.frequency = atof(argus[1]);
                                /* TODO: set jtag speed to */
@@ -1434,7 +1423,7 @@ xxr_common:
                                                return ERROR_FAIL;
                                        }
                                        /* OpenOCD refuses paths containing TAP_RESET */
-                                       if (TAP_RESET == path[i]) {
+                                       if (path[i] == TAP_RESET) {
                                                /* FIXME last state MUST be stable! */
                                                if (i > 0) {
                                                        if (!svf_nil)
@@ -1487,7 +1476,7 @@ xxr_common:
                                return ERROR_FAIL;
                        }
                        if (svf_para.trst_mode != TRST_ABSENT) {
-                               if (ERROR_OK != svf_execute_tap())
+                               if (svf_execute_tap() != ERROR_OK)
                                        return ERROR_FAIL;
                                i_tmp = svf_find_string_in_array(argus[1],
                                                (char **)svf_trst_mode_name,
@@ -1530,7 +1519,7 @@ xxr_common:
                if ((svf_buffer_index > 0) &&
                                (((command != STATE) && (command != RUNTEST)) ||
                                                ((command == STATE) && (num_of_argu == 2)))) {
-                       if (ERROR_OK != svf_execute_tap())
+                       if (svf_execute_tap() != ERROR_OK)
                                return ERROR_FAIL;
 
                        /* output debug info */