* [PATCH net-next 1/2] lib: string: add strreplace_nonalnum
2019-03-03 17:19 [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Heiner Kallweit
@ 2019-03-03 17:20 ` Heiner Kallweit
2019-03-03 17:21 ` [PATCH net-next 2/2] net: phy: aquantia: use new function strreplace_nonalnum Heiner Kallweit
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-03 17:20 UTC (permalink / raw)
To: Florian Fainelli, Andrew Lunn, David Miller; +Cc: 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.
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.
+ */
+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';
+
+ return p;
+}
+EXPORT_SYMBOL(strreplace_nonalnum);
+
void fortify_panic(const char *name)
{
pr_emerg("detected buffer overflow in %s\n", name);
--
2.21.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next 2/2] net: phy: aquantia: use new function strreplace_nonalnum
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:21 ` Heiner Kallweit
2019-03-03 17:31 ` Andrew Lunn
2019-03-03 17:34 ` [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Andrew Lunn
2019-03-03 18:36 ` Heiner Kallweit
3 siblings, 1 reply; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-03 17:21 UTC (permalink / raw)
To: Florian Fainelli, Andrew Lunn, David Miller; +Cc: netdev@vger.kernel.org
Use new function strreplace_nonalnum to simplify the code.
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
drivers/net/phy/aquantia_hwmon.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/net/phy/aquantia_hwmon.c b/drivers/net/phy/aquantia_hwmon.c
index 19c4c280a..d47b3ed16 100644
--- a/drivers/net/phy/aquantia_hwmon.c
+++ b/drivers/net/phy/aquantia_hwmon.c
@@ -226,20 +226,12 @@ int aqr_hwmon_probe(struct phy_device *phydev)
struct device *dev = &phydev->mdio.dev;
struct device *hwmon_dev;
char *hwmon_name;
- int i, j;
hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
if (!hwmon_name)
return -ENOMEM;
- for (i = j = 0; hwmon_name[i]; i++) {
- if (isalnum(hwmon_name[i])) {
- if (i != j)
- hwmon_name[j] = hwmon_name[i];
- j++;
- }
- }
- hwmon_name[j] = '\0';
+ strreplace_nonalnum(hwmon_name, 0);
hwmon_dev = devm_hwmon_device_register_with_info(dev, hwmon_name,
phydev, &aqr_hwmon_chip_info, NULL);
--
2.21.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net-next 2/2] net: phy: aquantia: use new function strreplace_nonalnum
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
0 siblings, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2019-03-03 17:31 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: Florian Fainelli, David Miller, netdev@vger.kernel.org
On Sun, Mar 03, 2019 at 06:21:53PM +0100, Heiner Kallweit wrote:
> Use new function strreplace_nonalnum to simplify the code.
Hi Heiner
Both Marvell PHY drivers could use this.
sfp.c has a variant of this as well.
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next 2/2] net: phy: aquantia: use new function strreplace_nonalnum
2019-03-03 17:31 ` Andrew Lunn
@ 2019-03-03 17:41 ` Heiner Kallweit
0 siblings, 0 replies; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-03 17:41 UTC (permalink / raw)
To: Andrew Lunn; +Cc: Florian Fainelli, David Miller, netdev@vger.kernel.org
On 03.03.2019 18:31, Andrew Lunn wrote:
> On Sun, Mar 03, 2019 at 06:21:53PM +0100, Heiner Kallweit wrote:
>> Use new function strreplace_nonalnum to simplify the code.
>
> Hi Heiner
>
> Both Marvell PHY drivers could use this.
>
> sfp.c has a variant of this as well.
>
Thanks! My plan was to provide a first user so that the new
function gets accepted, and then look for more places where it
could be used. Most likely there are few HWMON drivers also
open-coding this functionality.
> Andrew
>
Heiner
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/2] lib: string: add strreplace_nonalnum
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:21 ` [PATCH net-next 2/2] net: phy: aquantia: use new function strreplace_nonalnum Heiner Kallweit
@ 2019-03-03 17:34 ` Andrew Lunn
2019-03-03 17:39 ` Heiner Kallweit
2019-03-03 18:36 ` Heiner Kallweit
3 siblings, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2019-03-03 17:34 UTC (permalink / raw)
To: Heiner Kallweit; +Cc: Florian Fainelli, David Miller, netdev@vger.kernel.org
On Sun, Mar 03, 2019 at 06:19:35PM +0100, Heiner Kallweit wrote:
> There doesn't seem to be a maintainer or mailing list for lib/string.c
> Therefore I hope it's ok to submit this through the netdev tree.
Hi Heiner
It is probably a good idea to Cc:
~/linux$ ./scripts/get_maintainer.pl -f lib/string.c
Alexander Shishkin <alexander.shishkin@linux.intel.com> (commit_signer:2/2=100%,authored:2/2=100%,added_lines:31/31=100%,removed_lines:30/30=100%)
Greg Kroah-Hartman <gregkh@linuxfoundation.org> (commit_signer:2/2=100%)
Andy Shevchenko <andriy.shevchenko@linux.intel.com> (commit_signer:1/2=50%)
linux-kernel@vger.kernel.org (open list)
And also Guenter Roeck who does most of the HWMON maintenance work.
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next 0/2] lib: string: add strreplace_nonalnum
2019-03-03 17:34 ` [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Andrew Lunn
@ 2019-03-03 17:39 ` Heiner Kallweit
0 siblings, 0 replies; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-03 17:39 UTC (permalink / raw)
To: Andrew Lunn; +Cc: Florian Fainelli, David Miller, netdev@vger.kernel.org
On 03.03.2019 18:34, Andrew Lunn wrote:
> On Sun, Mar 03, 2019 at 06:19:35PM +0100, Heiner Kallweit wrote:
>> There doesn't seem to be a maintainer or mailing list for lib/string.c
>> Therefore I hope it's ok to submit this through the netdev tree.
>
> Hi Heiner
>
> It is probably a good idea to Cc:
>
> ~/linux$ ./scripts/get_maintainer.pl -f lib/string.c
> Alexander Shishkin <alexander.shishkin@linux.intel.com> (commit_signer:2/2=100%,authored:2/2=100%,added_lines:31/31=100%,removed_lines:30/30=100%)
> Greg Kroah-Hartman <gregkh@linuxfoundation.org> (commit_signer:2/2=100%)
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> (commit_signer:1/2=50%)
> linux-kernel@vger.kernel.org (open list)
>
Strange, when I use get_maintainer.pl with the patch I get the following only:
[root@hkvirt linux-next]# scripts/get_maintainer.pl 0001-lib-string-add-strreplace_nonalnum.patch
Stephen Rothwell <sfr@canb.auug.org.au> (commit_signer:1/1=100%,authored:1/1=100%,added_lines:479/479=100%,added_lines:1055/1055=100%)
linux-kernel@vger.kernel.org (open list)
Therefore I sent it to the usual suspects only.
> And also Guenter Roeck who does most of the HWMON maintenance work.
>
Right.
> Andrew
>
Heiner
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/2] lib: string: add strreplace_nonalnum
2019-03-03 17:19 [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Heiner Kallweit
` (2 preceding siblings ...)
2019-03-03 17:34 ` [PATCH net-next 0/2] lib: string: add strreplace_nonalnum Andrew Lunn
@ 2019-03-03 18:36 ` Heiner Kallweit
2019-03-04 18:54 ` Heiner Kallweit
3 siblings, 1 reply; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-03 18:36 UTC (permalink / raw)
To: Florian Fainelli, Andrew Lunn, David Miller; +Cc: netdev@vger.kernel.org
On 03.03.2019 18:19, Heiner Kallweit wrote:
> 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 file name. If '\0' is given as new
> character then non-alphanumeric characters are cut.
>
> There doesn't seem to be a maintainer or mailing list for lib/string.c
> Therefore I hope it's ok to submit this through the netdev tree.
>
> Heiner Kallweit (2):
> lib: string: add strreplace_nonalnum
> net: phy: aquantia: use new function strreplace_nonalnum
>
> drivers/net/phy/aquantia_hwmon.c | 10 +---------
> include/linux/string.h | 1 +
> lib/string.c | 27 +++++++++++++++++++++++++++
> 3 files changed, 29 insertions(+), 9 deletions(-)
>
Greg still has some concerns, let's see what the outcome of this
discussion is.
https://lkml.org/lkml/2019/3/3/151
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next 0/2] lib: string: add strreplace_nonalnum
2019-03-03 18:36 ` Heiner Kallweit
@ 2019-03-04 18:54 ` Heiner Kallweit
2019-03-04 19:22 ` David Miller
0 siblings, 1 reply; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-04 18:54 UTC (permalink / raw)
To: Florian Fainelli, Andrew Lunn, David Miller; +Cc: netdev@vger.kernel.org
On 03.03.2019 19:36, Heiner Kallweit wrote:
> On 03.03.2019 18:19, Heiner Kallweit wrote:
>> 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 file name. If '\0' is given as new
>> character then non-alphanumeric characters are cut.
>>
>> There doesn't seem to be a maintainer or mailing list for lib/string.c
>> Therefore I hope it's ok to submit this through the netdev tree.
>>
>> Heiner Kallweit (2):
>> lib: string: add strreplace_nonalnum
>> net: phy: aquantia: use new function strreplace_nonalnum
>>
>> drivers/net/phy/aquantia_hwmon.c | 10 +---------
>> include/linux/string.h | 1 +
>> lib/string.c | 27 +++++++++++++++++++++++++++
>> 3 files changed, 29 insertions(+), 9 deletions(-)
>>
> Greg still has some concerns, let's see what the outcome of this
> discussion is.
> https://lkml.org/lkml/2019/3/3/151
>
This series should be deferred to next merge window.
Heiner
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/2] lib: string: add strreplace_nonalnum
2019-03-04 18:54 ` Heiner Kallweit
@ 2019-03-04 19:22 ` David Miller
2019-03-04 19:27 ` Heiner Kallweit
0 siblings, 1 reply; 11+ messages in thread
From: David Miller @ 2019-03-04 19:22 UTC (permalink / raw)
To: hkallweit1; +Cc: f.fainelli, andrew, netdev
From: Heiner Kallweit <hkallweit1@gmail.com>
Date: Mon, 4 Mar 2019 19:54:16 +0100
> On 03.03.2019 19:36, Heiner Kallweit wrote:
>> On 03.03.2019 18:19, Heiner Kallweit wrote:
>>> 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 file name. If '\0' is given as new
>>> character then non-alphanumeric characters are cut.
>>>
>>> There doesn't seem to be a maintainer or mailing list for lib/string.c
>>> Therefore I hope it's ok to submit this through the netdev tree.
>>>
>>> Heiner Kallweit (2):
>>> lib: string: add strreplace_nonalnum
>>> net: phy: aquantia: use new function strreplace_nonalnum
>>>
>>> drivers/net/phy/aquantia_hwmon.c | 10 +---------
>>> include/linux/string.h | 1 +
>>> lib/string.c | 27 +++++++++++++++++++++++++++
>>> 3 files changed, 29 insertions(+), 9 deletions(-)
>>>
>> Greg still has some concerns, let's see what the outcome of this
>> discussion is.
>> https://lkml.org/lkml/2019/3/3/151
>>
> This series should be deferred to next merge window.
Ok I'll revert, sorry I just saw this.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH net-next 0/2] lib: string: add strreplace_nonalnum
2019-03-04 19:22 ` David Miller
@ 2019-03-04 19:27 ` Heiner Kallweit
0 siblings, 0 replies; 11+ messages in thread
From: Heiner Kallweit @ 2019-03-04 19:27 UTC (permalink / raw)
To: David Miller; +Cc: f.fainelli, andrew, netdev
On 04.03.2019 20:22, David Miller wrote:
> From: Heiner Kallweit <hkallweit1@gmail.com>
> Date: Mon, 4 Mar 2019 19:54:16 +0100
>
>> On 03.03.2019 19:36, Heiner Kallweit wrote:
>>> On 03.03.2019 18:19, Heiner Kallweit wrote:
>>>> 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 file name. If '\0' is given as new
>>>> character then non-alphanumeric characters are cut.
>>>>
>>>> There doesn't seem to be a maintainer or mailing list for lib/string.c
>>>> Therefore I hope it's ok to submit this through the netdev tree.
>>>>
>>>> Heiner Kallweit (2):
>>>> lib: string: add strreplace_nonalnum
>>>> net: phy: aquantia: use new function strreplace_nonalnum
>>>>
>>>> drivers/net/phy/aquantia_hwmon.c | 10 +---------
>>>> include/linux/string.h | 1 +
>>>> lib/string.c | 27 +++++++++++++++++++++++++++
>>>> 3 files changed, 29 insertions(+), 9 deletions(-)
>>>>
>>> Greg still has some concerns, let's see what the outcome of this
>>> discussion is.
>>> https://lkml.org/lkml/2019/3/3/151
>>>
>> This series should be deferred to next merge window.
>
> Ok I'll revert, sorry I just saw this.
>
Thank you!
^ permalink raw reply [flat|nested] 11+ messages in thread