lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220126093951.1470898-2-lucas.demarchi@intel.com>
Date:   Wed, 26 Jan 2022 01:39:41 -0800
From:   Lucas De Marchi <lucas.demarchi@...el.com>
To:     linux-kernel@...r.kernel.org, intel-gfx@...ts.freedesktop.org,
        dri-devel@...ts.freedesktop.org, amd-gfx@...ts.freedesktop.org,
        linux-security-module@...r.kernel.org,
        nouveau@...ts.freedesktop.org, netdev@...r.kernel.org
Cc:     Andy Shevchenko <andy.shevchenko@...il.com>,
        Jani Nikula <jani.nikula@...el.com>,
        Daniel Vetter <daniel.vetter@...ll.ch>,
        Alex Deucher <alexander.deucher@....com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Ben Skeggs <bskeggs@...hat.com>,
        Christian König <christian.koenig@....com>,
        Chris Wilson <chris@...is-wilson.co.uk>,
        Daniel Vetter <daniel@...ll.ch>,
        David Airlie <airlied@...ux.ie>,
        "David S. Miller" <davem@...emloft.net>,
        Emma Anholt <emma@...olt.net>,
        Francis Laniel <laniel_francis@...vacyrequired.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Harry Wentland <harry.wentland@....com>,
        Jakub Kicinski <kuba@...nel.org>,
        Jani Nikula <jani.nikula@...ux.intel.com>,
        Joonas Lahtinen <joonas.lahtinen@...ux.intel.com>,
        Julia Lawall <julia.lawall@...6.fr>,
        Kentaro Takeda <takedakn@...data.co.jp>,
        Leo Li <sunpeng.li@....com>, Petr Mladek <pmladek@...e.com>,
        Rahul Lakkireddy <rahul.lakkireddy@...lsio.com>,
        Raju Rangoju <rajur@...lsio.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Rodrigo Vivi <rodrigo.vivi@...el.com>,
        Sakari Ailus <sakari.ailus@...ux.intel.com>,
        Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Vishal Kulkarni <vishal@...lsio.com>
Subject: [PATCH v2 01/11] lib/string_helpers: Consolidate string helpers implementation

There are a few implementations of string helpers in the tree like yesno()
that just returns "yes" or "no" depending on a boolean argument. Those
are helpful to output strings to the user or log.

In order to consolidate them, prefix all of them str_ prefix to make it
clear what they are about and avoid symbol clashes.
Taking the commoon `val ? "yes" : "no"` implementation,  quite a few
users of open coded yesno() could later be converted to the new
function:

$ git grep '?\s*"yes"\s*' | wc -l
286
$ git grep '?\s*"no"\s*' | wc -l
20

The inlined function should keep the const strings local to each
compilation unit, the same way it's now, thus not changing the current
behavior.

Signed-off-by: Lucas De Marchi <lucas.demarchi@...el.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@...il.com>
Acked-by: Jani Nikula <jani.nikula@...el.com>
Acked-by: Daniel Vetter <daniel.vetter@...ll.ch>
---
 include/linux/string_helpers.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index 7a22921c9db7..4d72258d42fd 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -106,4 +106,24 @@ void kfree_strarray(char **array, size_t n);
 
 char **devm_kasprintf_strarray(struct device *dev, const char *prefix, size_t n);
 
+static inline const char *str_yes_no(bool v)
+{
+	return v ? "yes" : "no";
+}
+
+static inline const char *str_on_off(bool v)
+{
+	return v ? "on" : "off";
+}
+
+static inline const char *str_enable_disable(bool v)
+{
+	return v ? "enable" : "disable";
+}
+
+static inline const char *str_enabled_disabled(bool v)
+{
+	return v ? "enabled" : "disabled";
+}
+
 #endif
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ