diff options
author | Antonio Borneo <borneo.antonio@gmail.com> | 2021-07-03 16:47:35 +0200 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2021-07-20 14:55:24 +0100 |
commit | 28c24a5c41c47a66e9310912f88148814f730a25 (patch) | |
tree | 803cf52a0c8f5a0687f5c7fef402b08cf337ebac /src/helper | |
parent | bba48b057cdc4f26721e06a5310652dcf0e55873 (diff) | |
download | riscv-openocd-28c24a5c41c47a66e9310912f88148814f730a25.zip riscv-openocd-28c24a5c41c47a66e9310912f88148814f730a25.tar.gz riscv-openocd-28c24a5c41c47a66e9310912f88148814f730a25.tar.bz2 |
openocd: fix simple cases of Yoda condition
There are ~900 Yoda conditions to be aligned to the coding style.
For recurrent Yoda conditions it's preferable using a trivial
script in order to minimize the review effort.
E.g. comparison of uppercase macro/enum with lowercase variable:
- ...(ERROR_OK == retval)...
+ ...(retval == ERROR_OK)...
Patch generated automatically with the command:
sed -i \
's/(\([A-Z][A-Z0-9_]*\) \([=!]=\) \([a-z][a-z0-9_]*\))/(\3 \2 \1)/g' \
$(find src/ -type f)
While there, remove the braces {} around a single statement block
to prevent warning from checkpatch.
Change-Id: If585b0a4b4578879c87b2dd74d9e0025e275ec6b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6354
Tested-by: jenkins
Reviewed-by: Xiang W <wxjstz@126.com>
Diffstat (limited to 'src/helper')
-rw-r--r-- | src/helper/command.c | 12 | ||||
-rw-r--r-- | src/helper/command.h | 4 | ||||
-rw-r--r-- | src/helper/fileio.c | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/helper/command.c b/src/helper/command.c index 8ea805b..0c76450 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -394,11 +394,11 @@ int __register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, } else { retval = __register_commands(cmd_ctx, cmd_prefix, cr->chain, data, override_target); } - if (ERROR_OK != retval) + if (retval != ERROR_OK) break; } } - if (ERROR_OK != retval) { + if (retval != ERROR_OK) { for (unsigned j = 0; j < i; j++) unregister_command(cmd_ctx, cmd_prefix, cmds[j].name); } @@ -1171,7 +1171,7 @@ COMMAND_HANDLER(handle_sleep_command) unsigned long duration = 0; int retval = parse_ulong(CMD_ARGV[0], &duration); - if (ERROR_OK != retval) + if (retval != ERROR_OK) return retval; if (!busy) { @@ -1354,11 +1354,11 @@ void process_jim_events(struct command_context *cmd_ctx) LOG_ERROR("Invalid command argument"); \ return ERROR_COMMAND_ARGUMENT_INVALID; \ } \ - if ((max == *ul) && (ERANGE == errno)) { \ + if ((max == *ul) && (errno == ERANGE)) { \ LOG_ERROR("Argument overflow"); \ return ERROR_COMMAND_ARGUMENT_OVERFLOW; \ } \ - if (min && (min == *ul) && (ERANGE == errno)) { \ + if (min && (min == *ul) && (errno == ERANGE)) { \ LOG_ERROR("Argument underflow"); \ return ERROR_COMMAND_ARGUMENT_UNDERFLOW; \ } \ @@ -1374,7 +1374,7 @@ DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MIN, LLONG_MAX) { \ functype n; \ int retval = parse ## funcname(str, &n); \ - if (ERROR_OK != retval) \ + if (retval != ERROR_OK) \ return retval; \ if (n > max) \ return ERROR_COMMAND_ARGUMENT_OVERFLOW; \ diff --git a/src/helper/command.h b/src/helper/command.h index 719c94b..f387019 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -427,7 +427,7 @@ DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t); #define COMMAND_PARSE_NUMBER(type, in, out) \ do { \ int retval_macro_tmp = parse_ ## type(in, &(out)); \ - if (ERROR_OK != retval_macro_tmp) { \ + if (retval_macro_tmp != ERROR_OK) { \ command_print(CMD, stringify(out) \ " option value ('%s') is not valid", in); \ return retval_macro_tmp; \ @@ -489,7 +489,7 @@ DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t); do { \ bool value; \ int retval_macro_tmp = command_parse_bool_arg(in, &value); \ - if (ERROR_OK != retval_macro_tmp) { \ + if (retval_macro_tmp != ERROR_OK) { \ command_print(CMD, stringify(out) \ " option value ('%s') is not valid", in); \ command_print(CMD, " choices are '%s' or '%s'", \ diff --git a/src/helper/fileio.c b/src/helper/fileio.c index b6f1f4e..5138fa1 100644 --- a/src/helper/fileio.c +++ b/src/helper/fileio.c @@ -200,7 +200,7 @@ int fileio_read_u32(struct fileio *fileio, uint32_t *data) if (ERROR_OK == retval && sizeof(uint32_t) != size_read) retval = -EIO; - if (ERROR_OK == retval) + if (retval == ERROR_OK) *data = be_to_h_u32(buf); return retval; |