Skip to content

Conversation

@finikorg
Copy link
Contributor

@finikorg finikorg commented Feb 10, 2020

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) {
...

@zephyrbot
Copy link

zephyrbot commented Feb 10, 2020

All checks are passing now.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

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>
void (*handler)(struct device*, struct gpio_callback*,
u32_t), struct gpio_callback *callback, u32_t *val)
{
int ret;
Copy link
Contributor

@jfischer-no jfischer-no Feb 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not hurry to fix it. IMHO it would be better to change val and def_val type to int.

diff --git a/samples/sensor/fxos8700-hid/src/main.c b/samples/sensor/fxos8700-hid/src/main.c
index de587ae687..d35a24084a 100644
--- a/samples/sensor/fxos8700-hid/src/main.c
+++ b/samples/sensor/fxos8700-hid/src/main.c
@@ -60,7 +60,7 @@ LOG_MODULE_REGISTER(main);
 
 static const u8_t hid_report_desc[] = HID_MOUSE_REPORT_DESC(2);
 
-static u32_t def_val[4];
+static int def_val[4];
 static volatile u8_t status[4];
 static K_SEM_DEFINE(sem, 0, 1);        /* starts off "not available" */
 static struct gpio_callback callback[4];
@@ -77,7 +77,7 @@ static struct gpio_callback callback[4];
 static void left_button(struct device *gpio, struct gpio_callback *cb,
                        u32_t pins)
 {
-       u32_t cur_val;
+       int cur_val;
        u8_t state = status[MOUSE_BTN_REPORT_POS];
 
        cur_val = gpio_pin_get(gpio, PIN0);
@@ -97,7 +97,7 @@ static void left_button(struct device *gpio, struct gpio_callback *cb,
 static void right_button(struct device *gpio, struct gpio_callback *cb,
                         u32_t pins)
 {
-       u32_t cur_val;
+       int cur_val;
        u8_t state = status[MOUSE_BTN_REPORT_POS];
 
        cur_val = gpio_pin_get(gpio, PIN1);
@@ -116,7 +116,7 @@ static void right_button(struct device *gpio, struct gpio_callback *cb,
 
 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)
+                       u32_t), struct gpio_callback *callback, int *val)
 {
        if (!gpio) {
                LOG_ERR("Could not find PORT");

But there is more to fix, L:104 should probably be if (def_val[1] != cur_val) {. left_button() and right_button() return type is void and it is not possible to forward gpio_pin_get() error.

@galak galak added bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix labels Feb 10, 2020
@finikorg
Copy link
Contributor Author

I will reconsider the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Samples Samples bug The issue is a bug, or the PR is fixing a bug Coverity A Coverity detected issue or its fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants