motion_sense: Check presence of {set,get}_{range,offset}

Prevents a null pointer dereference when the AP asks the EC
for nonexistent settings of a sensor.

BUG=chromium:761758
TEST="ectool motionsense offset ${ID of baro_bmp280 sensor}"
And see no null pointer dereference, but an invalid command error
BRANCH=master

Change-Id: I3050feaa3c9752abebc30237dac1befa4e5775cc
Signed-off-by: Alexandru M Stan <amstan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/850639
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
This commit is contained in:
Alexandru M Stan
2018-01-04 12:21:39 -08:00
committed by chrome-bot
parent 61b602d292
commit c870c87f2d

View File

@@ -1218,6 +1218,8 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
in->sensor_range.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
if (!sensor->drv->set_range || !sensor->drv->get_range)
return EC_RES_INVALID_COMMAND;
/* Set new range if the data arg has a value. */
if (in->sensor_range.data != EC_MOTION_SENSE_NO_VALUE) {
@@ -1239,6 +1241,8 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
in->sensor_offset.sensor_num);
if (sensor == NULL)
return EC_RES_INVALID_PARAM;
if (!sensor->drv->set_offset || !sensor->drv->get_offset)
return EC_RES_INVALID_COMMAND;
/* Set new range if the data arg has a value. */
if (in->sensor_offset.flags & MOTION_SENSE_SET_OFFSET) {