Skip to content

Commit a5c3db2

Browse files
committed
samples: fxos8700-hid: Fix using gpio_pin_get()
Fix using unsigned with gpio_pin_get(). Closes Coverity issue: ... 128 *val = gpio_pin_get(gpio, pin); >>> CID 208206: Control flow issues (NO_EFFECT) >>> This less-than-zero comparison of an unsigned value >>> is never true. "*val < 0U". 129 if (*val < 0) { ... Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
1 parent ad9883a commit a5c3db2

File tree

1 file changed

+10
-3
lines changed
  • samples/sensor/fxos8700-hid/src

1 file changed

+10
-3
lines changed

samples/sensor/fxos8700-hid/src/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,25 @@ int callbacks_configure(struct device *gpio, u32_t pin, int flags,
118118
void (*handler)(struct device*, struct gpio_callback*,
119119
u32_t), struct gpio_callback *callback, u32_t *val)
120120
{
121+
int ret;
122+
121123
if (!gpio) {
122124
LOG_ERR("Could not find PORT");
123125
return -ENXIO;
124126
}
125127

126128
gpio_pin_configure(gpio, pin,
127129
GPIO_INPUT | GPIO_INT_DEBOUNCE | flags);
128-
*val = gpio_pin_get(gpio, pin);
129-
if (*val < 0) {
130-
return *val;
130+
131+
ret = gpio_pin_get(gpio, pin);
132+
if (ret < 0) {
133+
LOG_ERR("Failed to get the state of pin %u, error: %d",
134+
pin, ret);
135+
return ret;
131136
}
132137

138+
*val = (u8_t)ret;
139+
133140
gpio_init_callback(callback, handler, BIT(pin));
134141
gpio_add_callback(gpio, callback);
135142
gpio_pin_interrupt_configure(gpio, pin, GPIO_INT_EDGE_BOTH);

0 commit comments

Comments
 (0)