[PATCH] lib/string_choices: add str_pass_fail() and str_passed_failed()

Dmitry Antipov posted 1 patch 1 month, 1 week ago
include/linux/string_choices.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
[PATCH] lib/string_choices: add str_pass_fail() and str_passed_failed()
Posted by Dmitry Antipov 1 month, 1 week ago
Looking over a few kernel subsystems I'm currently working on,
I suppose that 'str_pass_fail()' and 'str_passed_failed()' with
their opposite counterpart macros may be useful as well.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 include/linux/string_choices.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/string_choices.h b/include/linux/string_choices.h
index ee84087d4b26..901ab80bfdd7 100644
--- a/include/linux/string_choices.h
+++ b/include/linux/string_choices.h
@@ -59,6 +59,20 @@ static inline const char *str_on_off(bool v)
 }
 #define str_off_on(v)		str_on_off(!(v))
 
+static inline const char *str_pass_fail(bool v)
+{
+	return v ? "pass" : "fail";
+}
+
+#define str_fail_pass(v)		str_pass_fail(!(v))
+
+static inline const char *str_passed_failed(bool v)
+{
+	return v ? "passed" : "failed";
+}
+
+#define str_failed_passed(v)		str_passed_failed(!(v))
+
 static inline const char *str_read_write(bool v)
 {
 	return v ? "read" : "write";
-- 
2.55.0
Re: [PATCH] lib/string_choices: add str_pass_fail() and str_passed_failed()
Posted by Andy Shevchenko 1 month, 1 week ago
On Wed, Aug 19, 2026 at 5:35 PM Dmitry Antipov <dmantipov@yandex.ru> wrote:
>
> Looking over a few kernel subsystems I'm currently working on,
> I suppose that 'str_pass_fail()' and 'str_passed_failed()' with
> their opposite counterpart macros may be useful as well.

But we don't take this without users. So, at least convert one
existing case per the API (so, +2 patches).

...

>  }
>  #define str_off_on(v)          str_on_off(!(v))

^^^

> +static inline const char *str_pass_fail(bool v)
> +{
> +       return v ? "pass" : "fail";
> +}
> +
> +#define str_fail_pass(v)               str_pass_fail(!(v))

As you may easily see, the style is to avoid the blank line in each of
the group of helpers (static inline + #define are coupled).

> +
> +static inline const char *str_passed_failed(bool v)
> +{
> +       return v ? "passed" : "failed";
> +}
> +
> +#define str_failed_passed(v)           str_passed_failed(!(v))

Ditto.

-- 
With Best Regards,
Andy Shevchenko