diff options
author | Tim Van Patten <timvp@google.com> | 2023-03-07 11:02:54 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-09 23:58:20 +0000 |
commit | a362f8c342528a372d2acaa9fbb1883b8b5a0ec5 (patch) | |
tree | 67ed81d75d7f705f76311371c2898735a8beeeef | |
parent | ba8a4079180b3bf73ae736bd0d76a83dd4fcda88 (diff) | |
download | chrome-ec-a362f8c342528a372d2acaa9fbb1883b8b5a0ec5.tar.gz |
body_detection,tablet_mode: Cleanup parameter checking
Cleanup the parameter checking to use strncmp() for the following
commands:
- bodydetectmode
- tabletmode
BRANCH=none
BUG=b:257490479
TEST=bodydetectmode on|off|reset
TEST=bodydetectmode onf|ofn|reeseet
TEST=tabletmode on|off|reset
TEST=tabletmode onf|ofn|reeseet
Change-Id: Ifeae3f41d3a2af634f7ffc6623db29117b5afe77
Signed-off-by: Tim Van Patten <timvp@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4316726
Reviewed-by: Diana Z <dzigterman@chromium.org>
Reviewed-by: Rob Barnes <robbarnes@google.com>
-rw-r--r-- | common/body_detection.c | 7 | ||||
-rw-r--r-- | common/tablet_mode.c | 9 |
2 files changed, 10 insertions, 6 deletions
diff --git a/common/body_detection.c b/common/body_detection.c index cfc4052390..3357283eb2 100644 --- a/common/body_detection.c +++ b/common/body_detection.c @@ -275,13 +275,14 @@ static int command_setbodydetectionmode(int argc, const char **argv) if (argc != 2) return EC_ERROR_PARAM_COUNT; - if (argv[1][0] == 'o' && argv[1][1] == 'n') { + /* |+1| to also make sure the strings the same length. */ + if (strncmp(argv[1], "on", strlen("on") + 1) == 0) { body_detect_change_state(BODY_DETECTION_ON_BODY, true); spoof_enable = true; - } else if (argv[1][0] == 'o' && argv[1][1] == 'f') { + } else if (strncmp(argv[1], "off", strlen("off") + 1) == 0) { body_detect_change_state(BODY_DETECTION_OFF_BODY, true); spoof_enable = true; - } else if (argv[1][0] == 'r') { + } else if (strncmp(argv[1], "reset", strlen("reset") + 1) == 0) { body_detect_reset(); /* * Don't call body_detect_set_spoof(), since diff --git a/common/tablet_mode.c b/common/tablet_mode.c index 18e97e91db..bfdc7558ee 100644 --- a/common/tablet_mode.c +++ b/common/tablet_mode.c @@ -13,6 +13,8 @@ #include "tablet_mode.h" #include "timer.h" +#include <string.h> + #define CPRINTS(format, args...) cprints(CC_MOTION_LID, format, ##args) #define CPRINTF(format, args...) cprintf(CC_MOTION_LID, format, ##args) @@ -250,13 +252,14 @@ static int command_settabletmode(int argc, const char **argv) if (tablet_mode_forced == false) tablet_mode_store = tablet_mode; - if (argv[1][0] == 'o' && argv[1][1] == 'n') { + /* |+1| to also make sure the strings the same length. */ + if (strncmp(argv[1], "on", strlen("on") + 1) == 0) { tablet_mode = TABLET_TRIGGER_LID; tablet_mode_forced = true; - } else if (argv[1][0] == 'o' && argv[1][1] == 'f') { + } else if (strncmp(argv[1], "off", strlen("off") + 1) == 0) { tablet_mode = 0; tablet_mode_forced = true; - } else if (argv[1][0] == 'r') { + } else if (strncmp(argv[1], "reset", strlen("reset") + 1) == 0) { tablet_mode = tablet_mode_store; tablet_mode_forced = false; } else { |