device property: Add const qualifier to device_get_match_data() parameter
Subsystems (3)
Andy Shevchenko
reviewerPATCH 1/1 device property: Add const qualifier to device_get_match_data() parameter
Add const qualifier to the device_get_match_data() parameter. Some of the future users may utilize this function without forcing the type.
All the same, dev_fwnode() may be used with a const qualifier.
--- drivers/base/property.c | 4 ++-- include/linux/property.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/base/property.c +2 -2
@@ -17,7 +17,7 @@#include <linux/property.h> #include <linux/phy.h> -struct fwnode_handle *dev_fwnode (struct device *dev) +struct fwnode_handle *dev_fwnode (const struct device *dev) {return IS_ENABLED (CONFIG_OF ) && dev->of_node ?of_fwnode_handle (dev->of_node) : dev->fwnode;
@@ -1200,7 +1200,7 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, }EXPORT_SYMBOL (fwnode_graph_parse_endpoint); -const void *device_get_match_data (struct device *dev) +const void *device_get_match_data (const struct device *dev) {return fwnode_call_ptr_op (dev_fwnode (dev), device_get_match_data, dev); }
include/linux/property.h +2 -2
@@ -32,7 +32,7 @@ enum dev_dma_attr { DEV_DMA_COHERENT, }; -struct fwnode_handle *dev_fwnode (struct device *dev); +struct fwnode_handle *dev_fwnode (const struct device *dev);bool device_property_present (struct device *dev,const char *propname); int device_property_read_u8_array(struct device *dev, const char *propname,
@@ -387,7 +387,7 @@ bool device_dma_supported(struct device *dev);enum dev_dma_attr device_get_dma_attr (struct device *dev); -const void *device_get_match_data (struct device *dev); +const void *device_get_match_data (const struct device *dev);int device_get_phy_mode (struct device *dev);int fwnode_get_phy_mode (struct fwnode_handle *fwnode);
Signature · 1 line
2.35.1
Quoted 8 lines · Andy Shevchenko
Add const qualifier to the
device_get_match_data()parameter. Some of the future users may utilize this function without forcing the type.All the same,
dev_fwnode()may be used with a const qualifier.Reported-by kernel test robot <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 51 lines
--- drivers/base/property.c | 4 ++-- include/linux/property.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/base/property.c +2
-2@@ -17,7 +17,7 @@#include <linux/property.h> #include <linux/phy.h> -struct fwnode_handle *dev_fwnode (struct device *dev) +struct fwnode_handle *dev_fwnode (const struct device *dev) {return IS_ENABLED (CONFIG_OF ) && dev->of_node ?of_fwnode_handle (dev->of_node) : dev->fwnode;@@ -1200,7 +1200,7 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, }EXPORT_SYMBOL (fwnode_graph_parse_endpoint); -const void *device_get_match_data (struct device *dev) +const void *device_get_match_data (const struct device *dev) {return fwnode_call_ptr_op (dev_fwnode (dev), device_get_match_data, dev); }include/linux/property.h +2
-2@@ -32,7 +32,7 @@ enum dev_dma_attr { DEV_DMA_COHERENT, }; -struct fwnode_handle *dev_fwnode (struct device *dev); +struct fwnode_handle *dev_fwnode (const struct device *dev);bool device_property_present (struct device *dev,const char *propname); int device_property_read_u8_array(struct device *dev, const char *propname,@@ -387,7 +387,7 @@ bool device_dma_supported(struct device *dev);enum dev_dma_attr device_get_dma_attr (struct device *dev); -const void *device_get_match_data (struct device *dev); +const void *device_get_match_data (const struct device *dev);int device_get_phy_mode (struct device *dev);int fwnode_get_phy_mode (struct fwnode_handle *fwnode);Signature · 1 line
2.35.1
Signature · 1 line
heikki
Sakari Ailus
reviewerHi Andy,
Thanks for cc'ing me.
Quoted 3 lines · Andy Shevchenko
Add const qualifier to the
device_get_match_data()parameter. Some of the future users may utilize this function without forcing the type.
From const to non-const? This is what this patch does, right?
Quoted 15 lines
All the same,
dev_fwnode()may be used with a const qualifier.Reported-by kernel test robot <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/base/property.c | 4 ++-- include/linux/property.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/base/property.c +0
-0
drivers/base/property.c line 20
Quoted 5 lines
drivers/base/property.c +1
-1@@ -17,7 +17,7 @@#include <linux/property.h> #include <linux/phy.h> -struct fwnode_handle *dev_fwnode (struct device *dev) +struct fwnode_handle *dev_fwnode (const struct device *dev)
If you have const struct device pointer, then the embedded fwnode handle in that object sure is const, too. Isn't it?
If you really have const struct device pointer (where do you?), then I'd suggest to add another function, dev_fwnode_const() that is otherwise the same except the argument as well as the return value are const.
Or alternatively define it as a macro and use _Generic()?
Quoted 34 lines
drivers/base/property.c +1
-1{return IS_ENABLED (CONFIG_OF ) && dev->of_node ?of_fwnode_handle (dev->of_node) : dev->fwnode;@@ -1200,7 +1200,7 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, }EXPORT_SYMBOL (fwnode_graph_parse_endpoint); -const void *device_get_match_data (struct device *dev) +const void *device_get_match_data (const struct device *dev) {return fwnode_call_ptr_op (dev_fwnode (dev), device_get_match_data, dev); }include/linux/property.h +2
-2@@ -32,7 +32,7 @@ enum dev_dma_attr { DEV_DMA_COHERENT, }; -struct fwnode_handle *dev_fwnode (struct device *dev); +struct fwnode_handle *dev_fwnode (const struct device *dev);bool device_property_present (struct device *dev,const char *propname); int device_property_read_u8_array(struct device *dev, const char *propname,@@ -387,7 +387,7 @@ bool device_dma_supported(struct device *dev);enum dev_dma_attr device_get_dma_attr (struct device *dev); -const void *device_get_match_data (struct device *dev); +const void *device_get_match_data (const struct device *dev);int device_get_phy_mode (struct device *dev);int fwnode_get_phy_mode (struct fwnode_handle *fwnode);
Signature · 3 lines
Regards, Sakari Ailus
Andy Shevchenko
reviewerQuoted 6 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Add const qualifier to the
device_get_match_data()parameter. Some of the future users may utilize this function without forcing the type.From const to non-const? This is what this patch does, right?
Right.
Quoted 5 lines
Quoted 4 lines
All the same,
dev_fwnode()may be used with a const qualifier.Reported-by kernel test robot <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Quoted 7 lines
drivers/base/property.c line 20
Quoted 2 lines
drivers/base/property.c +1
-1-struct fwnode_handle *dev_fwnode (struct device *dev) +struct fwnode_handle *dev_fwnode (const struct device *dev)If you have const struct device pointer, then the embedded fwnode handle in that object sure is const, too. Isn't it?
If you really have const struct device pointer (where do you?), then I'd
device_get_match_data() expects the const parameter, but due to dev_fwnode() it can't be satisfied. This has been reported by LKP when I tried to submit a wrapper:
https://lore.kernel.org/linux-spi/[email protected]/
Yes, I probably can drop const there, but it will be again awkward to see almost all APIs beneath using const and upper one without it for unclear (to the reader) reasons.
Quoted 2 lines
suggest to add another function,
dev_fwnode_const()that is otherwise the same except the argument as well as the return value are const.
Perhaps this is the case, but does it mean we need to duplicate APIs when we know we don't modify data? Seems road to bloating the code for peanuts.
Quoted 1 line
Or alternatively define it as a macro and use
_Generic()?
Yeah, I have the mixed feelings about _Generic for generic APIs because it requires to convert some stuff to macros when type checking of the parameters can be missed (if a target takes two or more of them).
It might work here (we have a single parameter), but in general...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerHi Andy,
Quoted 23 lines · Andy Shevchenko
Quoted 6 lines · Sakari Ailus
Quoted 3 lines · Andy Shevchenko
Add const qualifier to the
device_get_match_data()parameter. Some of the future users may utilize this function without forcing the type.From const to non-const? This is what this patch does, right?
Right.
Quoted 5 lines
Quoted 4 lines
All the same,
dev_fwnode()may be used with a const qualifier.Reported-by kernel test robot <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>Quoted 7 lines
drivers/base/property.c line 20
Quoted 2 lines
drivers/base/property.c +1
-1-struct fwnode_handle *dev_fwnode (struct device *dev) +struct fwnode_handle *dev_fwnode (const struct device *dev)If you have const struct device pointer, then the embedded fwnode handle in that object sure is const, too. Isn't it?
If you really have const struct device pointer (where do you?), then I'd
Quoted 8 lines
device_get_match_data()expects the const parameter, but due todev_fwnode()it can't be satisfied. This has been reported by LKP when I tried to submit a wrapper:
https://lore.kernel.org/linux-spi/[email protected]/Yes, I probably can drop const there, but it will be again awkward to see almost all APIs beneath using const and upper one without it for unclear (to the reader) reasons.
dev could indeed be const there otherwise, I understand, but it's certainly not better to force it non-const elsewhere for that.
Quoted 4 lines
Quoted 3 lines
suggest to add another function,
dev_fwnode_const()that is otherwise the same except the argument as well as the return value are const.
Quoted 8 lines
Perhaps this is the case, but does it mean we need to duplicate APIs when we know we don't modify data? Seems road to bloating the code for peanuts.
Quoted 1 line
Or alternatively define it as a macro and use
_Generic()?Yeah, I have the mixed feelings about
_Genericfor generic APIs because it requires to convert some stuff to macros when type checking of the parameters can be missed (if a target takes two or more of them).
It's not uncommon to use wrapper functions in addition to get type checking done properly.
Quoted 2 lines
It might work here (we have a single parameter), but in general...
If it works here, why not to do it then? :-)
Signature · 1 line
Sakari Ailus