summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2020-11-11 21:54:15 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-12 19:09:03 +0000
commit788c241efcba8e98ca45b002434522725c961050 (patch)
treee45b567bdfff12803abaf6d10cbf2c93b1e61887
parent0b8148c1f2b20cb3883ec7ed2058a53b2f063ff6 (diff)
downloadchrome-ec-788c241efcba8e98ca45b002434522725c961050.tar.gz
ioexpander: Fix type error in command_ioex_get
enum ioex_signal is a uint16. It gets cast to an int32 in command_ioex_get. When find_ioex_by_name returns -1, it gets interpreted as 65535, not -1. Return IOEX_SIGNAL_END from find_ioex_by_name instead of -1. Minor cleanup to make it more clear that enum ioex_signal is not an int. BUG=b:172599383 BRANCH=Zork TEST='ioexget foo' does not crash Change-Id: I92922591b6a657a1d2a0840c3d361a8a909895fb Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2533671 Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--common/ioexpander.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/common/ioexpander.c b/common/ioexpander.c
index c5c06ee8e1..1e3f22764b 100644
--- a/common/ioexpander.c
+++ b/common/ioexpander.c
@@ -79,6 +79,7 @@ static int ioex_is_valid_interrupt_signal(enum ioex_signal signal)
return EC_SUCCESS;
}
+
int ioex_enable_interrupt(enum ioex_signal signal)
{
int rv;
@@ -254,24 +255,24 @@ static int ioex_get_default_flags(enum ioex_signal signal)
/* IO expander commands */
static enum ioex_signal find_ioex_by_name(const char *name)
{
- int i;
+ enum ioex_signal signal;
if (!name)
- return -1;
+ return IOEX_SIGNAL_END;
- for (i = IOEX_SIGNAL_START; i < IOEX_SIGNAL_END; i++) {
- if (!strcasecmp(name, ioex_get_name(i)))
- return i;
+ for (signal = IOEX_SIGNAL_START; signal < IOEX_SIGNAL_END; signal++) {
+ if (!strcasecmp(name, ioex_get_name(signal)))
+ return signal;
}
- return -1;
+ return IOEX_SIGNAL_END;
}
static enum ec_error_list ioex_set(const char *name, int value)
{
enum ioex_signal signal = find_ioex_by_name(name);
- if (signal == -1)
+ if (!signal_is_ioex(signal))
return EC_ERROR_INVAL;
if (!(ioex_get_default_flags(signal) & GPIO_OUTPUT))
@@ -303,21 +304,21 @@ DECLARE_CONSOLE_COMMAND(ioexset, command_ioex_set,
static int command_ioex_get(int argc, char **argv)
{
- int i;
+ enum ioex_signal signal;
/* If a signal is specified, print only that one */
if (argc == 2) {
- i = find_ioex_by_name(argv[1]);
- if (i == -1)
+ signal = find_ioex_by_name(argv[1]);
+ if (!signal_is_ioex(signal))
return EC_ERROR_PARAM1;
- print_ioex_info(i);
+ print_ioex_info(signal);
return EC_SUCCESS;
}
/* Otherwise print them all */
- for (i = IOEX_SIGNAL_START; i < IOEX_SIGNAL_END; i++)
- print_ioex_info(i);
+ for (signal = IOEX_SIGNAL_START; signal < IOEX_SIGNAL_END; signal++)
+ print_ioex_info(signal);
return EC_SUCCESS;
}