diff options
author | li feng <li1.feng@intel.com> | 2016-12-13 17:17:51 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-12-14 02:53:50 -0800 |
commit | e95ce7682eeacc543c3731d4af1bd726702555e7 (patch) | |
tree | c0e8cd9d3421671493049447a9464580b073ae1d /driver/baro_bmp280.c | |
parent | c7ea2c9125b9d6be9a52c6358e2892ff67e404c7 (diff) | |
download | chrome-ec-e95ce7682eeacc543c3731d4af1bd726702555e7.tar.gz |
bmp280: handle divided by 0 case
In bmp280 driver bmp280_set_data_rate(), parameter rate may be 0
On reef ISH enabled board, this caused unhandled exception.
BUG=None
BRANCH=None
TEST=On reef ISH enabled board, verified barometer bmp280
sensor initialized succefully.
Change-Id: I7cdae8efbc618fca1551fd9fe809cb69ba0cee34
Signed-off-by: li feng <li1.feng@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/419744
Commit-Ready: Li1 Feng <li1.feng@intel.com>
Tested-by: Li1 Feng <li1.feng@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'driver/baro_bmp280.c')
-rw-r--r-- | driver/baro_bmp280.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/driver/baro_bmp280.c b/driver/baro_bmp280.c index 3a3f3e3b6d..d755b278fd 100644 --- a/driver/baro_bmp280.c +++ b/driver/baro_bmp280.c @@ -352,13 +352,14 @@ static int bmp280_set_data_rate(const struct motion_sensor_t *s, int rate, { struct bmp280_drv_data_t *data = BMP280_GET_DATA(s); int durn, i, ret; - int period = 1000000 / rate; /* Period in ms */ + int period; /* Period in ms */ if (rate == 0) { /* Set to sleep mode */ data->rate = 0; return bmp280_set_power_mode(s, BMP280_SLEEP_MODE); - } + } else + period = 1000000 / rate; /* reset power mode, waking from sleep */ if (!data->rate) { |