]> git.itanic.dy.fi Git - linux-stable/commitdiff
lib/string_helpers: Introduce string_upper() and string_lower() helpers
authorVadim Pasternak <vadimp@mellanox.com>
Tue, 14 Jul 2020 12:01:53 +0000 (15:01 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 30 May 2023 11:44:08 +0000 (12:44 +0100)
[ Upstream commit 58eeba0bdb52afe5c18ce2a760ca9fe2901943e9 ]

Provide the helpers for string conversions to upper and lower cases.

Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Stable-dep-of: 3c0f4f09c063 ("usb: gadget: u_ether: Fix host MAC address case")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/string_helpers.h

index c2895513223422d9dac62bdac6313a25a31613b3..86f150c2a6b663dffb9fd47f89712c3ea6a8ef37 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef _LINUX_STRING_HELPERS_H_
 #define _LINUX_STRING_HELPERS_H_
 
+#include <linux/ctype.h>
 #include <linux/types.h>
 
 struct file;
@@ -75,6 +76,20 @@ static inline int string_escape_str_any_np(const char *src, char *dst,
        return string_escape_str(src, dst, sz, ESCAPE_ANY_NP, only);
 }
 
+static inline void string_upper(char *dst, const char *src)
+{
+       do {
+               *dst++ = toupper(*src);
+       } while (*src++);
+}
+
+static inline void string_lower(char *dst, const char *src)
+{
+       do {
+               *dst++ = tolower(*src);
+       } while (*src++);
+}
+
 char *kstrdup_quotable(const char *src, gfp_t gfp);
 char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp);
 char *kstrdup_quotable_file(struct file *file, gfp_t gfp);