Skip to content

Commit

Permalink
samples: fxos8700-hid: Fix possible underflow
Browse files Browse the repository at this point in the history
gpio_pin_get() returns a negative value in case of error and
callbacks_configure was assigning this value to an unsigned variable.

Fixes: zephyrproject-rtos#22643
Coverity CID :208206

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
  • Loading branch information
Flavio Ceolin committed Mar 23, 2020
1 parent f0a4cb0 commit 00abb35
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions samples/sensor/fxos8700-hid/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,22 @@ int callbacks_configure(struct device *gpio, u32_t pin, int flags,
void (*handler)(struct device*, struct gpio_callback*,
u32_t), struct gpio_callback *callback, u32_t *val)
{
int ret;

if (!gpio) {
LOG_ERR("Could not find PORT");
return -ENXIO;
}

gpio_pin_configure(gpio, pin,
GPIO_INPUT | GPIO_INT_DEBOUNCE | flags);
*val = gpio_pin_get(gpio, pin);
if (*val < 0) {
return *val;
ret = gpio_pin_get(gpio, pin);
if (ret < 0) {
return ret;
}

*val = (u32_t)ret;

gpio_init_callback(callback, handler, BIT(pin));
gpio_add_callback(gpio, callback);
gpio_pin_interrupt_configure(gpio, pin, GPIO_INT_EDGE_BOTH);
Expand Down

0 comments on commit 00abb35

Please sign in to comment.