Fix svace issue in gpio interface 78/128078/3
authorHyeongsik Min <hyeongsik.min@samsung.com>
Fri, 5 May 2017 01:57:42 +0000 (10:57 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Mon, 8 May 2017 00:40:19 +0000 (00:40 +0000)
- DEREF_AFTER_NULL.EX in peripheral_bus_gpio_open.
  Null pointer is dereferenced after peripherl_bus_gpio_data_new returns null.
- UNREACHABLE_CODE in peripheral_bus_gpio_register_irq().
  gpio->io_id will be zero if it failed and cannot be less than zero.

Change-Id: Ic780ba4362ef13273c3cb2f367ad13276ea429c5
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
src/daemon/peripheral_bus_gpio.c

index dbf9a69..b49a202 100644 (file)
@@ -129,7 +129,7 @@ int peripheral_bus_gpio_open(gint pin, gint *edge, gint *direction, gpointer use
        return PERIPHERAL_ERROR_NONE;
 
 err:
-       gpio_close(gpio->pin);
+       gpio_close(pin);
 
 open_err:
        return ret;
@@ -176,9 +176,8 @@ int peripheral_bus_gpio_get_direction(gint pin, gint *direction, gpointer user_d
        }
 
        if (*direction == GPIO_DIRECTION_OUT) {
-               if ((ret = gpio_read(pin, &value)) < 0) {
+               if ((ret = gpio_read(pin, &value)) < 0)
                        return ret;
-               }
                /* Update direction state with the current value */
                *direction = GPIO_DIRECTION_OUT + value;
                gpio->direction = *direction;
@@ -353,7 +352,7 @@ int peripheral_bus_gpio_register_irq(gint pin, gpointer user_data)
        g_free(strval);
 
        gpio->io_id = g_io_add_watch(gpio->io, G_IO_PRI, peripheral_bus_gpio_cb, gpio);
-       if (gpio->io_id < 0) {
+       if (gpio->io_id == 0) {
                _E("g_io_add_watch error (%d)", gpio->io);
                goto err_io_add_watch;
        }