diff mbox series

[v1,2/4] driver core: Replace kstrdup() + strreplace() with kstrdup_and_replace()

Message ID 20230628153211.52988-3-andriy.shevchenko@linux.intel.com
State Superseded
Headers show
Series clk: Add kstrdup_and_replace() helper and use it | expand

Commit Message

Andy Shevchenko June 28, 2023, 3:32 p.m. UTC
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(-)

Comments

Greg KH Aug. 4, 2023, 2:10 p.m. UTC | #1
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>
Andy Shevchenko Aug. 4, 2023, 2:30 p.m. UTC | #2
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)?
Andy Shevchenko Aug. 4, 2023, 2:46 p.m. UTC | #3
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
diff mbox series

Patch

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;
 }