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

lib/string_choices: Add some comments to make more clear for string choices helpers.

Add some comments to explain why we should use string_choices helpers.

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

authored by

Hongbo Li and committed by
Kees Cook
c121d5cc c2708ba9

+13
+13
include/linux/string_choices.h
··· 2 2 #ifndef _LINUX_STRING_CHOICES_H_ 3 3 #define _LINUX_STRING_CHOICES_H_ 4 4 5 + /* 6 + * Here provide a series of helpers in the str_$TRUE_$FALSE format (you can 7 + * also expand some helpers as needed), where $TRUE and $FALSE are their 8 + * corresponding literal strings. These helpers can be used in the printing 9 + * and also in other places where constant strings are required. Using these 10 + * helpers offers the following benefits: 11 + * 1) Reducing the hardcoding of strings, which makes the code more elegant 12 + * through these simple literal-meaning helpers. 13 + * 2) Unifying the output, which prevents the same string from being printed 14 + * in various forms, such as enable/disable, enabled/disabled, en/dis. 15 + * 3) Deduping by the linker, which results in a smaller binary file. 16 + */ 17 + 5 18 #include <linux/types.h> 6 19 7 20 static inline const char *str_enable_disable(bool v)