diff options
author | Caveh Jalali <caveh@chromium.org> | 2021-02-11 02:06:51 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-22 16:26:16 +0000 |
commit | 4cbade0256c7eb43d214595f83f236d37bfc630e (patch) | |
tree | ef9b694c28bebc5681d06fc998af736bfd642cd7 | |
parent | 803b4e99e191e5cdcbc1b135e7a498402cf9c511 (diff) | |
download | chrome-ec-4cbade0256c7eb43d214595f83f236d37bfc630e.tar.gz |
fan: fix fanset console command
This fixes how the fanset console command parses its arguments. The
original parsing would use the fan number as the RPM/duty cycle
percentage when two arguments were given on a single fan system. Two
arguments are now always treated as (fan number, RPM/duty cycle). On a
single fan system, the fan number may be omitted. Additional arguments
are rejected.
BRANCH=none
BUG=none
TEST=verified fanset console command controls fan
Change-Id: Ia6094354cbbc99c8bfcdb9dd9f227f75dc34507a
Signed-off-by: Caveh Jalali <caveh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2689498
Reviewed-by: Keith Short <keithshort@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r-- | common/fan.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/common/fan.c b/common/fan.c index 5c363ed124..636bec04f9 100644 --- a/common/fan.c +++ b/common/fan.c @@ -218,6 +218,7 @@ DECLARE_CONSOLE_COMMAND(faninfo, cc_faninfo, static int cc_fanset(int argc, char **argv) { + const char *rpm_str; int rpm; char *e; int fan = 0; @@ -228,21 +229,24 @@ static int cc_fanset(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) + rpm_str = argv[2]; + } else if (argc == 2) { + rpm_str = argv[1]; + } else { return EC_ERROR_PARAM_COUNT; + } - rpm = strtoi(argv[2], &e, 0); + rpm = strtoi(rpm_str, &e, 0); if (*e == '%') { /* Wait, that's a percentage */ ccprintf("Fan rpm given as %d%%\n", rpm); if (rpm < 0) @@ -270,7 +274,7 @@ static int cc_fanset(int argc, char **argv) return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(fanset, cc_fanset, - "{fan} (rpm | pct%)", + "[fan] (rpm | pct%)", "Set fan speed"); static int cc_fanduty(int argc, char **argv) |