* [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it
@ 2023-06-28 15:32 Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 1/4] lib/string_helpers: Add kstrdup_and_replace() helper Andy Shevchenko
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Andy Shevchenko @ 2023-06-28 15:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Saravana Kannan, Andy Shevchenko,
Stephen Boyd, Dario Binacchi, Tony Lindgren, linux-kernel,
linux-clk, linux-tegra, linux-omap
Cc: Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
There are a few existing users and more might come which would like
to have the kstrdup_and_replace() functionality.
Provide this new API and reuse it in a few users.
Since most of that is under CCF, perhaps it makes sense to route it
via that tree.
Andy Shevchenko (4):
lib/string_helpers: Add kstrdup_and_replace() helper
driver core: Replace kstrdup() + strreplace() with
kstrdup_and_replace()
clk: tegra: Replace kstrdup() + strreplace() with
kstrdup_and_replace()
clk: ti: Replace kstrdup() + strreplace() with kstrdup_and_replace()
drivers/base/core.c | 5 ++---
drivers/clk/tegra/clk.c | 6 ++----
drivers/clk/ti/clk.c | 4 ++--
drivers/clk/ti/clkctrl.c | 9 +++++----
include/linux/string_helpers.h | 2 ++
lib/string_helpers.c | 15 +++++++++++++++
6 files changed, 28 insertions(+), 13 deletions(-)
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 1/4] lib/string_helpers: Add kstrdup_and_replace() helper
2023-06-28 15:32 [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it Andy Shevchenko
@ 2023-06-28 15:32 ` Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace() Andy Shevchenko
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2023-06-28 15:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Saravana Kannan, Andy Shevchenko,
Stephen Boyd, Dario Binacchi, Tony Lindgren, linux-kernel,
linux-clk, linux-tegra, linux-omap
Cc: Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
Duplicate a NULL-terminated string and replace all occurrences of
the old character with a new one. In other words, provide functionality
of kstrdup() + strreplace().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/string_helpers.h | 2 ++
lib/string_helpers.c | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index 789ab30045da..9d1f5bb74dd5 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -109,6 +109,8 @@ 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);
+char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp);
+
char **kasprintf_strarray(gfp_t gfp, const char *prefix, size_t n);
void kfree_strarray(char **array, size_t n);
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index d3b1dd718daf..9982344cca34 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -719,6 +719,21 @@ char *kstrdup_quotable_file(struct file *file, gfp_t gfp)
}
EXPORT_SYMBOL_GPL(kstrdup_quotable_file);
+/*
+ * Returns duplicate string in which the @old characters are replaced by @new.
+ */
+char *kstrdup_and_replace(const char *src, char old, char new, gfp_t gfp)
+{
+ char *dst;
+
+ dst = kstrdup(src, gfp);
+ if (!dst)
+ return NULL;
+
+ return strreplace(dst, old, new);
+}
+EXPORT_SYMBOL_GPL(kstrdup_and_replace);
+
/**
* kasprintf_strarray - allocate and fill array of sequential strings
* @gfp: flags for the slab allocator
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace()
2023-06-28 15:32 [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 1/4] lib/string_helpers: Add kstrdup_and_replace() helper Andy Shevchenko
@ 2023-06-28 15:32 ` Andy Shevchenko
2023-08-04 14:10 ` Greg Kroah-Hartman
2023-06-28 15:32 ` [PATCH v1 3/4] clk: tegra: " Andy Shevchenko
` (2 subsequent siblings)
4 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2023-06-28 15:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Saravana Kannan, Andy Shevchenko,
Stephen Boyd, Dario Binacchi, Tony Lindgren, linux-kernel,
linux-clk, linux-tegra, linux-omap
Cc: Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
Replace open coded functionalify of kstrdup_and_replace() with a call.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/base/core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 3dff5037943e..af0ee691520a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -17,7 +17,6 @@
#include <linux/kstrtox.h>
#include <linux/module.h>
#include <linux/slab.h>
-#include <linux/string.h>
#include <linux/kdev_t.h>
#include <linux/notifier.h>
#include <linux/of.h>
@@ -28,6 +27,7 @@
#include <linux/netdevice.h>
#include <linux/sched/signal.h>
#include <linux/sched/mm.h>
+#include <linux/string_helpers.h>
#include <linux/swiotlb.h>
#include <linux/sysfs.h>
#include <linux/dma-map-ops.h> /* for dma_default_coherent */
@@ -3910,10 +3910,9 @@ const char *device_get_devnode(const struct device *dev,
return dev_name(dev);
/* replace '!' in the name with '/' */
- s = kstrdup(dev_name(dev), GFP_KERNEL);
+ s = kstrdup_and_replace(dev_name(dev), '!', '/', GFP_KERNEL);
if (!s)
return NULL;
- strreplace(s, '!', '/');
return *tmp = s;
}
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 3/4] clk: tegra: Replace kstrdup() + strreplace() with kstrdup_and_replace()
2023-06-28 15:32 [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 1/4] lib/string_helpers: Add kstrdup_and_replace() helper Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace() Andy Shevchenko
@ 2023-06-28 15:32 ` Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 4/4] clk: ti: " Andy Shevchenko
[not found] ` <ad13bab23313ca4bdfd405528a76ac37.sboyd@kernel.org>
4 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2023-06-28 15:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Saravana Kannan, Andy Shevchenko,
Stephen Boyd, Dario Binacchi, Tony Lindgren, linux-kernel,
linux-clk, linux-tegra, linux-omap
Cc: Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
Replace open coded functionalify of kstrdup_and_replace() with a call.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/clk/tegra/clk.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/tegra/clk.c b/drivers/clk/tegra/clk.c
index 26bda45813c0..071e72d1598a 100644
--- a/drivers/clk/tegra/clk.c
+++ b/drivers/clk/tegra/clk.c
@@ -14,7 +14,7 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset-controller.h>
-#include <linux/string.h>
+#include <linux/string_helpers.h>
#include <soc/tegra/fuse.h>
@@ -384,12 +384,10 @@ static struct device_node *tegra_clk_get_of_node(struct clk_hw *hw)
struct device_node *np;
char *node_name;
- node_name = kstrdup(hw->init->name, GFP_KERNEL);
+ node_name = kstrdup_and_replace(hw->init->name, '_', '-', GFP_KERNEL);
if (!node_name)
return NULL;
- strreplace(node_name, '_', '-');
-
for_each_child_of_node(tegra_car_np, np) {
if (!strcmp(np->name, node_name))
break;
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v1 4/4] clk: ti: Replace kstrdup() + strreplace() with kstrdup_and_replace()
2023-06-28 15:32 [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it Andy Shevchenko
` (2 preceding siblings ...)
2023-06-28 15:32 ` [PATCH v1 3/4] clk: tegra: " Andy Shevchenko
@ 2023-06-28 15:32 ` Andy Shevchenko
[not found] ` <ad13bab23313ca4bdfd405528a76ac37.sboyd@kernel.org>
4 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2023-06-28 15:32 UTC (permalink / raw)
To: Greg Kroah-Hartman, Saravana Kannan, Andy Shevchenko,
Stephen Boyd, Dario Binacchi, Tony Lindgren, linux-kernel,
linux-clk, linux-tegra, linux-omap
Cc: Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
Replace open coded functionalify of kstrdup_and_replace() with a call.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/clk/ti/clk.c | 4 ++--
drivers/clk/ti/clkctrl.c | 9 +++++----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/clk/ti/clk.c b/drivers/clk/ti/clk.c
index 3d636938a739..1862958ab412 100644
--- a/drivers/clk/ti/clk.c
+++ b/drivers/clk/ti/clk.c
@@ -16,6 +16,7 @@
#include <linux/of_address.h>
#include <linux/list.h>
#include <linux/regmap.h>
+#include <linux/string_helpers.h>
#include <linux/memblock.h>
#include <linux/device.h>
@@ -123,10 +124,9 @@ static struct device_node *ti_find_clock_provider(struct device_node *from,
const char *n;
char *tmp;
- tmp = kstrdup(name, GFP_KERNEL);
+ tmp = kstrdup_and_replace(name, '-', '_', GFP_KERNEL);
if (!tmp)
return NULL;
- strreplace(tmp, '-', '_');
/* Node named "clock" with "clock-output-names" */
for_each_of_allnodes_from(from, np) {
diff --git a/drivers/clk/ti/clkctrl.c b/drivers/clk/ti/clkctrl.c
index 8c40f10280b7..607e34d8e289 100644
--- a/drivers/clk/ti/clkctrl.c
+++ b/drivers/clk/ti/clkctrl.c
@@ -13,6 +13,7 @@
#include <linux/of_address.h>
#include <linux/clk/ti.h>
#include <linux/delay.h>
+#include <linux/string_helpers.h>
#include <linux/timekeeping.h>
#include "clock.h"
@@ -473,11 +474,11 @@ static const char * __init clkctrl_get_name(struct device_node *np)
const int prefix_len = 11;
const char *compat;
const char *output;
+ const char *end;
char *name;
if (!of_property_read_string_index(np, "clock-output-names", 0,
&output)) {
- const char *end;
int len;
len = strlen(output);
@@ -491,13 +492,13 @@ static const char * __init clkctrl_get_name(struct device_node *np)
of_property_for_each_string(np, "compatible", prop, compat) {
if (!strncmp("ti,clkctrl-", compat, prefix_len)) {
+ end = compat + prefix_len;
/* Two letter minimum name length for l3, l4 etc */
- if (strnlen(compat + prefix_len, 16) < 2)
+ if (strnlen(end, 16) < 2)
continue;
- name = kasprintf(GFP_KERNEL, "%s", compat + prefix_len);
+ name = kstrdup_and_replace(end, '-', '_', GFP_KERNEL);
if (!name)
continue;
- strreplace(name, '-', '_');
return name;
}
--
2.40.0.1.gaa8946217a0b
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it
[not found] ` <ad13bab23313ca4bdfd405528a76ac37.sboyd@kernel.org>
@ 2023-07-20 8:32 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2023-07-20 8:32 UTC (permalink / raw)
To: Stephen Boyd
Cc: Dario Binacchi, Greg Kroah-Hartman, Saravana Kannan,
Tony Lindgren, linux-clk, linux-kernel, linux-omap, linux-tegra,
Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo
On Wed, Jul 19, 2023 at 04:47:58PM -0700, Stephen Boyd wrote:
> Quoting Andy Shevchenko (2023-06-28 08:32:07)
> > There are a few existing users and more might come which would like
> > to have the kstrdup_and_replace() functionality.
> >
> > Provide this new API and reuse it in a few users.
> >
> > Since most of that is under CCF, perhaps it makes sense to route it
> > via that tree.
>
> I'm happy to pick it up if you can get an ack from GregKH on the driver
> core bits.
It's also an option to skip that patch.
Greg, can you Ack the patch 2 in this series?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace()
2023-06-28 15:32 ` [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace() Andy Shevchenko
@ 2023-08-04 14:10 ` Greg Kroah-Hartman
2023-08-04 14:30 ` Andy Shevchenko
0 siblings, 1 reply; 9+ messages in thread
From: Greg Kroah-Hartman @ 2023-08-04 14:10 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Saravana Kannan, Stephen Boyd, Dario Binacchi, Tony Lindgren,
linux-kernel, linux-clk, linux-tegra, linux-omap,
Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
On Wed, Jun 28, 2023 at 06:32:09PM +0300, Andy Shevchenko wrote:
> Replace open coded functionalify of kstrdup_and_replace() with a call.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/base/core.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 3dff5037943e..af0ee691520a 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -17,7 +17,6 @@
> #include <linux/kstrtox.h>
> #include <linux/module.h>
> #include <linux/slab.h>
> -#include <linux/string.h>
> #include <linux/kdev_t.h>
> #include <linux/notifier.h>
> #include <linux/of.h>
> @@ -28,6 +27,7 @@
> #include <linux/netdevice.h>
> #include <linux/sched/signal.h>
> #include <linux/sched/mm.h>
> +#include <linux/string_helpers.h>
> #include <linux/swiotlb.h>
> #include <linux/sysfs.h>
> #include <linux/dma-map-ops.h> /* for dma_default_coherent */
> @@ -3910,10 +3910,9 @@ const char *device_get_devnode(const struct device *dev,
> return dev_name(dev);
>
> /* replace '!' in the name with '/' */
> - s = kstrdup(dev_name(dev), GFP_KERNEL);
> + s = kstrdup_and_replace(dev_name(dev), '!', '/', GFP_KERNEL);
> if (!s)
> return NULL;
> - strreplace(s, '!', '/');
> return *tmp = s;
> }
>
> --
> 2.40.0.1.gaa8946217a0b
>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace()
2023-08-04 14:10 ` Greg Kroah-Hartman
@ 2023-08-04 14:30 ` Andy Shevchenko
2023-08-04 14:46 ` Andy Shevchenko
0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2023-08-04 14:30 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Andy Shevchenko, Saravana Kannan, Stephen Boyd, Dario Binacchi,
Tony Lindgren, linux-kernel, linux-clk, linux-tegra, linux-omap,
Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo,
Andy Shevchenko
On Fri, Aug 4, 2023 at 5:10 PM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Wed, Jun 28, 2023 at 06:32:09PM +0300, Andy Shevchenko wrote:
> > Replace open coded functionalify of kstrdup_and_replace() with a call.
Oh, here is a typo.
...
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Thank you, Greg!
Stephen, can you take the series now (okay, I think I need to send a
new version with all tags and typos fixed)?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace()
2023-08-04 14:30 ` Andy Shevchenko
@ 2023-08-04 14:46 ` Andy Shevchenko
0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2023-08-04 14:46 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Saravana Kannan, Stephen Boyd, Dario Binacchi, Tony Lindgren,
linux-kernel, linux-clk, linux-tegra, linux-omap,
Rafael J. Wysocki, Peter De Schrijver, Prashant Gaikwad,
Michael Turquette, Thierry Reding, Jonathan Hunter, Tero Kristo
On Fri, Aug 04, 2023 at 05:30:49PM +0300, Andy Shevchenko wrote:
> On Fri, Aug 4, 2023 at 5:10 PM Greg Kroah-Hartman
> <gregkh@linuxfoundation.org> wrote:
> > On Wed, Jun 28, 2023 at 06:32:09PM +0300, Andy Shevchenko wrote:
...
> Stephen, can you take the series now (okay, I think I need to send a
> new version with all tags and typos fixed)?
v2 has been sent: 20230804143910.15504-1-andriy.shevchenko@linux.intel.com
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-08-04 14:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 15:32 [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 1/4] lib/string_helpers: Add kstrdup_and_replace() helper Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace() Andy Shevchenko
2023-08-04 14:10 ` Greg Kroah-Hartman
2023-08-04 14:30 ` Andy Shevchenko
2023-08-04 14:46 ` Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 3/4] clk: tegra: " Andy Shevchenko
2023-06-28 15:32 ` [PATCH v1 4/4] clk: ti: " Andy Shevchenko
[not found] ` <ad13bab23313ca4bdfd405528a76ac37.sboyd@kernel.org>
2023-07-20 8:32 ` [PATCH v1 0/4] clk: Add kstrdup_and_replace() helper and use it Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).