diff mbox series

[1/2] lib/string_choices: Add str_up_down() helper

Message ID 20240725101841.574-1-michal.wajdeczko@intel.com (mailing list archive)
State Mainlined
Commit a98ae7f045b29de4f48b191d5aeb4e803183d759
Headers show
Series [1/2] lib/string_choices: Add str_up_down() helper | expand

Commit Message

Michal Wajdeczko July 25, 2024, 10:18 a.m. UTC
Add str_up_down() helper to return "up" or "down" string literal.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
---
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/string_choices.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Kees Cook Aug. 6, 2024, 4:40 a.m. UTC | #1
On Thu, 25 Jul 2024 12:18:40 +0200, Michal Wajdeczko wrote:
> Add str_up_down() helper to return "up" or "down" string literal.
> 
> 

Applied to for-next/hardening, thanks!

[1/2] lib/string_choices: Add str_up_down() helper
      https://git.kernel.org/kees/c/3ff37dbb1ae9
[2/2] coccinelle: Add rules to find str_up_down() replacements
      https://git.kernel.org/kees/c/d518b5f7f2d5

Take care,
Andy Shevchenko Aug. 8, 2024, 9:10 a.m. UTC | #2
On Thu, Jul 25, 2024 at 12:18:40PM +0200, Michal Wajdeczko wrote:
> Add str_up_down() helper to return "up" or "down" string literal.

...

> +static inline const char *str_up_down(bool v)
> +{
> +	return v ? "up" : "down";
> +}

Can you please add a respective macro for str_down_up() as it's done for (some)
others?

P.S. Yes, I see these two has been applied, so perhaps followup?
Kees Cook Aug. 8, 2024, 5:57 p.m. UTC | #3
On Thu, Aug 08, 2024 at 12:10:12PM +0300, Andy Shevchenko wrote:
> On Thu, Jul 25, 2024 at 12:18:40PM +0200, Michal Wajdeczko wrote:
> > Add str_up_down() helper to return "up" or "down" string literal.
> 
> ...
> 
> > +static inline const char *str_up_down(bool v)
> > +{
> > +	return v ? "up" : "down";
> > +}
> 
> Can you please add a respective macro for str_down_up() as it's done for (some)
> others?

e.g.

#define str_down_up(v)	str_up_down(!(v))
diff mbox series

Patch

diff --git a/include/linux/string_choices.h b/include/linux/string_choices.h
index d9ebe20229f8..bcde3c9cff81 100644
--- a/include/linux/string_choices.h
+++ b/include/linux/string_choices.h
@@ -42,6 +42,11 @@  static inline const char *str_yes_no(bool v)
 	return v ? "yes" : "no";
 }
 
+static inline const char *str_up_down(bool v)
+{
+	return v ? "up" : "down";
+}
+
 /**
  * str_plural - Return the simple pluralization based on English counts
  * @num: Number used for deciding pluralization