All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] devres: provide and use devm_kstrdup_const()
@ 2018-08-28  9:33 Bartosz Golaszewski
  2018-08-28  9:33 ` [PATCH v2 1/4] devres: constify p in devm_kfree() Bartosz Golaszewski
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Bartosz Golaszewski @ 2018-08-28  9:33 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Bjorn Andersson, Arnd Bergmann
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

This series implements devm_kstrdup_const() together with some
prerequisite changes and uses it in pmc-atom driver.

v1 -> v2:
- fixed the changelog in the patch implementing devm_kstrdup_const()
- fixed the kernel doc
- moved is_kernel_rodata() to asm-generic/sections.h
- fixed constness

Bartosz Golaszewski (4):
  devres: constify p in devm_kfree()
  mm: move is_kernel_rodata() to asm-generic/sections.h
  devres: provide devm_kstrdup_const()
  clk: pmc-atom: use devm_kstrdup_const()

 drivers/base/devres.c          | 43 ++++++++++++++++++++++++++++++++--
 drivers/clk/x86/clk-pmc-atom.c | 19 ++++-----------
 include/asm-generic/sections.h | 14 +++++++++++
 include/linux/device.h         |  5 +++-
 mm/util.c                      |  7 ------
 5 files changed, 63 insertions(+), 25 deletions(-)

-- 
2.18.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/4] devres: constify p in devm_kfree()
  2018-08-28  9:33 [PATCH v2 0/4] devres: provide and use devm_kstrdup_const() Bartosz Golaszewski
@ 2018-08-28  9:33 ` Bartosz Golaszewski
  2018-09-20 16:38   ` Bjorn Andersson
  2018-08-28  9:33 ` [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Bartosz Golaszewski
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Bartosz Golaszewski @ 2018-08-28  9:33 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Bjorn Andersson, Arnd Bergmann
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

Make devm_kfree() signature uniform with that of kfree(). To avoid
compiler warnings: cast p to (void *) when calling devres_destroy().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/base/devres.c  | 5 +++--
 include/linux/device.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index f98a097e73f2..438c91a43508 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -885,11 +885,12 @@ EXPORT_SYMBOL_GPL(devm_kasprintf);
  *
  * Free memory allocated with devm_kmalloc().
  */
-void devm_kfree(struct device *dev, void *p)
+void devm_kfree(struct device *dev, const void *p)
 {
 	int rc;
 
-	rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p);
+	rc = devres_destroy(dev, devm_kmalloc_release,
+			    devm_kmalloc_match, (void *)p);
 	WARN_ON(rc);
 }
 EXPORT_SYMBOL_GPL(devm_kfree);
diff --git a/include/linux/device.h b/include/linux/device.h
index 8f882549edee..33f7cb271fbb 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -692,7 +692,7 @@ static inline void *devm_kcalloc(struct device *dev,
 {
 	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
 }
-extern void devm_kfree(struct device *dev, void *p);
+extern void devm_kfree(struct device *dev, const void *p);
 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
 extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
 			  gfp_t gfp);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h
  2018-08-28  9:33 [PATCH v2 0/4] devres: provide and use devm_kstrdup_const() Bartosz Golaszewski
  2018-08-28  9:33 ` [PATCH v2 1/4] devres: constify p in devm_kfree() Bartosz Golaszewski
@ 2018-08-28  9:33 ` Bartosz Golaszewski
  2018-09-20 16:38   ` Bjorn Andersson
  2018-08-28  9:33 ` [PATCH v2 3/4] devres: provide devm_kstrdup_const() Bartosz Golaszewski
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Bartosz Golaszewski @ 2018-08-28  9:33 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Bjorn Andersson, Arnd Bergmann
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

Export this routine so that we can use it later in devm_kstrdup_const()
and devm_kfree_const().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 include/asm-generic/sections.h | 14 ++++++++++++++
 mm/util.c                      |  7 -------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 849cd8eb5ca0..d79abca81a52 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -141,4 +141,18 @@ static inline bool init_section_intersects(void *virt, size_t size)
 	return memory_intersects(__init_begin, __init_end, virt, size);
 }
 
+/**
+ * is_kernel_rodata - checks if the pointer address is located in the
+ *                    .rodata section
+ *
+ * @addr: address to check
+ *
+ * Returns: true if the address is located in .rodata, false otherwise.
+ */
+static inline bool is_kernel_rodata(unsigned long addr)
+{
+	return addr >= (unsigned long)__start_rodata &&
+	       addr < (unsigned long)__end_rodata;
+}
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
diff --git a/mm/util.c b/mm/util.c
index d2890a407332..41e9892a50ce 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -15,17 +15,10 @@
 #include <linux/vmalloc.h>
 #include <linux/userfaultfd_k.h>
 
-#include <asm/sections.h>
 #include <linux/uaccess.h>
 
 #include "internal.h"
 
-static inline int is_kernel_rodata(unsigned long addr)
-{
-	return addr >= (unsigned long)__start_rodata &&
-		addr < (unsigned long)__end_rodata;
-}
-
 /**
  * kfree_const - conditionally free memory
  * @x: pointer to the memory
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/4] devres: provide devm_kstrdup_const()
  2018-08-28  9:33 [PATCH v2 0/4] devres: provide and use devm_kstrdup_const() Bartosz Golaszewski
  2018-08-28  9:33 ` [PATCH v2 1/4] devres: constify p in devm_kfree() Bartosz Golaszewski
  2018-08-28  9:33 ` [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Bartosz Golaszewski
@ 2018-08-28  9:33 ` Bartosz Golaszewski
  2018-09-20 16:39   ` Bjorn Andersson
  2018-08-28  9:33 ` [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const() Bartosz Golaszewski
  2018-09-20 12:59 ` [PATCH v2 0/4] devres: provide and " Bartosz Golaszewski
  4 siblings, 1 reply; 14+ messages in thread
From: Bartosz Golaszewski @ 2018-08-28  9:33 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Bjorn Andersson, Arnd Bergmann
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

Provide a resource managed version of kstrdup_const(). This variant
internally calls devm_kstrdup() on pointers that are outside of
.rodata section and returns the string as is otherwise.

Also provide a corresponding version of devm_kfree().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/base/devres.c  | 38 ++++++++++++++++++++++++++++++++++++++
 include/linux/device.h |  3 +++
 2 files changed, 41 insertions(+)

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 438c91a43508..48185d57bc5b 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -11,6 +11,8 @@
 #include <linux/slab.h>
 #include <linux/percpu.h>
 
+#include <asm/sections.h>
+
 #include "base.h"
 
 struct devres_node {
@@ -822,6 +824,28 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
 }
 EXPORT_SYMBOL_GPL(devm_kstrdup);
 
+/**
+ * devm_kstrdup_const - resource managed conditional string duplication
+ * @dev: device for which to duplicate the string
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Strings allocated by devm_kstrdup_const will be automatically freed when
+ * the associated device is detached.
+ *
+ * RETURNS:
+ * Source string if it is in .rodata section otherwise it falls back to
+ * devm_kstrdup.
+ */
+const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp)
+{
+	if (is_kernel_rodata((unsigned long)s))
+		return s;
+
+	return devm_kstrdup(dev, s, gfp);
+}
+EXPORT_SYMBOL(devm_kstrdup_const);
+
 /**
  * devm_kvasprintf - Allocate resource managed space and format a string
  *		     into that.
@@ -895,6 +919,20 @@ void devm_kfree(struct device *dev, const void *p)
 }
 EXPORT_SYMBOL_GPL(devm_kfree);
 
+/**
+ * devm_kfree_const - Resource managed conditional kfree
+ * @dev: device this memory belongs to
+ * @p: memory to free
+ *
+ * Function calls devm_kfree only if @p is not in .rodata section.
+ */
+void devm_kfree_const(struct device *dev, const void *p)
+{
+	if (!is_kernel_rodata((unsigned long)p))
+		devm_kfree(dev, p);
+}
+EXPORT_SYMBOL(devm_kfree_const);
+
 /**
  * devm_kmemdup - Resource-managed kmemdup
  * @dev: Device this memory belongs to
diff --git a/include/linux/device.h b/include/linux/device.h
index 33f7cb271fbb..79ccc6eb0975 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -693,7 +693,10 @@ static inline void *devm_kcalloc(struct device *dev,
 	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
 }
 extern void devm_kfree(struct device *dev, const void *p);
+extern void devm_kfree_const(struct device *dev, const void *p);
 extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
+extern const char *devm_kstrdup_const(struct device *dev,
+				      const char *s, gfp_t gfp);
 extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
 			  gfp_t gfp);
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const()
  2018-08-28  9:33 [PATCH v2 0/4] devres: provide and use devm_kstrdup_const() Bartosz Golaszewski
                   ` (2 preceding siblings ...)
  2018-08-28  9:33 ` [PATCH v2 3/4] devres: provide devm_kstrdup_const() Bartosz Golaszewski
@ 2018-08-28  9:33 ` Bartosz Golaszewski
  2018-08-30 21:53     ` Stephen Boyd
  2018-09-20 16:39   ` Bjorn Andersson
  2018-09-20 12:59 ` [PATCH v2 0/4] devres: provide and " Bartosz Golaszewski
  4 siblings, 2 replies; 14+ messages in thread
From: Bartosz Golaszewski @ 2018-08-28  9:33 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Bjorn Andersson, Arnd Bergmann
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as
an example of how to use this new routine to shrink driver code.

While we're at it: replace a call to kcalloc() with devm_kcalloc().

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/clk/x86/clk-pmc-atom.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/x86/clk-pmc-atom.c b/drivers/clk/x86/clk-pmc-atom.c
index 08ef69945ffb..daa2192e6568 100644
--- a/drivers/clk/x86/clk-pmc-atom.c
+++ b/drivers/clk/x86/clk-pmc-atom.c
@@ -253,14 +253,6 @@ static void plt_clk_unregister_fixed_rate_loop(struct clk_plt_data *data,
 		plt_clk_unregister_fixed_rate(data->parents[i]);
 }
 
-static void plt_clk_free_parent_names_loop(const char **parent_names,
-					   unsigned int i)
-{
-	while (i--)
-		kfree_const(parent_names[i]);
-	kfree(parent_names);
-}
-
 static void plt_clk_unregister_loop(struct clk_plt_data *data,
 				    unsigned int i)
 {
@@ -286,8 +278,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev,
 	if (!data->parents)
 		return ERR_PTR(-ENOMEM);
 
-	parent_names = kcalloc(nparents, sizeof(*parent_names),
-			       GFP_KERNEL);
+	parent_names = devm_kcalloc(&pdev->dev, nparents,
+				    sizeof(*parent_names), GFP_KERNEL);
 	if (!parent_names)
 		return ERR_PTR(-ENOMEM);
 
@@ -300,7 +292,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev,
 			err = PTR_ERR(data->parents[i]);
 			goto err_unreg;
 		}
-		parent_names[i] = kstrdup_const(clks[i].name, GFP_KERNEL);
+		parent_names[i] = devm_kstrdup_const(&pdev->dev,
+						     clks[i].name, GFP_KERNEL);
 	}
 
 	data->nparents = nparents;
@@ -308,7 +301,6 @@ static const char **plt_clk_register_parents(struct platform_device *pdev,
 
 err_unreg:
 	plt_clk_unregister_fixed_rate_loop(data, i);
-	plt_clk_free_parent_names_loop(parent_names, i);
 	return ERR_PTR(err);
 }
 
@@ -351,15 +343,12 @@ static int plt_clk_probe(struct platform_device *pdev)
 		goto err_unreg_clk_plt;
 	}
 
-	plt_clk_free_parent_names_loop(parent_names, data->nparents);
-
 	platform_set_drvdata(pdev, data);
 	return 0;
 
 err_unreg_clk_plt:
 	plt_clk_unregister_loop(data, i);
 	plt_clk_unregister_parents(data);
-	plt_clk_free_parent_names_loop(parent_names, data->nparents);
 	return err;
 }
 
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const()
  2018-08-28  9:33 ` [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const() Bartosz Golaszewski
  2018-08-30 21:53     ` Stephen Boyd
@ 2018-08-30 21:53     ` Stephen Boyd
  1 sibling, 0 replies; 14+ messages in thread
From: Stephen Boyd @ 2018-08-30 21:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Al Viro, Andrew Morton, Arend van Spriel,
	Arnd Bergmann, Bartosz Golaszewski, Bjorn Andersson,
	Bjorn Helgaas, Greg Kroah-Hartman, Heikki Krogerus, Huang Ying,
	Joe Perches, Jonathan Corbet, Kees Cook, Michael Turquette,
	Michal Hocko, Mike Rapoport, Robin Murphy, Roman Gushchin,
	Ulf Hansson, Vivek Gautam
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

Quoting Bartosz Golaszewski (2018-08-28 02:33:32)
> Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as
> an example of how to use this new routine to shrink driver code.
> 
> While we're at it: replace a call to kcalloc() with devm_kcalloc().
> 
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

If you want this example to be merged through the clk tree please resend
after the other patches merge.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const()
@ 2018-08-30 21:53     ` Stephen Boyd
  0 siblings, 0 replies; 14+ messages in thread
From: Stephen Boyd @ 2018-08-30 21:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Al Viro, Andrew Morton, Arend van Spriel,
	Arnd Bergmann, Bartosz Golaszewski, Bjorn Andersson,
	Bjorn Helgaas, Greg Kroah-Hartman, Heikki Krogerus, Huang Ying,
	Joe Perches, Jonathan Corbet, Kees Cook, Michael Turquette,
	Michal Hocko, Mike Rapoport, Robin Murphy, Roman Gushchin,
	Ulf Hansson, Vivek Gautam
  Cc: linux-clk, linux-kernel, linux-mm, Bartosz Golaszewski

Quoting Bartosz Golaszewski (2018-08-28 02:33:32)
> Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as
> an example of how to use this new routine to shrink driver code.
> =

> While we're at it: replace a call to kcalloc() with devm_kcalloc().
> =

> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

If you want this example to be merged through the clk tree please resend
after the other patches merge.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const()
@ 2018-08-30 21:53     ` Stephen Boyd
  0 siblings, 0 replies; 14+ messages in thread
From: Stephen Boyd @ 2018-08-30 21:53 UTC (permalink / raw)
  To: Rafael J . Wysocki, Al Viro, Andrew Morton, Arend van Spriel,
	Arnd Bergmann, Bartosz Golaszewski, Bjorn Andersson,
	Bjorn Helgaas, Greg Kroah-Hartman, Heikki Krogerus, Huang Ying,
	Joe Perches, Jonathan Corbet, Kees Cook, Michael Turquette,
	Michal Hocko, Mike Rapoport, Robin Murphy, Roman Gushchin,
	Ulf Hansson, Vivek Gautam
  Cc: linux-clk, linux-kernel, linux-mm

Quoting Bartosz Golaszewski (2018-08-28 02:33:32)
> Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as
> an example of how to use this new routine to shrink driver code.
> 
> While we're at it: replace a call to kcalloc() with devm_kcalloc().
> 
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---

Reviewed-by: Stephen Boyd <sboyd@kernel.org>

If you want this example to be merged through the clk tree please resend
after the other patches merge.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/4] devres: provide and use devm_kstrdup_const()
  2018-08-28  9:33 [PATCH v2 0/4] devres: provide and use devm_kstrdup_const() Bartosz Golaszewski
                   ` (3 preceding siblings ...)
  2018-08-28  9:33 ` [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const() Bartosz Golaszewski
@ 2018-09-20 12:59 ` Bartosz Golaszewski
  2018-10-12 17:48   ` Stephen Boyd
  4 siblings, 1 reply; 14+ messages in thread
From: Bartosz Golaszewski @ 2018-09-20 12:59 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Bjorn Andersson, Arnd Bergmann
  Cc: linux-clk, Linux Kernel Mailing List, linux-mm, Bartosz Golaszewski

2018-08-28 11:33 GMT+02:00 Bartosz Golaszewski <brgl@bgdev.pl>:
> This series implements devm_kstrdup_const() together with some
> prerequisite changes and uses it in pmc-atom driver.
>
> v1 -> v2:
> - fixed the changelog in the patch implementing devm_kstrdup_const()
> - fixed the kernel doc
> - moved is_kernel_rodata() to asm-generic/sections.h
> - fixed constness
>
> Bartosz Golaszewski (4):
>   devres: constify p in devm_kfree()
>   mm: move is_kernel_rodata() to asm-generic/sections.h
>   devres: provide devm_kstrdup_const()
>   clk: pmc-atom: use devm_kstrdup_const()
>
>  drivers/base/devres.c          | 43 ++++++++++++++++++++++++++++++++--
>  drivers/clk/x86/clk-pmc-atom.c | 19 ++++-----------
>  include/asm-generic/sections.h | 14 +++++++++++
>  include/linux/device.h         |  5 +++-
>  mm/util.c                      |  7 ------
>  5 files changed, 63 insertions(+), 25 deletions(-)
>
> --
> 2.18.0
>

If there are no objections - can this be picked up for 4.20?

Thanks,
Bartosz

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 1/4] devres: constify p in devm_kfree()
  2018-08-28  9:33 ` [PATCH v2 1/4] devres: constify p in devm_kfree() Bartosz Golaszewski
@ 2018-09-20 16:38   ` Bjorn Andersson
  0 siblings, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2018-09-20 16:38 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Arnd Bergmann, linux-clk, linux-kernel, linux-mm

On Tue 28 Aug 02:33 PDT 2018, Bartosz Golaszewski wrote:

> Make devm_kfree() signature uniform with that of kfree(). To avoid
> compiler warnings: cast p to (void *) when calling devres_destroy().
> 

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
>  drivers/base/devres.c  | 5 +++--
>  include/linux/device.h | 2 +-
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index f98a097e73f2..438c91a43508 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -885,11 +885,12 @@ EXPORT_SYMBOL_GPL(devm_kasprintf);
>   *
>   * Free memory allocated with devm_kmalloc().
>   */
> -void devm_kfree(struct device *dev, void *p)
> +void devm_kfree(struct device *dev, const void *p)
>  {
>  	int rc;
>  
> -	rc = devres_destroy(dev, devm_kmalloc_release, devm_kmalloc_match, p);
> +	rc = devres_destroy(dev, devm_kmalloc_release,
> +			    devm_kmalloc_match, (void *)p);
>  	WARN_ON(rc);
>  }
>  EXPORT_SYMBOL_GPL(devm_kfree);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 8f882549edee..33f7cb271fbb 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -692,7 +692,7 @@ static inline void *devm_kcalloc(struct device *dev,
>  {
>  	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
>  }
> -extern void devm_kfree(struct device *dev, void *p);
> +extern void devm_kfree(struct device *dev, const void *p);
>  extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
>  extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
>  			  gfp_t gfp);
> -- 
> 2.18.0
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h
  2018-08-28  9:33 ` [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Bartosz Golaszewski
@ 2018-09-20 16:38   ` Bjorn Andersson
  0 siblings, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2018-09-20 16:38 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Arnd Bergmann, linux-clk, linux-kernel, linux-mm

On Tue 28 Aug 02:33 PDT 2018, Bartosz Golaszewski wrote:

> Export this routine so that we can use it later in devm_kstrdup_const()
> and devm_kfree_const().
> 

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
>  include/asm-generic/sections.h | 14 ++++++++++++++
>  mm/util.c                      |  7 -------
>  2 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
> index 849cd8eb5ca0..d79abca81a52 100644
> --- a/include/asm-generic/sections.h
> +++ b/include/asm-generic/sections.h
> @@ -141,4 +141,18 @@ static inline bool init_section_intersects(void *virt, size_t size)
>  	return memory_intersects(__init_begin, __init_end, virt, size);
>  }
>  
> +/**
> + * is_kernel_rodata - checks if the pointer address is located in the
> + *                    .rodata section
> + *
> + * @addr: address to check
> + *
> + * Returns: true if the address is located in .rodata, false otherwise.
> + */
> +static inline bool is_kernel_rodata(unsigned long addr)
> +{
> +	return addr >= (unsigned long)__start_rodata &&
> +	       addr < (unsigned long)__end_rodata;
> +}
> +
>  #endif /* _ASM_GENERIC_SECTIONS_H_ */
> diff --git a/mm/util.c b/mm/util.c
> index d2890a407332..41e9892a50ce 100644
> --- a/mm/util.c
> +++ b/mm/util.c
> @@ -15,17 +15,10 @@
>  #include <linux/vmalloc.h>
>  #include <linux/userfaultfd_k.h>
>  
> -#include <asm/sections.h>
>  #include <linux/uaccess.h>
>  
>  #include "internal.h"
>  
> -static inline int is_kernel_rodata(unsigned long addr)
> -{
> -	return addr >= (unsigned long)__start_rodata &&
> -		addr < (unsigned long)__end_rodata;
> -}
> -
>  /**
>   * kfree_const - conditionally free memory
>   * @x: pointer to the memory
> -- 
> 2.18.0
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 3/4] devres: provide devm_kstrdup_const()
  2018-08-28  9:33 ` [PATCH v2 3/4] devres: provide devm_kstrdup_const() Bartosz Golaszewski
@ 2018-09-20 16:39   ` Bjorn Andersson
  0 siblings, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2018-09-20 16:39 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Arnd Bergmann, linux-clk, linux-kernel, linux-mm

On Tue 28 Aug 02:33 PDT 2018, Bartosz Golaszewski wrote:

> Provide a resource managed version of kstrdup_const(). This variant
> internally calls devm_kstrdup() on pointers that are outside of
> .rodata section and returns the string as is otherwise.
> 
> Also provide a corresponding version of devm_kfree().
> 
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  drivers/base/devres.c  | 38 ++++++++++++++++++++++++++++++++++++++
>  include/linux/device.h |  3 +++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index 438c91a43508..48185d57bc5b 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -11,6 +11,8 @@
>  #include <linux/slab.h>
>  #include <linux/percpu.h>
>  
> +#include <asm/sections.h>
> +
>  #include "base.h"
>  
>  struct devres_node {
> @@ -822,6 +824,28 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
>  }
>  EXPORT_SYMBOL_GPL(devm_kstrdup);
>  
> +/**
> + * devm_kstrdup_const - resource managed conditional string duplication
> + * @dev: device for which to duplicate the string
> + * @s: the string to duplicate
> + * @gfp: the GFP mask used in the kmalloc() call when allocating memory
> + *
> + * Strings allocated by devm_kstrdup_const will be automatically freed when
> + * the associated device is detached.
> + *
> + * RETURNS:
> + * Source string if it is in .rodata section otherwise it falls back to
> + * devm_kstrdup.
> + */
> +const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp)
> +{
> +	if (is_kernel_rodata((unsigned long)s))
> +		return s;
> +
> +	return devm_kstrdup(dev, s, gfp);
> +}
> +EXPORT_SYMBOL(devm_kstrdup_const);
> +
>  /**
>   * devm_kvasprintf - Allocate resource managed space and format a string
>   *		     into that.
> @@ -895,6 +919,20 @@ void devm_kfree(struct device *dev, const void *p)
>  }
>  EXPORT_SYMBOL_GPL(devm_kfree);
>  
> +/**
> + * devm_kfree_const - Resource managed conditional kfree
> + * @dev: device this memory belongs to
> + * @p: memory to free
> + *
> + * Function calls devm_kfree only if @p is not in .rodata section.
> + */
> +void devm_kfree_const(struct device *dev, const void *p)
> +{
> +	if (!is_kernel_rodata((unsigned long)p))
> +		devm_kfree(dev, p);
> +}
> +EXPORT_SYMBOL(devm_kfree_const);
> +
>  /**
>   * devm_kmemdup - Resource-managed kmemdup
>   * @dev: Device this memory belongs to
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 33f7cb271fbb..79ccc6eb0975 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -693,7 +693,10 @@ static inline void *devm_kcalloc(struct device *dev,
>  	return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);
>  }
>  extern void devm_kfree(struct device *dev, const void *p);
> +extern void devm_kfree_const(struct device *dev, const void *p);
>  extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc;
> +extern const char *devm_kstrdup_const(struct device *dev,
> +				      const char *s, gfp_t gfp);
>  extern void *devm_kmemdup(struct device *dev, const void *src, size_t len,
>  			  gfp_t gfp);
>  
> -- 
> 2.18.0
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const()
  2018-08-28  9:33 ` [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const() Bartosz Golaszewski
  2018-08-30 21:53     ` Stephen Boyd
@ 2018-09-20 16:39   ` Bjorn Andersson
  1 sibling, 0 replies; 14+ messages in thread
From: Bjorn Andersson @ 2018-09-20 16:39 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Michael Turquette, Stephen Boyd, Greg Kroah-Hartman,
	Rafael J . Wysocki, Arend van Spriel, Ulf Hansson, Bjorn Helgaas,
	Vivek Gautam, Robin Murphy, Joe Perches, Heikki Krogerus,
	Andrew Morton, Mike Rapoport, Michal Hocko, Al Viro,
	Jonathan Corbet, Roman Gushchin, Huang Ying, Kees Cook,
	Arnd Bergmann, linux-clk, linux-kernel, linux-mm

On Tue 28 Aug 02:33 PDT 2018, Bartosz Golaszewski wrote:

> Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as
> an example of how to use this new routine to shrink driver code.
> 
> While we're at it: replace a call to kcalloc() with devm_kcalloc().
> 
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  drivers/clk/x86/clk-pmc-atom.c | 19 ++++---------------
>  1 file changed, 4 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/clk/x86/clk-pmc-atom.c b/drivers/clk/x86/clk-pmc-atom.c
> index 08ef69945ffb..daa2192e6568 100644
> --- a/drivers/clk/x86/clk-pmc-atom.c
> +++ b/drivers/clk/x86/clk-pmc-atom.c
> @@ -253,14 +253,6 @@ static void plt_clk_unregister_fixed_rate_loop(struct clk_plt_data *data,
>  		plt_clk_unregister_fixed_rate(data->parents[i]);
>  }
>  
> -static void plt_clk_free_parent_names_loop(const char **parent_names,
> -					   unsigned int i)
> -{
> -	while (i--)
> -		kfree_const(parent_names[i]);
> -	kfree(parent_names);
> -}
> -
>  static void plt_clk_unregister_loop(struct clk_plt_data *data,
>  				    unsigned int i)
>  {
> @@ -286,8 +278,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev,
>  	if (!data->parents)
>  		return ERR_PTR(-ENOMEM);
>  
> -	parent_names = kcalloc(nparents, sizeof(*parent_names),
> -			       GFP_KERNEL);
> +	parent_names = devm_kcalloc(&pdev->dev, nparents,
> +				    sizeof(*parent_names), GFP_KERNEL);
>  	if (!parent_names)
>  		return ERR_PTR(-ENOMEM);
>  
> @@ -300,7 +292,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev,
>  			err = PTR_ERR(data->parents[i]);
>  			goto err_unreg;
>  		}
> -		parent_names[i] = kstrdup_const(clks[i].name, GFP_KERNEL);
> +		parent_names[i] = devm_kstrdup_const(&pdev->dev,
> +						     clks[i].name, GFP_KERNEL);
>  	}
>  
>  	data->nparents = nparents;
> @@ -308,7 +301,6 @@ static const char **plt_clk_register_parents(struct platform_device *pdev,
>  
>  err_unreg:
>  	plt_clk_unregister_fixed_rate_loop(data, i);
> -	plt_clk_free_parent_names_loop(parent_names, i);
>  	return ERR_PTR(err);
>  }
>  
> @@ -351,15 +343,12 @@ static int plt_clk_probe(struct platform_device *pdev)
>  		goto err_unreg_clk_plt;
>  	}
>  
> -	plt_clk_free_parent_names_loop(parent_names, data->nparents);
> -
>  	platform_set_drvdata(pdev, data);
>  	return 0;
>  
>  err_unreg_clk_plt:
>  	plt_clk_unregister_loop(data, i);
>  	plt_clk_unregister_parents(data);
> -	plt_clk_free_parent_names_loop(parent_names, data->nparents);
>  	return err;
>  }
>  
> -- 
> 2.18.0
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 0/4] devres: provide and use devm_kstrdup_const()
  2018-09-20 12:59 ` [PATCH v2 0/4] devres: provide and " Bartosz Golaszewski
@ 2018-10-12 17:48   ` Stephen Boyd
  0 siblings, 0 replies; 14+ messages in thread
From: Stephen Boyd @ 2018-10-12 17:48 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: linux-clk, Linux Kernel Mailing List, linux-mm,
	Rafael J . Wysocki, Al Viro, Andrew Morton, Arend van Spriel,
	Arnd Bergmann, Bjorn Andersson, Bjorn Helgaas,
	Greg Kroah-Hartman, Heikki Krogerus, Huang Ying, Joe Perches,
	Jonathan Corbet, Kees Cook, Michael Turquette, Michal Hocko,
	Mike Rapoport, Robin Murphy, Roman Gushchin, Ulf Hansson,
	Vivek Gautam

Quoting Bartosz Golaszewski (2018-09-20 05:59:54)
> 2018-08-28 11:33 GMT+02:00 Bartosz Golaszewski <brgl@bgdev.pl>:
> > This series implements devm_kstrdup_const() together with some
> > prerequisite changes and uses it in pmc-atom driver.
> >
> > v1 -> v2:
> > - fixed the changelog in the patch implementing devm_kstrdup_const()
> > - fixed the kernel doc
> > - moved is_kernel_rodata() to asm-generic/sections.h
> > - fixed constness
> >
> > Bartosz Golaszewski (4):
> >   devres: constify p in devm_kfree()
> >   mm: move is_kernel_rodata() to asm-generic/sections.h
> >   devres: provide devm_kstrdup_const()
> >   clk: pmc-atom: use devm_kstrdup_const()
> >
> >  drivers/base/devres.c          | 43 ++++++++++++++++++++++++++++++++--
> >  drivers/clk/x86/clk-pmc-atom.c | 19 ++++-----------
> >  include/asm-generic/sections.h | 14 +++++++++++
> >  include/linux/device.h         |  5 +++-
> >  mm/util.c                      |  7 ------
> >  5 files changed, 63 insertions(+), 25 deletions(-)
> >
> > --
> > 2.18.0
> >
> 
> If there are no objections - can this be picked up for 4.20?
> 

There are so many people on To: line who do you want to pick this up?
Maybe you can send a pull request to Greg directly.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-10-12 17:49 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-28  9:33 [PATCH v2 0/4] devres: provide and use devm_kstrdup_const() Bartosz Golaszewski
2018-08-28  9:33 ` [PATCH v2 1/4] devres: constify p in devm_kfree() Bartosz Golaszewski
2018-09-20 16:38   ` Bjorn Andersson
2018-08-28  9:33 ` [PATCH v2 2/4] mm: move is_kernel_rodata() to asm-generic/sections.h Bartosz Golaszewski
2018-09-20 16:38   ` Bjorn Andersson
2018-08-28  9:33 ` [PATCH v2 3/4] devres: provide devm_kstrdup_const() Bartosz Golaszewski
2018-09-20 16:39   ` Bjorn Andersson
2018-08-28  9:33 ` [PATCH v2 4/4] clk: pmc-atom: use devm_kstrdup_const() Bartosz Golaszewski
2018-08-30 21:53   ` Stephen Boyd
2018-08-30 21:53     ` Stephen Boyd
2018-08-30 21:53     ` Stephen Boyd
2018-09-20 16:39   ` Bjorn Andersson
2018-09-20 12:59 ` [PATCH v2 0/4] devres: provide and " Bartosz Golaszewski
2018-10-12 17:48   ` Stephen Boyd

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.