aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2017-02-02 20:41:26 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-02-07 07:21:15 -0500
commit9426998ce6f8616c48c2834cafbe5616da3f5abd (patch)
tree03990e849cc0985423227886b1b65772a6eb8526
parentbec84da8d1da6677c458e6eedd8e814eea91b9fc (diff)
device property: constify property arrays values
Data that is fed into property arrays should not be modified, so let's mark relevant pointers as const. This will allow us making source arrays as const/__initconst. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/base/property.c10
-rw-r--r--include/linux/property.h12
2 files changed, 11 insertions, 11 deletions
diff --git a/drivers/base/property.c b/drivers/base/property.c
index e9fa75645d69..31b942a29fdc 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -718,7 +718,8 @@ static void pset_free_set(struct property_set *pset)
718static int pset_copy_entry(struct property_entry *dst, 718static int pset_copy_entry(struct property_entry *dst,
719 const struct property_entry *src) 719 const struct property_entry *src)
720{ 720{
721 const char **d, **s; 721 const char * const *s;
722 char **d;
722 size_t i, nval; 723 size_t i, nval;
723 724
724 dst->name = kstrdup(src->name, GFP_KERNEL); 725 dst->name = kstrdup(src->name, GFP_KERNEL);
@@ -731,12 +732,11 @@ static int pset_copy_entry(struct property_entry *dst,
731 732
732 if (src->is_string) { 733 if (src->is_string) {
733 nval = src->length / sizeof(const char *); 734 nval = src->length / sizeof(const char *);
734 dst->pointer.str = kcalloc(nval, sizeof(const char *), 735 d = kcalloc(nval, sizeof(const char *), GFP_KERNEL);
735 GFP_KERNEL); 736 if (!d)
736 if (!dst->pointer.str)
737 return -ENOMEM; 737 return -ENOMEM;
738 738
739 d = dst->pointer.str; 739 dst->pointer.raw_data = d;
740 s = src->pointer.str; 740 s = src->pointer.str;
741 for (i = 0; i < nval; i++) { 741 for (i = 0; i < nval; i++) {
742 d[i] = kstrdup(s[i], GFP_KERNEL); 742 d[i] = kstrdup(s[i], GFP_KERNEL);
diff --git a/include/linux/property.h b/include/linux/property.h
index d37a4498b3ac..7a0a1cce5165 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -160,12 +160,12 @@ struct property_entry {
160 bool is_string; 160 bool is_string;
161 union { 161 union {
162 union { 162 union {
163 void *raw_data; 163 const void *raw_data;
164 u8 *u8_data; 164 const u8 *u8_data;
165 u16 *u16_data; 165 const u16 *u16_data;
166 u32 *u32_data; 166 const u32 *u32_data;
167 u64 *u64_data; 167 const u64 *u64_data;
168 const char **str; 168 const char * const *str;
169 } pointer; 169 } pointer;
170 union { 170 union {
171 unsigned long long raw_data; 171 unsigned long long raw_data;