aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/devres.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/devres.c')
-rw-r--r--drivers/base/devres.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 438c91a43508..4aaf00d2098b 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -11,6 +11,8 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/percpu.h> 12#include <linux/percpu.h>
13 13
14#include <asm/sections.h>
15
14#include "base.h" 16#include "base.h"
15 17
16struct devres_node { 18struct devres_node {
@@ -823,6 +825,28 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp)
823EXPORT_SYMBOL_GPL(devm_kstrdup); 825EXPORT_SYMBOL_GPL(devm_kstrdup);
824 826
825/** 827/**
828 * devm_kstrdup_const - resource managed conditional string duplication
829 * @dev: device for which to duplicate the string
830 * @s: the string to duplicate
831 * @gfp: the GFP mask used in the kmalloc() call when allocating memory
832 *
833 * Strings allocated by devm_kstrdup_const will be automatically freed when
834 * the associated device is detached.
835 *
836 * RETURNS:
837 * Source string if it is in .rodata section otherwise it falls back to
838 * devm_kstrdup.
839 */
840const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp)
841{
842 if (is_kernel_rodata((unsigned long)s))
843 return s;
844
845 return devm_kstrdup(dev, s, gfp);
846}
847EXPORT_SYMBOL_GPL(devm_kstrdup_const);
848
849/**
826 * devm_kvasprintf - Allocate resource managed space and format a string 850 * devm_kvasprintf - Allocate resource managed space and format a string
827 * into that. 851 * into that.
828 * @dev: Device to allocate memory for 852 * @dev: Device to allocate memory for
@@ -889,6 +913,13 @@ void devm_kfree(struct device *dev, const void *p)
889{ 913{
890 int rc; 914 int rc;
891 915
916 /*
917 * Special case: pointer to a string in .rodata returned by
918 * devm_kstrdup_const().
919 */
920 if (unlikely(is_kernel_rodata((unsigned long)p)))
921 return;
922
892 rc = devres_destroy(dev, devm_kmalloc_release, 923 rc = devres_destroy(dev, devm_kmalloc_release,
893 devm_kmalloc_match, (void *)p); 924 devm_kmalloc_match, (void *)p);
894 WARN_ON(rc); 925 WARN_ON(rc);