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:
parent
2f323e65b2
commit
a7b327310d
1 changed files with 7 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue