clk: ti: Replace kstrdup() + strreplace() with kstrdup_and_replace()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Fri, 4 Aug 2023 14:39:10 +0000 (17:39 +0300)
committerStephen Boyd <sboyd@kernel.org>
Sat, 5 Aug 2023 01:21:51 +0000 (18:21 -0700)
Replace open coded functionality of kstrdup_and_replace() with a call.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230804143910.15504-5-andriy.shevchenko@linux.intel.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/ti/clk.c
drivers/clk/ti/clkctrl.c

index 3d63693..1862958 100644 (file)
@@ -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) {
index 8c40f10..607e34d 100644 (file)
@@ -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;
                }