From bc021ce9c7007d0848d338df84f46aadfb54fa2f Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Mon, 21 May 2012 16:34:44 +0800 Subject: [PATCH] Fix a bug that 'ectool thermalget' silently fails 'ectool thermalget' should return error if sensor ID or threshold ID is out of range. This CL fixes a bug that error codes mismatch. BUG=chrome-os-partner:9840 TEST='ectool thermalget 0 10' gives error. Change-Id: I74d0c66044cd31743c4fac0a8dc0431db6259e71 --- common/thermal.c | 10 +++++++--- common/thermal_commands.c | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/thermal.c b/common/thermal.c index 9aa3e5d066..72709cd8ec 100644 --- a/common/thermal.c +++ b/common/thermal.c @@ -57,11 +57,13 @@ static int fan_ctrl_on = 1; int thermal_set_threshold(enum temp_sensor_type type, int threshold_id, int value) { + if (type < 0 || type >= TEMP_SENSOR_TYPE_COUNT) + return -1; if (threshold_id < 0 || threshold_id >= THRESHOLD_COUNT + THERMAL_FAN_STEPS) - return EC_ERROR_INVAL; + return -1; if (value < 0) - return EC_ERROR_INVAL; + return -1; thermal_config[type].thresholds[threshold_id] = value; @@ -71,9 +73,11 @@ int thermal_set_threshold(enum temp_sensor_type type, int threshold_id, int valu int thermal_get_threshold(enum temp_sensor_type type, int threshold_id) { + if (type < 0 || type >= TEMP_SENSOR_TYPE_COUNT) + return -1; if (threshold_id < 0 || threshold_id >= THRESHOLD_COUNT + THERMAL_FAN_STEPS) - return EC_ERROR_INVAL; + return -1; return thermal_config[type].thresholds[threshold_id]; } diff --git a/common/thermal_commands.c b/common/thermal_commands.c index aedbf63f80..f4bb8d6497 100644 --- a/common/thermal_commands.c +++ b/common/thermal_commands.c @@ -28,10 +28,11 @@ int thermal_command_get_threshold(uint8_t *data, int *resp_size) (struct ec_params_thermal_get_threshold *)data; struct ec_response_thermal_get_threshold *r = (struct ec_response_thermal_get_threshold *)data; + int value = thermal_get_threshold(p->sensor_type, p->threshold_id); - r->value = thermal_get_threshold(p->sensor_type, p->threshold_id); - if (r->value == -1) + if (value == -1) return EC_RES_ERROR; + r->value = value; *resp_size = sizeof(struct ec_response_thermal_get_threshold); return EC_RES_SUCCESS;