]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpiolib: Deduplicate gpiod_direction_input_nonotify() call
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 4 Feb 2025 17:56:46 +0000 (19:56 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 12 Feb 2025 09:56:42 +0000 (10:56 +0100)
Deduplicate gpiod_direction_input_nonotify() call in
gpiod_direction_output_nonotify() when emulating open-drain
or open-source behaviour. It also aligns the error check
approaches in set_output_value and set_output_flag labels.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250204175646.150577-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib.c

index 618fe2eebf3809500b3d4191a273bfa2ca8ae514..f261f7893f85194467588e19e672ca03a6b5fd6d 100644 (file)
@@ -2873,19 +2873,15 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value)
                if (!ret)
                        goto set_output_value;
                /* Emulate open drain by not actively driving the line high */
-               if (value) {
-                       ret = gpiod_direction_input_nonotify(desc);
+               if (value)
                        goto set_output_flag;
-               }
        } else if (test_bit(FLAG_OPEN_SOURCE, &flags)) {
                ret = gpio_set_config(desc, PIN_CONFIG_DRIVE_OPEN_SOURCE);
                if (!ret)
                        goto set_output_value;
                /* Emulate open source by not actively driving the line low */
-               if (!value) {
-                       ret = gpiod_direction_input_nonotify(desc);
+               if (!value)
                        goto set_output_flag;
-               }
        } else {
                gpio_set_config(desc, PIN_CONFIG_DRIVE_PUSH_PULL);
        }
@@ -2897,15 +2893,17 @@ set_output_value:
        return gpiod_direction_output_raw_commit(desc, value);
 
 set_output_flag:
+       ret = gpiod_direction_input_nonotify(desc);
+       if (ret)
+               return ret;
        /*
         * When emulating open-source or open-drain functionalities by not
         * actively driving the line (setting mode to input) we still need to
         * set the IS_OUT flag or otherwise we won't be able to set the line
         * value anymore.
         */
-       if (ret == 0)
-               set_bit(FLAG_IS_OUT, &desc->flags);
-       return ret;
+       set_bit(FLAG_IS_OUT, &desc->flags);
+       return 0;
 }
 
 /**