Skip to content

Commit

Permalink
device property: Allow const parameter to dev_fwnode()
Browse files Browse the repository at this point in the history
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.

Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Fixes: aade55c ("device property: Add const qualifier to device_get_match_data() parameter")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Link: https://lore.kernel.org/r/20221004092129.19412-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Andy Shevchenko authored and Greg Kroah-Hartman committed Oct 22, 2022
1 parent 3d24903 commit b295d48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions drivers/base/property.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion include/linux/property.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b295d48

Please sign in to comment.