* [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
@ 2024-10-31 9:21 Andy Shevchenko
2024-10-31 19:14 ` Bartosz Golaszewski
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2024-10-31 9:21 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko
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>
---
drivers/gpio/gpiolib.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5666c462248c..9376dd270344 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2877,19 +2877,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);
}
@@ -2901,15 +2897,17 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int 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;
}
/**
--
2.43.0.rc1.1336.g36b5255a03ac
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
2024-10-31 9:21 [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call Andy Shevchenko
@ 2024-10-31 19:14 ` Bartosz Golaszewski
2024-11-01 8:15 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2024-10-31 19:14 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij
On Thu, Oct 31, 2024 at 10:22 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> 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>
> ---
> drivers/gpio/gpiolib.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 5666c462248c..9376dd270344 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2877,19 +2877,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);
> }
> @@ -2901,15 +2897,17 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int value)
> return gpiod_direction_output_raw_commit(desc, value);
>
> set_output_flag:
Ok, I'll take it but please change this label to "emulate_output" or
something similar that's more indicative on what the goal here is.
Bart
> + 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;
> }
>
> /**
> --
> 2.43.0.rc1.1336.g36b5255a03ac
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
2024-10-31 19:14 ` Bartosz Golaszewski
@ 2024-11-01 8:15 ` Andy Shevchenko
2024-11-01 12:56 ` Bartosz Golaszewski
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2024-11-01 8:15 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij
On Thu, Oct 31, 2024 at 08:14:56PM +0100, Bartosz Golaszewski wrote:
> On Thu, Oct 31, 2024 at 10:22 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
...
> > set_output_flag:
>
> Ok, I'll take it but please change this label to "emulate_output" or
> something similar that's more indicative on what the goal here is.
It's out of scope of this patch.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
2024-11-01 8:15 ` Andy Shevchenko
@ 2024-11-01 12:56 ` Bartosz Golaszewski
0 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2024-11-01 12:56 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Linus Walleij
On Fri, Nov 1, 2024 at 9:15 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Oct 31, 2024 at 08:14:56PM +0100, Bartosz Golaszewski wrote:
> > On Thu, Oct 31, 2024 at 10:22 AM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
>
> ...
>
> > > set_output_flag:
> >
> > Ok, I'll take it but please change this label to "emulate_output" or
> > something similar that's more indicative on what the goal here is.
>
> It's out of scope of this patch.
>
It is not though. You are already touching this code, make it even better.
Just say in the commit message: "while at it, rename the label to ..."
Bartosz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
@ 2025-02-04 17:56 Andy Shevchenko
2025-02-12 9:57 ` Bartosz Golaszewski
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2025-02-04 17:56 UTC (permalink / raw)
To: Bartosz Golaszewski, linux-gpio, linux-kernel
Cc: Linus Walleij, Bartosz Golaszewski, Andy Shevchenko
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>
---
drivers/gpio/gpiolib.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index efad5e2f9a9e..bf0b67f41e2e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2872,19 +2872,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);
}
@@ -2896,15 +2892,17 @@ int gpiod_direction_output_nonotify(struct gpio_desc *desc, int 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;
}
/**
--
2.43.0.rc1.1336.g36b5255a03ac
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
2025-02-04 17:56 Andy Shevchenko
@ 2025-02-12 9:57 ` Bartosz Golaszewski
0 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2025-02-12 9:57 UTC (permalink / raw)
To: linux-gpio, linux-kernel, Andy Shevchenko
Cc: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Tue, 04 Feb 2025 19:56:46 +0200, Andy Shevchenko wrote:
> 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.
>
>
Meh, it's a bit of churn IMO but whatever.
[1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call
commit: 8beaf839018096cd20e427e68645b4fbecdcb1f0
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-02-12 9:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-31 9:21 [PATCH v1 1/1] gpiolib: Deduplicate gpiod_direction_input_nonotify() call Andy Shevchenko
2024-10-31 19:14 ` Bartosz Golaszewski
2024-11-01 8:15 ` Andy Shevchenko
2024-11-01 12:56 ` Bartosz Golaszewski
-- strict thread matches above, loose matches on Subject: below --
2025-02-04 17:56 Andy Shevchenko
2025-02-12 9:57 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).