From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Hans de Goede <hdegoede@redhat.com>,
Wolfram Sang <wsa@the-dreams.de>
Subject: [PATCH v3 2/4] device property: allow to constify properties
Date: Wed, 1 Feb 2017 09:31:23 -0800 [thread overview]
Message-ID: <20170201173125.40354-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20170201173125.40354-1-dmitry.torokhov@gmail.com>
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: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
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 934845fc72e5..edc09854520b 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)
@@ -880,7 +880,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 48f154ae7e99..5746e9927016 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -247,7 +247,7 @@ property_entries_dup(const struct property_entry *properties);
void property_entries_free(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);
--
2.11.0.483.g087da7b7c-goog
next prev parent reply other threads:[~2017-02-01 17:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-01 17:31 [PATCH v3 0/4] Export APIs to copy device properties & more Dmitry Torokhov
2017-02-01 17:31 ` [PATCH v3 1/4] device property: export code duplicating array of property entries Dmitry Torokhov
2017-02-01 17:31 ` Dmitry Torokhov [this message]
2017-02-01 17:31 ` [PATCH v3 3/4] driver property: constify property arrays values Dmitry Torokhov
2017-02-01 23:30 ` Joe Perches
2017-02-02 11:24 ` Rafael J. Wysocki
2017-02-02 16:39 ` [PATCH v4 3/4] device " Dmitry Torokhov
2017-02-02 16:48 ` Andy Shevchenko
2017-02-02 17:07 ` Dmitry Torokhov
2017-02-02 17:52 ` Andy Shevchenko
2017-02-02 18:38 ` Dmitry Torokhov
2017-02-02 23:16 ` Rafael J. Wysocki
2017-02-03 0:16 ` Dmitry Torokhov
2017-02-03 0:37 ` Rafael J. Wysocki
2017-02-03 1:06 ` Dmitry Torokhov
2017-02-02 10:08 ` [PATCH v3 3/4] driver " Mika Westerberg
2017-02-01 17:31 ` [PATCH v3 4/4] i2c: allow specify device properties in i2c_board_info Dmitry Torokhov
2017-02-02 10:08 ` Mika Westerberg
2017-02-01 22:56 ` [PATCH v3 0/4] Export APIs to copy device properties & more Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170201173125.40354-3-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=rafael.j.wysocki@intel.com \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).