Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/string_choices: Introduce several opposite string choice helpers

Similar to the exists helper: str_enable_disable/
str_enabled_disabled/str_on_off/str_yes_no helpers, we can
add the opposite helpers. That's str_disable_enable,
str_disabled_enabled, str_off_on and str_no_yes.

There are more than 10 cases currently (expect
str_disable_enable now has 3 use cases) exist in the code
can be replaced with these helper.

Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Acked-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20240905092540.2962122-2-lihongbo22@huawei.com
Signed-off-by: Kees Cook <kees@kernel.org>

authored by

Hongbo Li and committed by
Kees Cook
c2708ba9 6ff4cd11

+4
+4
include/linux/string_choices.h
··· 8 8 { 9 9 return v ? "enable" : "disable"; 10 10 } 11 + #define str_disable_enable(v) str_enable_disable(!(v)) 11 12 12 13 static inline const char *str_enabled_disabled(bool v) 13 14 { 14 15 return v ? "enabled" : "disabled"; 15 16 } 17 + #define str_disabled_enabled(v) str_enabled_disabled(!(v)) 16 18 17 19 static inline const char *str_hi_lo(bool v) 18 20 { ··· 38 36 { 39 37 return v ? "on" : "off"; 40 38 } 39 + #define str_off_on(v) str_on_off(!(v)) 41 40 42 41 static inline const char *str_yes_no(bool v) 43 42 { 44 43 return v ? "yes" : "no"; 45 44 } 45 + #define str_no_yes(v) str_yes_no(!(v)) 46 46 47 47 static inline const char *str_up_down(bool v) 48 48 {