summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-02-11 01:39:21 -0800
committerCommit Bot <commit-bot@chromium.org>2021-02-22 16:26:13 +0000
commit803b4e99e191e5cdcbc1b135e7a498402cf9c511 (patch)
tree7ee892dafd736b258948e16112c03fcf2191d634
parent48fd15147167eab478b6c99e454d0cb3162d4bb5 (diff)
downloadchrome-ec-803b4e99e191e5cdcbc1b135e7a498402cf9c511.tar.gz
fan: fix fanduty console command
This fixes how the fanduty console command parses its arguments. The original parsing would use the fan number as the duty cycle percentage when two arguments were given on a single fan system. Two arguments are now always treated as (fan number, duty cycle). On a single fan system, the fan number may be omitted. Additional arguments are rejected. BRANCH=none BUG=none TEST=verified fanduty console command controls fan Change-Id: Ib7f0141e698d80957a6ac7b770602dcf049aafbc Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2689497 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--common/fan.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/common/fan.c b/common/fan.c
index 398a149268..5c363ed124 100644
--- a/common/fan.c
+++ b/common/fan.c
@@ -275,6 +275,7 @@ DECLARE_CONSOLE_COMMAND(fanset, cc_fanset,
static int cc_fanduty(int argc, char **argv)
{
+ const char *percent_str;
int percent = 0;
char *e;
int fan = 0;
@@ -285,21 +286,24 @@ static int cc_fanduty(int argc, char **argv)
}
if (fan_count > 1) {
- if (argc < 2) {
+ if (argc < 3) {
ccprintf("fan number is required as the first arg\n");
return EC_ERROR_PARAM_COUNT;
}
+ }
+
+ if (argc == 3) {
fan = strtoi(argv[1], &e, 0);
if (*e || fan >= fan_count)
return EC_ERROR_PARAM1;
- argc--;
- argv++;
- }
-
- if (argc < 2)
+ percent_str = argv[2];
+ } else if (argc == 2) {
+ percent_str = argv[1];
+ } else {
return EC_ERROR_PARAM_COUNT;
+ }
- percent = strtoi(argv[1], &e, 0);
+ percent = strtoi(percent_str, &e, 0);
if (*e)
return EC_ERROR_PARAM1;
@@ -309,7 +313,7 @@ static int cc_fanduty(int argc, char **argv)
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(fanduty, cc_fanduty,
- "{fan} percent",
+ "[fan] percent",
"Set fan duty cycle");
/*****************************************************************************/