ectool: Cleanup 'tabletmode' parameter checking
Cleanup the parameter checking to use strncmp() for the command
'tabletmode'.
This makes ectool match the EC console command parameter checking.
BUG=b:257490479
TEST=ectool tabletmode on|off|reset
TEST=ectool tabletmode onf|ofn|reeseet
Change-Id: Iee76b75b24ec7906accd346e0a21a2e652f00b7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4577897
Commit-Queue: Tim Van Patten <timvp@google.com>
Tested-by: Tim Van Patten <timvp@google.com>
Reviewed-by: Diana Z <dzigterman@chromium.org>
diff --git a/util/ectool.cc b/util/ectool.cc
index 332a484..9a26e28 100644
--- a/util/ectool.cc
+++ b/util/ectool.cc
@@ -7314,11 +7314,12 @@
return EC_ERROR_PARAM_COUNT;
memset(&p, 0, sizeof(p));
- 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) {
p.tablet_mode = TABLET_MODE_FORCE_TABLET;
- } else if (argv[1][0] == 'o' && argv[1][1] == 'f') {
+ } else if (strncmp(argv[1], "off", strlen("off") + 1) == 0) {
p.tablet_mode = TABLET_MODE_FORCE_CLAMSHELL;
- } else if (argv[1][0] == 'r') {
+ } else if (strncmp(argv[1], "reset", strlen("reset") + 1) == 0) {
// Match tablet mode to the current HW orientation.
p.tablet_mode = TABLET_MODE_DEFAULT;
} else {