[PATCH v1 05/16] gpiolib: Utilize helpers from string_choices.h

From: Andy Shevchenko
Date: Mon Mar 06 2023 - 14:56:06 EST


There are a few helpers available to convert a boolean variable
to the dedicated string literals depending on the application.
Use them in the driver.

While at, utilize specifier field for padding the strings where
it's required.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
---
drivers/gpio/gpiolib-sysfs.c | 3 ++-
drivers/gpio/gpiolib.c | 13 ++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index c1cbf71329f0..54dc53b74dc4 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -13,6 +13,7 @@
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
+#include <linux/string_choices.h>
#include <linux/sysfs.h>
#include <linux/types.h>

@@ -82,7 +83,7 @@ static ssize_t direction_show(struct device *dev,

mutex_unlock(&data->mutex);

- return sysfs_emit(buf, "%s\n", value ? "out" : "in");
+ return sysfs_emit(buf, "%s\n", str_out_in(value));
}

static ssize_t direction_store(struct device *dev,
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 700195a1faae..b554ad435245 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -20,6 +20,7 @@
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
+#include <linux/string_choices.h>

#include <linux/gpio.h>
#include <linux/gpio/driver.h>
@@ -4198,6 +4199,8 @@ EXPORT_SYMBOL_GPL(gpiod_get_index_optional);
int gpiod_hog(struct gpio_desc *desc, const char *name,
unsigned long lflags, enum gpiod_flags dflags)
{
+ bool out = dflags & GPIOD_FLAGS_BIT_DIR_OUT;
+ bool hi = dflags & GPIOD_FLAGS_BIT_DIR_VAL;
struct gpio_chip *gc;
struct gpio_desc *local_desc;
int hwnum;
@@ -4218,10 +4221,7 @@ int gpiod_hog(struct gpio_desc *desc, const char *name,
/* Mark GPIO as hogged so it can be identified and removed later */
set_bit(FLAG_IS_HOGGED, &desc->flags);

- gpiod_info(desc, "hogged as %s%s\n",
- (dflags & GPIOD_FLAGS_BIT_DIR_OUT) ? "output" : "input",
- (dflags & GPIOD_FLAGS_BIT_DIR_OUT) ?
- (dflags & GPIOD_FLAGS_BIT_DIR_VAL) ? "/high" : "/low" : "");
+ gpiod_info(desc, "hogged as %s/%s\n", str_output_input(out), out ? str_high_low(hi) : "?");

return 0;
}
@@ -4509,10 +4509,9 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)
value = gpio_chip_get_value(gc, desc);
is_irq = test_bit(FLAG_USED_AS_IRQ, &desc->flags);
active_low = test_bit(FLAG_ACTIVE_LOW, &desc->flags);
- seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %s %s %s%s\n",
+ seq_printf(s, " gpio-%-3d (%-20.20s|%-20.20s) %-3.3s %-2.2s %s%s\n",
gpio, desc->name ?: "", desc->label,
- is_out ? "out" : "in ",
- value >= 0 ? (value ? "hi" : "lo") : "? ",
+ str_out_in(is_out), value < 0 ? "?" : str_hi_lo(value),
is_irq ? "IRQ " : "",
active_low ? "ACTIVE LOW" : "");
} else if (desc->name) {
--
2.39.1