Message ID | 20221004092129.19412-2-andriy.shevchenko@linux.intel.com (mailing list archive) |
---|---|
State | Accepted |
Commit | b295d484b97081feba72b071ffcb72fb4638ccfd |
Headers | show |
Series | device property: Consitify a few APIs and | expand |
On Tue, Oct 04, 2022 at 12:21:25PM +0300, Andy Shevchenko wrote: > 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.
On Tue, Oct 04, 2022 at 12:34:56PM +0300, Andy Shevchenko wrote: > On Tue, Oct 04, 2022 at 12:21:25PM +0300, Andy Shevchenko wrote: > > 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. Ah, sorry, I mixed this with previous version of the patch here, so everything is fine in v3!
diff --git a/drivers/base/property.c b/drivers/base/property.c index 4d6278a84868..d77302d28566 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -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 diff --git a/include/linux/property.h b/include/linux/property.h index 117cc200c656..587b5b666b5b 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -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,