diff options
| author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-02-02 20:41:25 -0500 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2017-02-07 07:21:15 -0500 |
| commit | bec84da8d1da6677c458e6eedd8e814eea91b9fc (patch) | |
| tree | c78b997b7d47c5040f67fdabb3770e5dc0057c63 /drivers/base | |
| parent | d5adbfcd5f7bcc6fa58a41c5c5ada0e5c826ce2c (diff) | |
device property: allow to constify properties
There is no reason why statically defined properties should be modifiable,
so let's make device_add_properties() and the rest of pset_*() functions to
take const pointers to properties.
This will allow us to mark properties as const/__initconst at definition
sites.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/base')
| -rw-r--r-- | drivers/base/property.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/drivers/base/property.c b/drivers/base/property.c index 43a36d68c3fd..e9fa75645d69 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c | |||
| @@ -21,7 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | struct property_set { | 22 | struct property_set { |
| 23 | struct fwnode_handle fwnode; | 23 | struct fwnode_handle fwnode; |
| 24 | struct property_entry *properties; | 24 | const struct property_entry *properties; |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | static inline bool is_pset_node(struct fwnode_handle *fwnode) | 27 | static inline bool is_pset_node(struct fwnode_handle *fwnode) |
| @@ -35,10 +35,10 @@ static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode) | |||
| 35 | container_of(fwnode, struct property_set, fwnode) : NULL; | 35 | container_of(fwnode, struct property_set, fwnode) : NULL; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | static struct property_entry *pset_prop_get(struct property_set *pset, | 38 | static const struct property_entry *pset_prop_get(struct property_set *pset, |
| 39 | const char *name) | 39 | const char *name) |
| 40 | { | 40 | { |
| 41 | struct property_entry *prop; | 41 | const struct property_entry *prop; |
| 42 | 42 | ||
| 43 | if (!pset || !pset->properties) | 43 | if (!pset || !pset->properties) |
| 44 | return NULL; | 44 | return NULL; |
| @@ -50,11 +50,11 @@ static struct property_entry *pset_prop_get(struct property_set *pset, | |||
| 50 | return NULL; | 50 | return NULL; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | static void *pset_prop_find(struct property_set *pset, const char *propname, | 53 | static const void *pset_prop_find(struct property_set *pset, |
| 54 | size_t length) | 54 | const char *propname, size_t length) |
| 55 | { | 55 | { |
| 56 | struct property_entry *prop; | 56 | const struct property_entry *prop; |
| 57 | void *pointer; | 57 | const void *pointer; |
| 58 | 58 | ||
| 59 | prop = pset_prop_get(pset, propname); | 59 | prop = pset_prop_get(pset, propname); |
| 60 | if (!prop) | 60 | if (!prop) |
| @@ -74,7 +74,7 @@ static int pset_prop_read_u8_array(struct property_set *pset, | |||
| 74 | const char *propname, | 74 | const char *propname, |
| 75 | u8 *values, size_t nval) | 75 | u8 *values, size_t nval) |
| 76 | { | 76 | { |
| 77 | void *pointer; | 77 | const void *pointer; |
| 78 | size_t length = nval * sizeof(*values); | 78 | size_t length = nval * sizeof(*values); |
| 79 | 79 | ||
| 80 | pointer = pset_prop_find(pset, propname, length); | 80 | pointer = pset_prop_find(pset, propname, length); |
| @@ -89,7 +89,7 @@ static int pset_prop_read_u16_array(struct property_set *pset, | |||
| 89 | const char *propname, | 89 | const char *propname, |
| 90 | u16 *values, size_t nval) | 90 | u16 *values, size_t nval) |
| 91 | { | 91 | { |
| 92 | void *pointer; | 92 | const void *pointer; |
| 93 | size_t length = nval * sizeof(*values); | 93 | size_t length = nval * sizeof(*values); |
| 94 | 94 | ||
| 95 | pointer = pset_prop_find(pset, propname, length); | 95 | pointer = pset_prop_find(pset, propname, length); |
| @@ -104,7 +104,7 @@ static int pset_prop_read_u32_array(struct property_set *pset, | |||
| 104 | const char *propname, | 104 | const char *propname, |
| 105 | u32 *values, size_t nval) | 105 | u32 *values, size_t nval) |
| 106 | { | 106 | { |
| 107 | void *pointer; | 107 | const void *pointer; |
| 108 | size_t length = nval * sizeof(*values); | 108 | size_t length = nval * sizeof(*values); |
| 109 | 109 | ||
| 110 | pointer = pset_prop_find(pset, propname, length); | 110 | pointer = pset_prop_find(pset, propname, length); |
| @@ -119,7 +119,7 @@ static int pset_prop_read_u64_array(struct property_set *pset, | |||
| 119 | const char *propname, | 119 | const char *propname, |
| 120 | u64 *values, size_t nval) | 120 | u64 *values, size_t nval) |
| 121 | { | 121 | { |
| 122 | void *pointer; | 122 | const void *pointer; |
| 123 | size_t length = nval * sizeof(*values); | 123 | size_t length = nval * sizeof(*values); |
| 124 | 124 | ||
| 125 | pointer = pset_prop_find(pset, propname, length); | 125 | pointer = pset_prop_find(pset, propname, length); |
| @@ -133,7 +133,7 @@ static int pset_prop_read_u64_array(struct property_set *pset, | |||
| 133 | static int pset_prop_count_elems_of_size(struct property_set *pset, | 133 | static int pset_prop_count_elems_of_size(struct property_set *pset, |
| 134 | const char *propname, size_t length) | 134 | const char *propname, size_t length) |
| 135 | { | 135 | { |
| 136 | struct property_entry *prop; | 136 | const struct property_entry *prop; |
| 137 | 137 | ||
| 138 | prop = pset_prop_get(pset, propname); | 138 | prop = pset_prop_get(pset, propname); |
| 139 | if (!prop) | 139 | if (!prop) |
| @@ -146,7 +146,7 @@ static int pset_prop_read_string_array(struct property_set *pset, | |||
| 146 | const char *propname, | 146 | const char *propname, |
| 147 | const char **strings, size_t nval) | 147 | const char **strings, size_t nval) |
| 148 | { | 148 | { |
| 149 | void *pointer; | 149 | const void *pointer; |
| 150 | size_t length = nval * sizeof(*strings); | 150 | size_t length = nval * sizeof(*strings); |
| 151 | 151 | ||
| 152 | pointer = pset_prop_find(pset, propname, length); | 152 | pointer = pset_prop_find(pset, propname, length); |
| @@ -160,8 +160,8 @@ static int pset_prop_read_string_array(struct property_set *pset, | |||
| 160 | static int pset_prop_read_string(struct property_set *pset, | 160 | static int pset_prop_read_string(struct property_set *pset, |
| 161 | const char *propname, const char **strings) | 161 | const char *propname, const char **strings) |
| 162 | { | 162 | { |
| 163 | struct property_entry *prop; | 163 | const struct property_entry *prop; |
| 164 | const char **pointer; | 164 | const char * const *pointer; |
| 165 | 165 | ||
| 166 | prop = pset_prop_get(pset, propname); | 166 | prop = pset_prop_get(pset, propname); |
| 167 | if (!prop) | 167 | if (!prop) |
| @@ -776,7 +776,7 @@ static int pset_copy_entry(struct property_entry *dst, | |||
| 776 | */ | 776 | */ |
| 777 | static struct property_set *pset_copy_set(const struct property_set *pset) | 777 | static struct property_set *pset_copy_set(const struct property_set *pset) |
| 778 | { | 778 | { |
| 779 | const struct property_entry *entry; | 779 | struct property_entry *props; |
| 780 | struct property_set *p; | 780 | struct property_set *p; |
| 781 | size_t i, n = 0; | 781 | size_t i, n = 0; |
| 782 | 782 | ||
| @@ -787,14 +787,14 @@ static struct property_set *pset_copy_set(const struct property_set *pset) | |||
| 787 | while (pset->properties[n].name) | 787 | while (pset->properties[n].name) |
| 788 | n++; | 788 | n++; |
| 789 | 789 | ||
| 790 | p->properties = kcalloc(n + 1, sizeof(*entry), GFP_KERNEL); | 790 | p->properties = props = kcalloc(n + 1, sizeof(*props), GFP_KERNEL); |
| 791 | if (!p->properties) { | 791 | if (!p->properties) { |
| 792 | kfree(p); | 792 | kfree(p); |
| 793 | return ERR_PTR(-ENOMEM); | 793 | return ERR_PTR(-ENOMEM); |
| 794 | } | 794 | } |
| 795 | 795 | ||
| 796 | for (i = 0; i < n; i++) { | 796 | for (i = 0; i < n; i++) { |
| 797 | int ret = pset_copy_entry(&p->properties[i], | 797 | int ret = pset_copy_entry(&props[i], |
| 798 | &pset->properties[i]); | 798 | &pset->properties[i]); |
| 799 | if (ret) { | 799 | if (ret) { |
| 800 | pset_free_set(p); | 800 | pset_free_set(p); |
| @@ -847,7 +847,8 @@ EXPORT_SYMBOL_GPL(device_remove_properties); | |||
| 847 | * @dev as its secondary firmware node. The function takes a copy of | 847 | * @dev as its secondary firmware node. The function takes a copy of |
| 848 | * @properties. | 848 | * @properties. |
| 849 | */ | 849 | */ |
| 850 | int device_add_properties(struct device *dev, struct property_entry *properties) | 850 | int device_add_properties(struct device *dev, |
| 851 | const struct property_entry *properties) | ||
| 851 | { | 852 | { |
| 852 | struct property_set *p, pset; | 853 | struct property_set *p, pset; |
| 853 | 854 | ||
