diff mbox series

[net-next:,v4,5/8] device property: introduce fwnode_find_parent_dev_match

Message ID 20230116173420.1278704-6-mw@semihalf.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series DSA: switch to fwnode_/device_ | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8866 this patch: 8866
netdev/cc_maintainers warning 7 maintainers not CCed: gregkh@linuxfoundation.org djrscally@gmail.com heikki.krogerus@linux.intel.com sakari.ailus@linux.intel.com linux-mediatek@lists.infradead.org matthias.bgg@gmail.com linux-arm-kernel@lists.infradead.org
netdev/build_clang success Errors and warnings before: 2486 this patch: 2486
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9603 this patch: 9603
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 5 this patch: 5
netdev/source_inline success Was 0 now: 0

Commit Message

Marcin Wojtas Jan. 16, 2023, 5:34 p.m. UTC
Add a new generic routine fwnode_find_parent_dev_match that can be used
e.g. as a callback for class_find_device(). It searches for the struct
device corresponding to a struct fwnode_handle by iterating over device
and its parents.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
---
 include/linux/property.h |  1 +
 drivers/base/property.c  | 23 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Andy Shevchenko Jan. 16, 2023, 6 p.m. UTC | #1
On Mon, Jan 16, 2023 at 06:34:17PM +0100, Marcin Wojtas wrote:
> Add a new generic routine fwnode_find_parent_dev_match that can be used
> e.g. as a callback for class_find_device(). It searches for the struct
> device corresponding to a struct fwnode_handle by iterating over device
> and its parents.

If it helps you, I have no objections, hence
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
> ---
>  include/linux/property.h |  1 +
>  drivers/base/property.c  | 23 ++++++++++++++++++++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/include/linux/property.h b/include/linux/property.h
> index 37179e3abad5..4ae20d7c5103 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -109,6 +109,7 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode);
>  unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
>  struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
>  					    unsigned int depth);
> +int fwnode_find_parent_dev_match(struct device *dev, const void *data);
>  bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child);
>  struct fwnode_handle *fwnode_get_next_child_node(
>  	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index bbb3e499ff4a..84849d4934cc 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -693,6 +693,29 @@ struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode,
>  }
>  EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
>  
> +/**
> + * fwnode_find_parent_dev_match - look for a device matching the struct fwnode_handle
> + * @dev: the struct device to initiate the search
> + * @data: pointer passed for comparison
> + *
> + * Looks up the device structure corresponding with the fwnode by iterating
> + * over @dev and its parents.
> + * The routine can be used e.g. as a callback for class_find_device().
> + *
> + * Returns: %1 - match is found
> + *          %0 - match not found
> + */
> +int fwnode_find_parent_dev_match(struct device *dev, const void *data)
> +{
> +	for (; dev; dev = dev->parent) {
> +		if (device_match_fwnode(dev, data))
> +			return 1;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(fwnode_find_parent_dev_match);
> +
>  /**
>   * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child
>   * @ancestor: Firmware which is tested for being an ancestor
> -- 
> 2.29.0
>
diff mbox series

Patch

diff --git a/include/linux/property.h b/include/linux/property.h
index 37179e3abad5..4ae20d7c5103 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -109,6 +109,7 @@  struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode);
 unsigned int fwnode_count_parents(const struct fwnode_handle *fwn);
 struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwn,
 					    unsigned int depth);
+int fwnode_find_parent_dev_match(struct device *dev, const void *data);
 bool fwnode_is_ancestor_of(struct fwnode_handle *ancestor, struct fwnode_handle *child);
 struct fwnode_handle *fwnode_get_next_child_node(
 	const struct fwnode_handle *fwnode, struct fwnode_handle *child);
diff --git a/drivers/base/property.c b/drivers/base/property.c
index bbb3e499ff4a..84849d4934cc 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -693,6 +693,29 @@  struct fwnode_handle *fwnode_get_nth_parent(struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_get_nth_parent);
 
+/**
+ * fwnode_find_parent_dev_match - look for a device matching the struct fwnode_handle
+ * @dev: the struct device to initiate the search
+ * @data: pointer passed for comparison
+ *
+ * Looks up the device structure corresponding with the fwnode by iterating
+ * over @dev and its parents.
+ * The routine can be used e.g. as a callback for class_find_device().
+ *
+ * Returns: %1 - match is found
+ *          %0 - match not found
+ */
+int fwnode_find_parent_dev_match(struct device *dev, const void *data)
+{
+	for (; dev; dev = dev->parent) {
+		if (device_match_fwnode(dev, data))
+			return 1;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(fwnode_find_parent_dev_match);
+
 /**
  * fwnode_is_ancestor_of - Test if @ancestor is ancestor of @child
  * @ancestor: Firmware which is tested for being an ancestor