From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Fwd: [PATCH net-next 1/2] lib: string: add strreplace_nonalnum
Date: Sun, 3 Mar 2019 18:55:14 +0100 [thread overview]
Message-ID: <20190303175514.GA16636@kroah.com> (raw)
In-Reply-To: <43eb3aad-0e0b-9019-dfe3-47f205607df0@gmail.com>
On Sun, Mar 03, 2019 at 06:47:32PM +0100, Heiner Kallweit wrote:
> I submitted this through the netdev tree, maybe relevant for you as well.
> See also here: https://marc.info/?t=155103900100003&r=1&w=2
>
> -------- Forwarded Message --------
> Subject: [PATCH net-next 1/2] lib: string: add strreplace_nonalnum
> Date: Sun, 3 Mar 2019 18:20:50 +0100
> From: Heiner Kallweit <hkallweit1@gmail.com>
> To: Florian Fainelli <f.fainelli@gmail.com>, Andrew Lunn <andrew@lunn.ch>, David Miller <davem@davemloft.net>
> CC: netdev@vger.kernel.org <netdev@vger.kernel.org>
>
> Add a new function strreplace_nonalnum that replaces all
> non-alphanumeric characters. Such functionality is needed e.g. when a
> string is supposed to be used in a sysfs file name. If '\0' is given
> as new character then non-alphanumeric characters are cut.
sysfs doesn't have any such requirements, it can use whatever you want
to give it for a filename.
So don't create a random kernel function for sysfs please.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> include/linux/string.h | 1 +
> lib/string.c | 27 +++++++++++++++++++++++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/include/linux/string.h b/include/linux/string.h
> index 7927b875f..d827b0b0f 100644
> --- a/include/linux/string.h
> +++ b/include/linux/string.h
> @@ -169,6 +169,7 @@ static inline void memcpy_flushcache(void *dst, const void *src, size_t cnt)
> #endif
> void *memchr_inv(const void *s, int c, size_t n);
> char *strreplace(char *s, char old, char new);
> +char *strreplace_nonalnum(char *s, char new);
>
> extern void kfree_const(const void *x);
>
> diff --git a/lib/string.c b/lib/string.c
> index 38e4ca08e..f2b1baf96 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -1047,6 +1047,33 @@ char *strreplace(char *s, char old, char new)
> }
> EXPORT_SYMBOL(strreplace);
>
> +/**
> + * strreplace_nonalnum - Replace all non-alphanumeric characters in a string.
> + * @s: The string to operate on.
> + * @new: The character non-alphanumeric characters are replaced with.
> + *
> + * If new is '\0' then non-alphanumeric characters are cut.
> + *
> + * Returns pointer to the nul byte at the end of the modified string.
Why do you need to point to the end of the string?
> + */
> +char *strreplace_nonalnum(char *s, char new)
> +{
> + char *p = s;
> +
> + for (; *s; ++s)
> + if (isalnum(*s)) {
> + if (p != s)
> + *p = *s;
> + ++p;
> + } else if (new) {
> + *p++ = new;
> + }
> + *p = '\0';
No max length? No error checking? Surely we can do better, see the
long thread on the kernel-hardnening list about string functions please.
greg k-h
next prev parent reply other threads:[~2019-03-03 17:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-03 17:19 [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Heiner Kallweit
2019-03-03 17:20 ` [PATCH net-next 1/2] " Heiner Kallweit
2019-03-03 17:47 ` Fwd: " Heiner Kallweit
2019-03-03 17:55 ` Greg Kroah-Hartman [this message]
2019-03-03 18:04 ` Heiner Kallweit
2019-03-03 18:15 ` Greg Kroah-Hartman
2019-03-03 18:32 ` Heiner Kallweit
2019-03-03 18:41 ` Greg Kroah-Hartman
2019-03-03 18:47 ` Heiner Kallweit
2019-03-03 18:59 ` Greg Kroah-Hartman
2019-03-03 17:21 ` [PATCH net-next 2/2] net: phy: aquantia: use new function strreplace_nonalnum Heiner Kallweit
2019-03-03 17:31 ` Andrew Lunn
2019-03-03 17:41 ` Heiner Kallweit
2019-03-03 17:34 ` [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Andrew Lunn
2019-03-03 17:39 ` Heiner Kallweit
2019-03-03 18:36 ` Heiner Kallweit
2019-03-04 18:54 ` Heiner Kallweit
2019-03-04 19:22 ` David Miller
2019-03-04 19:27 ` Heiner Kallweit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190303175514.GA16636@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=hkallweit1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.