gpio: don't allow direction change if there is poll/callback set 56/261656/5
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 22 Jul 2021 06:53:12 +0000 (08:53 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 11 Aug 2021 10:14:00 +0000 (12:14 +0200)
This was missing. The function that sets the callback
(peripheral_gpio_set_interrupted_cb())
exits with error if the direction is not "in". Therefore,
the callback makes sense only when the direction is "in".
Therefore, we don't want to allow changing the direction if there
is a callback set.

Change-Id: Ib21746ee4c32706a4114a76fbd0f6bd80bc9b787

src/peripheral_gpio.c

index 15cf494..b36f384 100644 (file)
@@ -344,6 +344,9 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
        RETV_IF(gpio->direction == direction, PERIPHERAL_ERROR_NONE);
        RETV_IF(gpio->edge != PERIPHERAL_GPIO_EDGE_NONE, PERIPHERAL_ERROR_IO_ERROR);
 
+       RETVM_IF(gpio->cb_info.status != GPIO_INTERRUPTED_CALLBACK_UNSET, PERIPHERAL_ERROR_IO_ERROR,
+                       "Can't change direction to OUT while 'interrupted_cb' is set");
+
        static const predefined_type_s types[3] = {
                {"in",   2},
                {"high", 4},