samples: fxos8700-hid: Fix possible underflow

gpio_pin_get() returns a negative value in case of error and
callbacks_configure was assigning this value to an unsigned variable.

Fixes: #22643
Coverity CID :208206

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2020-03-23 13:40:50 -07:00 committed by Ioannis Glaropoulos
commit a7b327310d

View file

@ -118,6 +118,8 @@ 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;
@ -125,11 +127,13 @@ int callbacks_configure(struct device *gpio, u32_t pin, int flags,
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);