# \[PATCH v1 1/1\] gpiolib: Make use of assign\_bit() API (part 2)

- Subsystems: GPIO SUBSYSTEM, THE REST
- Maintainers: Linus Walleij, Bartosz Golaszewski, Linus Torvalds
- List: linux-gpio
- 3 messages, 3 authors
- Page: https://ratatoskr.run/linux-gpio/2021/05/1381721/t

## \[PATCH v1 1/1\] gpiolib: Make use of assign\_bit() API (part 2)

- From: Andy Shevchenko \<andriy.shevchenko@linux.intel.com\>
- Date: 2021-05-18 08:46:06 
- Message: https://ratatoskr.run/linux-gpio/2021/05/1381721.md

```text
We have for some time the assign_bit() API to replace open coded

	if (foo)
		set_bit(n, bar);
	else
		clear_bit(n, bar);

Use this API in GPIO library code.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib-sysfs.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 41b3b782bf3f..7c5afd999210 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -312,10 +312,7 @@ static int gpio_sysfs_set_active_low(struct device *dev, int value)
 	if (!!test_bit(FLAG_ACTIVE_LOW, &desc->flags) == !!value)
 		return 0;
 
-	if (value)
-		set_bit(FLAG_ACTIVE_LOW, &desc->flags);
-	else
-		clear_bit(FLAG_ACTIVE_LOW, &desc->flags);
+	assign_bit(FLAG_ACTIVE_LOW, &desc->flags, value);
 
 	/* reconfigure poll(2) support if enabled on one edge only */
 	if (flags == GPIO_IRQF_TRIGGER_FALLING ||
-- 
2.30.2

```

## Re: \[PATCH v1 1/1\] gpiolib: Make use of assign\_bit() API (part 2)

- From: Linus Walleij \<hidden\>
- Date: 2021-05-18 23:39:38 
- Message: https://ratatoskr.run/linux-gpio/2021/05/1382700.md

```text
On Tue, May 18, 2021 at 10:46 AM Andy Shevchenko
[ref] wrote:

> We have for some time the assign_bit() API to replace open coded
>
>         if (foo)
>                 set_bit(n, bar);
>         else
>                 clear_bit(n, bar);
>
> Use this API in GPIO library code.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Now I understand what assign_bit() is for...
Reviewed-by: Linus Walleij <redacted>

Yours,
Linus Walleij
```

## Re: \[PATCH v1 1/1\] gpiolib: Make use of assign\_bit() API (part 2)

- From: Bartosz Golaszewski \<hidden\>
- Date: 2021-05-21 12:56:14 
- Message: https://ratatoskr.run/linux-gpio/2021/05/1387485.md

```text
On Tue, May 18, 2021 at 10:46 AM Andy Shevchenko
[ref] wrote:
>
> We have for some time the assign_bit() API to replace open coded
>
>         if (foo)
>                 set_bit(n, bar);
>         else
>                 clear_bit(n, bar);
>
> Use this API in GPIO library code.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib-sysfs.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
> index 41b3b782bf3f..7c5afd999210 100644
> --- a/drivers/gpio/gpiolib-sysfs.c
> +++ b/drivers/gpio/gpiolib-sysfs.c
> @@ -312,10 +312,7 @@ static int gpio_sysfs_set_active_low(struct device *dev, int value)
>         if (!!test_bit(FLAG_ACTIVE_LOW, &desc->flags) == !!value)
>                 return 0;
>
> -       if (value)
> -               set_bit(FLAG_ACTIVE_LOW, &desc->flags);
> -       else
> -               clear_bit(FLAG_ACTIVE_LOW, &desc->flags);
> +       assign_bit(FLAG_ACTIVE_LOW, &desc->flags, value);
>
>         /* reconfigure poll(2) support if enabled on one edge only */
>         if (flags == GPIO_IRQF_TRIGGER_FALLING ||
> --
> 2.30.2
>

Patch applied, thanks!

Bartosz
```
