device property: Consitify a few APIs and
Subsystems (5)
Andy Shevchenko
reviewerv3 cover device property: Consitify a few APIs and
The property.h has inconsistency in how we annotate the parameters which are not modified anyhow by the certain APIs. Also dev_fwnode() needs to be rectified in sense of the handling const qualifier.
This series improves the above with only a couple of APIs left for now untouched (PHY, which I believe doesn't belong to property.h to begin with).
Changelog v3:
- used _Generic() to hide the _const API (Sakari, Greg)
Changelog v2:
- fixed USB Type-C compilation issues (LKP)
- added tags (Sakari, Heikki)
Andy Shevchenko (5):
device property: Allow const parameter to dev_fwnode() device property: Constify fwnode connection match APIs device property: Constify parameter in fwnode_graph_is_endpoint() device property: Constify device child node APIs device property: Constify parameter in device_dma_supported() and
device_get_dma_attr()
drivers/base/property.c | 29 ++++++++++++++++++----------- drivers/usb/roles/class.c | 2 +- drivers/usb/typec/mux.c | 8 ++++---- drivers/usb/typec/retimer.c | 2 +- include/linux/property.h | 34 +++++++++++++++++++--------------- 5 files changed, 43 insertions(+), 32 deletions(-)
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerPATCH v3 1/5 device property: Allow const parameter to dev_fwnode()
It's not fully correct to take a const parameter pointer to a struct and return a non-const pointer to a member of that struct.
Instead, introduce a const version of the dev_fwnode() API which takes and returns const pointers and use it where it's applicable.
With this, convert dev_fwnode() to be a macro wrapper on top of const and non-const APIs that chooses one based on the type.
--- drivers/base/property.c | 11 +++++++++-- include/linux/property.h | 7 ++++++- 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/base/property.c +9 -2
@@ -17,12 +17,19 @@#include <linux/property.h> #include <linux/phy.h> -struct fwnode_handle *dev_fwnode (const struct device *dev) +struct fwnode_handle *__dev_fwnode (struct device *dev) {return IS_ENABLED (CONFIG_OF ) && dev->of_node ?of_fwnode_handle (dev->of_node) : dev->fwnode; } -EXPORT_SYMBOL_GPL (dev_fwnode); +EXPORT_SYMBOL_GPL (__dev_fwnode); + +const struct fwnode_handle *__dev_fwnode_const (const struct device *dev) +{ +return IS_ENABLED (CONFIG_OF ) && dev->of_node ? +of_fwnode_handle (dev->of_node) : dev->fwnode; +} +EXPORT_SYMBOL_GPL (__dev_fwnode_const);/** * device_property_present - check if a property of a device is present
include/linux/property.h +6 -1
@@ -32,7 +32,12 @@ enum dev_dma_attr { DEV_DMA_COHERENT, }; -struct fwnode_handle *dev_fwnode (const struct device *dev); +const struct fwnode_handle *__dev_fwnode_const (const struct device *dev); +struct fwnode_handle *__dev_fwnode (struct device *dev); +#define dev_fwnode (dev) \ + _Generic((dev), \ + const struct device *: __dev_fwnode_const, \ + struct device *: __dev_fwnode)(dev)bool device_property_present (struct device *dev,const char *propname); int device_property_read_u8_array(struct device *dev, const char *propname,
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerRe: [PATCH v3 1/5] device property: Allow const parameter to dev_fwnode()
Quoted 8 lines · Andy Shevchenko
It's not fully correct to take a const parameter pointer to a struct and return a non-const pointer to a member of that struct.
Instead, introduce a const version of the
dev_fwnode()API which takes and returns const pointers and use it where it's applicable.With this, convert
dev_fwnode()to be a macro wrapper on top of const and non-const APIs that chooses one based on the type.
Hmm... it missed the device_get_match_data() implementation (reverse) change somehow. And it still compiles to me, probably I rebased wrongly and the hunk went to another patch. I'll investigate and resend as v4 the fixed version.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [PATCH v3 1/5] device property: Allow const parameter to dev_fwnode()
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Andy Shevchenko
It's not fully correct to take a const parameter pointer to a struct and return a non-const pointer to a member of that struct.
Instead, introduce a const version of the
dev_fwnode()API which takes and returns const pointers and use it where it's applicable.
Quoted 6 lines
Quoted 2 lines
With this, convert
dev_fwnode()to be a macro wrapper on top of const and non-const APIs that chooses one based on the type.Hmm... it missed the
device_get_match_data()implementation (reverse) change somehow. And it still compiles to me, probably I rebased wrongly and the hunk went to another patch. I'll investigate and resend as v4 the fixed version.
Ah, sorry, I mixed this with previous version of the patch here, so everything is fine in v3!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerPATCH v3 2/5 device property: Constify fwnode connection match APIs
In reply to Andy ShevchenkoThe fwnode and device parameters are not altered in the fwnode connection match APIs, constify them.
--- drivers/base/property.c | 8 ++++---- drivers/usb/roles/class.c | 2 +- drivers/usb/typec/mux.c | 8 ++++---- drivers/usb/typec/retimer.c | 2 +- include/linux/property.h | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-)
drivers/base/property.c +4 -4
@@ -1213,7 +1213,7 @@ const void *device_get_match_data(const struct device *dev) }EXPORT_SYMBOL_GPL (device_get_match_data); -static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode, +static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match, void **matches,
@@ -1247,7 +1247,7 @@ static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode,return count; } -static unsigned int fwnode_devcon_matches(struct fwnode_handle *fwnode, +static unsigned int fwnode_devcon_matches(const struct fwnode_handle *fwnode, const char *con_id, void *data, devcon_match_fn_t match, void **matches,
@@ -1289,7 +1289,7 @@ static unsigned int fwnode_devcon_matches(struct fwnode_handle *fwnode,* device node. @match will be used to convert the connection description to * data the caller is expecting to be returned. */ -void *fwnode_connection_find_match (struct fwnode_handle *fwnode, +void *fwnode_connection_find_match (const struct fwnode_handle *fwnode,const char *con_id,void *data,devcon_match_fn_t match) {
@@ -1326,7 +1326,7 @@ EXPORT_SYMBOL_GPL(fwnode_connection_find_match);* * Return: Number of matches resolved, or negative errno. */ -int fwnode_connection_find_matches (struct fwnode_handle *fwnode, +int fwnode_connection_find_matches (const struct fwnode_handle *fwnode,const char *con_id,void *data,devcon_match_fn_t match,void **matches,unsigned int matches_len)
drivers/usb/roles/class.c +1 -1
@@ -87,7 +87,7 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) }EXPORT_SYMBOL_GPL (usb_role_switch_get_role); -static void *usb_role_switch_match (struct fwnode_handle *fwnode,const char *id, +static void *usb_role_switch_match (const struct fwnode_handle *fwnode,const char *id,void *data) {struct device *dev;
drivers/usb/typec/mux.c +4 -4
@@ -32,8 +32,8 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode)return dev_fwnode (dev) == fwnode; } -static void *typec_switch_match (struct fwnode_handle *fwnode,const char *id, -void *data) +static void *typec_switch_match (const struct fwnode_handle *fwnode, +const char *id,void *data) {struct device *dev;
@@ -262,8 +262,8 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode)return dev_fwnode (dev) == fwnode; } -static void *typec_mux_match (struct fwnode_handle *fwnode,const char *id, -void *data) +static void *typec_mux_match (const struct fwnode_handle *fwnode, +const char *id,void *data) {const struct typec_altmode_desc *desc = data;struct device *dev;
drivers/usb/typec/retimer.c +1 -1
@@ -34,7 +34,7 @@ static int retimer_fwnode_match(struct device *dev, const void *fwnode)return dev_fwnode (dev) == fwnode &&dev_name_ends_with (dev,"-retimer" ); } -static void *typec_retimer_match (struct fwnode_handle *fwnode,const char *id,void *data) +static void *typec_retimer_match (const struct fwnode_handle *fwnode,const char *id,void *data) {struct device *dev;
include/linux/property.h +4 -4
@@ -442,21 +442,21 @@ unsigned int fwnode_graph_get_endpoint_count(struct fwnode_handle *fwnode,int fwnode_graph_parse_endpoint (const struct fwnode_handle *fwnode,struct fwnode_endpoint *endpoint); -typedef void *(*devcon_match_fn_t )(struct fwnode_handle *fwnode,const char *id, +typedef void *(*devcon_match_fn_t )(const struct fwnode_handle *fwnode,const char *id,void *data); -void *fwnode_connection_find_match (struct fwnode_handle *fwnode, +void *fwnode_connection_find_match (const struct fwnode_handle *fwnode,const char *con_id,void *data,devcon_match_fn_t match); -static inline void *device_connection_find_match (struct device *dev, +static inline void *device_connection_find_match (const struct device *dev,const char *con_id,void *data,devcon_match_fn_t match) {return fwnode_connection_find_match (dev_fwnode (dev), con_id, data, match); } -int fwnode_connection_find_matches (struct fwnode_handle *fwnode, +int fwnode_connection_find_matches (const struct fwnode_handle *fwnode,const char *con_id,void *data,devcon_match_fn_t match,void **matches,unsigned int matches_len);
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerPATCH v3 3/5 device property: Constify parameter in fwnode_graph_is_endpoint()
In reply to Andy ShevchenkoConstify parameter in fwnode_graph_is_endpoint() since it doesn't alter anything related to it.
--- include/linux/property.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/property.h +1 -1
@@ -410,7 +410,7 @@ struct fwnode_handle *fwnode_graph_get_remote_port(struct fwnode_handle *fwnode_graph_get_remote_endpoint (const struct fwnode_handle *fwnode); -static inline bool fwnode_graph_is_endpoint (struct fwnode_handle *fwnode) +static inline bool fwnode_graph_is_endpoint (const struct fwnode_handle *fwnode) {return fwnode_property_present (fwnode,"remote-endpoint" ); }
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerPATCH v3 4/5 device property: Constify device child node APIs
In reply to Andy ShevchenkoThe device parameter is not altered in the device child node APIs, constify them.
--- drivers/base/property.c | 6 +++--- include/linux/property.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/base/property.c +3 -3
@@ -763,7 +763,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_available_child_node);* @dev: Device to find the next child node for. * @child: Handle to one of the device's child nodes or a null handle. */ -struct fwnode_handle *device_get_next_child_node (struct device *dev, +struct fwnode_handle *device_get_next_child_node (const struct device *dev,struct fwnode_handle *child) {const struct fwnode_handle *fwnode =dev_fwnode (dev);
@@ -800,7 +800,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_named_child_node);* @dev: Device to find the named child node for. * @childname: String to match child node name against. */ -struct fwnode_handle *device_get_named_child_node (struct device *dev, +struct fwnode_handle *device_get_named_child_node (const struct device *dev,const char *childname) {return fwnode_get_named_child_node (dev_fwnode (dev), childname);
@@ -859,7 +859,7 @@ EXPORT_SYMBOL_GPL(fwnode_device_is_available);* device_get_child_node_count - return the number of child nodes for device * @dev: Device to cound the child nodes for */ -unsigned int device_get_child_node_count (struct device *dev) +unsigned int device_get_child_node_count (const struct device *dev) {struct fwnode_handle *child;unsigned int count =0 ;
include/linux/property.h +6 -6
@@ -114,16 +114,16 @@ struct fwnode_handle *fwnode_get_next_available_child_node(for (child =fwnode_get_next_available_child_node (fwnode,NULL ); child;\ child =fwnode_get_next_available_child_node (fwnode, child)) -struct fwnode_handle *device_get_next_child_node( -struct device *dev,struct fwnode_handle *child); +struct fwnode_handle *device_get_next_child_node(const struct device *dev, +struct fwnode_handle *child);#define device_for_each_child_node (dev, child) \ for (child = device_get_next_child_node(dev, NULL); child; \ child = device_get_next_child_node(dev, child)) -struct fwnode_handle *fwnode_get_named_child_node ( -const struct fwnode_handle *fwnode,const char *childname); -struct fwnode_handle *device_get_named_child_node (struct device *dev, +struct fwnode_handle *fwnode_get_named_child_node (const struct fwnode_handle *fwnode, +const char *childname); +struct fwnode_handle *device_get_named_child_node (const struct device *dev,const char *childname);struct fwnode_handle *fwnode_handle_get (struct fwnode_handle *fwnode);
@@ -132,7 +132,7 @@ void fwnode_handle_put(struct fwnode_handle *fwnode);int fwnode_irq_get (const struct fwnode_handle *fwnode,unsigned int index);int fwnode_irq_get_byname (const struct fwnode_handle *fwnode,const char *name); -unsigned int device_get_child_node_count (struct device *dev); +unsigned int device_get_child_node_count (const struct device *dev);static inline bool device_property_read_bool (struct device *dev,const char *propname)
Signature · 1 line
2.35.1
Andy Shevchenko
reviewerPATCH v3 5/5 device property: Constify parameter in device_dma_supported() and device_get_dma_attr()
In reply to Andy ShevchenkoConstify parameter in device_dma_supported() and device_get_dma_attr() since they don't alter anything related to it.
--- drivers/base/property.c | 4 ++-- include/linux/property.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/base/property.c +2 -2
@@ -871,13 +871,13 @@ unsigned int device_get_child_node_count(const struct device *dev) }EXPORT_SYMBOL_GPL (device_get_child_node_count); -bool device_dma_supported (struct device *dev) +bool device_dma_supported (const struct device *dev) {return fwnode_call_bool_op (dev_fwnode (dev), device_dma_supported); }EXPORT_SYMBOL_GPL (device_dma_supported); -enum dev_dma_attr device_get_dma_attr (struct device *dev) +enum dev_dma_attr device_get_dma_attr (const struct device *dev) {if (!fwnode_has_op (dev_fwnode (dev), device_get_dma_attr))return DEV_DMA_NOT_SUPPORTED ;
include/linux/property.h +2 -3
@@ -388,9 +388,8 @@ property_entries_dup(const struct property_entry *properties);void property_entries_free (const struct property_entry *properties); -bool device_dma_supported (struct device *dev); - -enum dev_dma_attr device_get_dma_attr (struct device *dev); +bool device_dma_supported (const struct device *dev); +enum dev_dma_attr device_get_dma_attr (const struct device *dev);const void *device_get_match_data (const struct device *dev);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerQuoted 7 lines · Andy Shevchenko
The
property.hhas inconsistency in how we annotate the parameters which are not modified anyhow by the certain APIs. Alsodev_fwnode()needs to be rectified in sense of the handling const qualifier.This series improves the above with only a couple of APIs left for now untouched (PHY, which I believe doesn't belong to
property.hto begin with).
Looks sane at first glance. I'll look at it some more once 6.1-rc1 is out, thanks.
greg k-h
Greg Kroah-Hartman
maintainerQuoted 11 lines · Greg Kroah-Hartman
Quoted 7 lines · Andy Shevchenko
The
property.hhas inconsistency in how we annotate the parameters which are not modified anyhow by the certain APIs. Alsodev_fwnode()needs to be rectified in sense of the handling const qualifier.This series improves the above with only a couple of APIs left for now untouched (PHY, which I believe doesn't belong to
property.hto begin with).Looks sane at first glance. I'll look at it some more once 6.1-rc1 is out, thanks.
All now applied, thanks.,
greg k-h