<br><br>On Wednesday, January 19, 2022, Lucas De Marchi <<a href="mailto:lucas.demarchi@intel.com">lucas.demarchi@intel.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There are a few implementations of yesno() in the tree. Consolidate them<br>
in include/linux/string_helpers.<wbr>h. Quite a few users of open coded<br>
yesno() could later be converted to the new function:<br>
<br>
$ git grep '?\s*"yes"\s*' | wc -l<br>
286<br>
$ git grep '?\s*"no"\s*' | wc -l<br>
20<br>
<br>
The inlined function should keep the const strings local to each<br>
compilation unit, the same way it's now, thus not changing the current<br>
behavior.<br>
<br>
Signed-off-by: Lucas De Marchi <<a href="mailto:lucas.demarchi@intel.com">lucas.demarchi@intel.com</a>><br>
---<br>
.../amd/display/amdgpu_dm/<wbr>amdgpu_dm_debugfs.c | 6 +-----<br>
drivers/gpu/drm/i915/i915_<wbr>utils.h | 5 -----<br>
.../net/ethernet/chelsio/<wbr>cxgb4/cxgb4_debugfs.c | 11 -----------<br>
include/linux/string_helpers.h | 2 ++<br>
security/tomoyo/audit.c | 2 +-<br>
security/tomoyo/common.c | 18 ++++--------------<br>
security/tomoyo/common.h | 1 -<br>
7 files changed, 8 insertions(+), 37 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/display/<wbr>amdgpu_dm/amdgpu_dm_debugfs.c b/drivers/gpu/drm/amd/display/<wbr>amdgpu_dm/amdgpu_dm_debugfs.c<br>
index 9d43ecb1f692..b59760f91bf6 100644<br>
--- a/drivers/gpu/drm/amd/display/<wbr>amdgpu_dm/amdgpu_dm_debugfs.c<br>
+++ b/drivers/gpu/drm/amd/display/<wbr>amdgpu_dm/amdgpu_dm_debugfs.c<br>
@@ -23,6 +23,7 @@<br>
*<br>
*/<br>
<br>
+#include <linux/string_helpers.h><br>
#include <linux/uaccess.h><br>
<br>
#include "dc.h"<br>
@@ -49,11 +50,6 @@ struct dmub_debugfs_trace_entry {<br>
uint32_t param1;<br>
};<br>
<br>
-static inline const char *yesno(bool v)<br>
-{<br>
- return v ? "yes" : "no";<br>
-}<br>
-<br>
/* parse_write_buffer_into_params - Helper function to parse debugfs write buffer into an array<br>
*<br>
* Function takes in attributes passed to debugfs write entry<br>
diff --git a/drivers/gpu/drm/i915/i915_<wbr>utils.h b/drivers/gpu/drm/i915/i915_<wbr>utils.h<br>
index 7a5925072466..2a8781cc648b 100644<br>
--- a/drivers/gpu/drm/i915/i915_<wbr>utils.h<br>
+++ b/drivers/gpu/drm/i915/i915_<wbr>utils.h<br>
@@ -414,11 +414,6 @@ wait_remaining_ms_from_<wbr>jiffies(unsigned long timestamp_jiffies, int to_wait_ms)<br>
#define MBps(x) KBps(1000 * (x))<br>
#define GBps(x) ((u64)1000 * MBps((x)))<br>
<br>
-static inline const char *yesno(bool v)<br>
-{<br>
- return v ? "yes" : "no";<br>
-}<br>
-<br>
static inline const char *onoff(bool v)<br>
{<br>
return v ? "on" : "off";<br>
diff --git a/drivers/net/ethernet/<wbr>chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/<wbr>chelsio/cxgb4/cxgb4_debugfs.c<br>
index 7d49fd4edc9e..61a04d7abc1f 100644<br>
--- a/drivers/net/ethernet/<wbr>chelsio/cxgb4/cxgb4_debugfs.c<br>
+++ b/drivers/net/ethernet/<wbr>chelsio/cxgb4/cxgb4_debugfs.c<br>
@@ -2015,17 +2015,6 @@ static const struct file_operations rss_debugfs_fops = {<br>
/* RSS Configuration.<br>
*/<br>
<br>
-/* Small utility function to return the strings "yes" or "no" if the supplied<br>
- * argument is non-zero.<br>
- */<br>
-static const char *yesno(int x)<br>
-{<br>
- static const char *yes = "yes";<br>
- static const char *no = "no";<br>
-<br>
- return x ? yes : no;<br>
-}<br>
-<br>
static int rss_config_show(struct seq_file *seq, void *v)<br>
{<br>
struct adapter *adapter = seq->private;<br>
diff --git a/include/linux/string_<wbr>helpers.h b/include/linux/string_<wbr>helpers.h<br>
index 4ba39e1403b2..e980dec05d31 100644<br>
--- a/include/linux/string_<wbr>helpers.h<br>
+++ b/include/linux/string_<wbr>helpers.h<br>
@@ -102,4 +102,6 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp);<br>
<br>
void kfree_strarray(char **array, size_t n);<br>
<br>
+static inline const char *yesno(bool v) { return v ? "yes" : "no"; }</blockquote><div><br></div><div><br></div><div>Perhaps keep it on 4 lines? Yes, yes/no is short, but if we add others (enable/disable) it will not be possible to keep on one line. And hence style will be broken among similar functions.</div><div><br></div><div><br></div><div>Also it needs to be rebased and resend after -rc1, I expect conflict here.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
#endif<br>
diff --git a/security/tomoyo/audit.c b/security/tomoyo/audit.c<br>
index d79bf07e16be..1458e27361e8 100644<br>
--- a/security/tomoyo/audit.c<br>
+++ b/security/tomoyo/audit.c<br>
@@ -166,7 +166,7 @@ static char *tomoyo_print_header(struct tomoyo_request_info *r)<br>
"#%04u/%02u/%02u %02u:%02u:%02u# profile=%u mode=%s granted=%s (global-pid=%u) task={ pid=%u ppid=%u uid=%u gid=%u euid=%u egid=%u suid=%u sgid=%u fsuid=%u fsgid=%u }",<br>
stamp.year, stamp.month, stamp.day, stamp.hour,<br>
stamp.min, stamp.sec, r->profile, tomoyo_mode[r->mode],<br>
- tomoyo_yesno(r->granted), gpid, tomoyo_sys_getpid(),<br>
+ yesno(r->granted), gpid, tomoyo_sys_getpid(),<br>
tomoyo_sys_getppid(),<br>
from_kuid(&init_user_ns, current_uid()),<br>
from_kgid(&init_user_ns, current_gid()),<br>
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c<br>
index 5c64927bf2b3..304ed0f426dd 100644<br>
--- a/security/tomoyo/common.c<br>
+++ b/security/tomoyo/common.c<br>
@@ -8,6 +8,7 @@<br>
#include <linux/uaccess.h><br>
#include <linux/slab.h><br>
#include <linux/security.h><br>
+#include <linux/string_helpers.h><br>
#include "common.h"<br>
<br>
/* String table for operation mode. */<br>
@@ -174,16 +175,6 @@ static bool tomoyo_manage_by_non_root;<br>
<br>
/* Utility functions. */<br>
<br>
-/**<br>
- * tomoyo_yesno - Return "yes" or "no".<br>
- *<br>
- * @value: Bool value.<br>
- */<br>
-const char *tomoyo_yesno(const unsigned int value)<br>
-{<br>
- return value ? "yes" : "no";<br>
-}<br>
-<br>
/**<br>
* tomoyo_addprintf - strncat()-like-snprintf().<br>
*<br>
@@ -730,8 +721,8 @@ static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config)<br>
{<br>
tomoyo_io_printf(head, "={ mode=%s grant_log=%s reject_log=%s }\n",<br>
tomoyo_mode[config & 3],<br>
- tomoyo_yesno(config & TOMOYO_CONFIG_WANT_GRANT_LOG),<br>
- tomoyo_yesno(config & TOMOYO_CONFIG_WANT_REJECT_LOG)<wbr>);<br>
+ yesno(config & TOMOYO_CONFIG_WANT_GRANT_LOG),<br>
+ yesno(config & TOMOYO_CONFIG_WANT_REJECT_LOG)<wbr>);<br>
}<br>
<br>
/**<br>
@@ -1354,8 +1345,7 @@ static bool tomoyo_print_condition(struct tomoyo_io_buffer *head,<br>
case 3:<br>
if (cond->grant_log != TOMOYO_GRANTLOG_AUTO)<br>
tomoyo_io_printf(head, " grant_log=%s",<br>
- tomoyo_yesno(cond->grant_log ==<br>
- TOMOYO_GRANTLOG_YES));<br>
+ yesno(cond->grant_log == TOMOYO_GRANTLOG_YES));<br>
tomoyo_set_lf(head);<br>
return true;<br>
}<br>
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h<br>
index 85246b9df7ca..ca285f362705 100644<br>
--- a/security/tomoyo/common.h<br>
+++ b/security/tomoyo/common.h<br>
@@ -959,7 +959,6 @@ char *tomoyo_read_token(struct tomoyo_acl_param *param);<br>
char *tomoyo_realpath_from_path(<wbr>const struct path *path);<br>
char *tomoyo_realpath_nofollow(<wbr>const char *pathname);<br>
const char *tomoyo_get_exe(void);<br>
-const char *tomoyo_yesno(const unsigned int value);<br>
const struct tomoyo_path_info *tomoyo_compare_name_union<br>
(const struct tomoyo_path_info *name, const struct tomoyo_name_union *ptr);<br>
const struct tomoyo_path_info *tomoyo_get_domainname<br>
-- <br>
2.34.1<br>
<br>
</blockquote><br><br>-- <br>With Best Regards,<br>Andy Shevchenko<br><br><br>