Re: [PATCH 2/2] device property: allow constify properties
From: Andy Shevchenko
Date: Mon Jan 23 2017 - 10:07:20 EST
On Sun, 2017-01-22 at 23:38 -0800, Dmitry Torokhov wrote:
> 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.
>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
> ---
> Âdrivers/base/property.cÂÂ| 35 ++++++++++++++++++-----------------
> Âinclude/linux/property.h |ÂÂ2 +-
> Â2 files changed, 19 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index ee22ded63e06..4cbf99cb8ef6 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -21,7 +21,7 @@
> Â
> Âstruct property_set {
> Â struct fwnode_handle fwnode;
> - struct property_entry *properties;
> + const struct property_entry *properties;
> Â};
> Â
> Â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)
> Â container_of(fwnode, struct property_set, fwnode) :
> NULL;
> Â}
> Â
> -static struct property_entry *pset_prop_get(struct property_set
> *pset,
> - ÂÂÂÂconst char *name)
> +static const struct property_entry *pset_prop_get(struct property_set
> *pset,
> + ÂÂconst char *name)
> Â{
> - struct property_entry *prop;
> + const struct property_entry *prop;
> Â
> Â if (!pset || !pset->properties)
> Â return NULL;
> @@ -50,11 +50,11 @@ static struct property_entry *pset_prop_get(struct
> property_set *pset,
> Â return NULL;
> Â}
> Â
> -static void *pset_prop_find(struct property_set *pset, const char
> *propname,
> - ÂÂÂÂsize_t length)
> +static const void *pset_prop_find(struct property_set *pset,
> + ÂÂconst char *propname, size_t
> length)
> Â{
> - struct property_entry *prop;
> - void *pointer;
> + const struct property_entry *prop;
> + const void *pointer;
> Â
> Â prop = pset_prop_get(pset, propname);
> Â if (!prop)
> @@ -74,7 +74,7 @@ static int pset_prop_read_u8_array(struct
> property_set *pset,
> Â ÂÂÂconst char *propname,
> Â ÂÂÂu8 *values, size_t nval)
> Â{
> - void *pointer;
> + const void *pointer;
> Â size_t length = nval * sizeof(*values);
> Â
> Â pointer = pset_prop_find(pset, propname, length);
> @@ -89,7 +89,7 @@ static int pset_prop_read_u16_array(struct
> property_set *pset,
> Â ÂÂÂÂconst char *propname,
> Â ÂÂÂÂu16 *values, size_t nval)
> Â{
> - void *pointer;
> + const void *pointer;
> Â size_t length = nval * sizeof(*values);
> Â
> Â pointer = pset_prop_find(pset, propname, length);
> @@ -104,7 +104,7 @@ static int pset_prop_read_u32_array(struct
> property_set *pset,
> Â ÂÂÂÂconst char *propname,
> Â ÂÂÂÂu32 *values, size_t nval)
> Â{
> - void *pointer;
> + const void *pointer;
> Â size_t length = nval * sizeof(*values);
> Â
> Â pointer = pset_prop_find(pset, propname, length);
> @@ -119,7 +119,7 @@ static int pset_prop_read_u64_array(struct
> property_set *pset,
> Â ÂÂÂÂconst char *propname,
> Â ÂÂÂÂu64 *values, size_t nval)
> Â{
> - void *pointer;
> + const void *pointer;
> Â size_t length = nval * sizeof(*values);
> Â
> Â pointer = pset_prop_find(pset, propname, length);
> @@ -133,7 +133,7 @@ static int pset_prop_read_u64_array(struct
> property_set *pset,
> Âstatic int pset_prop_count_elems_of_size(struct property_set *pset,
> Â Âconst char *propname, size_t
> length)
> Â{
> - struct property_entry *prop;
> + const struct property_entry *prop;
> Â
> Â prop = pset_prop_get(pset, propname);
> Â if (!prop)
> @@ -146,7 +146,7 @@ static int pset_prop_read_string_array(struct
> property_set *pset,
> Â ÂÂÂÂÂÂÂconst char *propname,
> Â ÂÂÂÂÂÂÂconst char **strings, size_t
> nval)
> Â{
> - void *pointer;
> + const void *pointer;
> Â size_t length = nval * sizeof(*strings);
> Â
> Â pointer = pset_prop_find(pset, propname, length);
> @@ -160,8 +160,8 @@ static int pset_prop_read_string_array(struct
> property_set *pset,
> Âstatic int pset_prop_read_string(struct property_set *pset,
> Â Âconst char *propname, const char
> **strings)
> Â{
> - struct property_entry *prop;
> - const char **pointer;
> + const struct property_entry *prop;
> + const char * const *pointer;
> Â
> Â prop = pset_prop_get(pset, propname);
> Â if (!prop)
> @@ -867,7 +867,8 @@ EXPORT_SYMBOL_GPL(device_remove_properties);
> Â * @dev as its secondary firmware node. The function takes a copy of
> Â * @properties.
> Â */
> -int device_add_properties(struct device *dev, struct property_entry
> *properties)
> +int device_add_properties(struct device *dev,
> + ÂÂconst struct property_entry *properties)
> Â{
> Â struct property_set *p, pset;
> Â
> diff --git a/include/linux/property.h b/include/linux/property.h
> index f7fa5891a8c3..3aeb4d7acd68 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -245,7 +245,7 @@ struct property_entry *property_entries_dup(
> Â const struct property_entry
> *properties);
> Â
> Âint device_add_properties(struct device *dev,
> - ÂÂstruct property_entry *properties);
> + ÂÂconst struct property_entry *properties);
> Âvoid device_remove_properties(struct device *dev);
> Â
> Âbool device_dma_supported(struct device *dev);
--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy