Re: [PATCH 07/21] of: port Linux of_get_compatible_child helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 13, 2020 at 09:51:50AM +0200, Ahmad Fatoum wrote:
> Incoming Linux code port makes use of the helper. Add it now instead of
> having to open-code it later.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---
>  drivers/of/base.c | 25 +++++++++++++++++++++++++
>  include/of.h      |  8 ++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 346d72e1e09e..5a0374a82c5c 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1712,6 +1712,31 @@ int of_get_available_child_count(const struct device_node *parent)
>  }
>  EXPORT_SYMBOL(of_get_available_child_count);
>  
> +/**
> + * of_get_compatible_child - Find compatible child node
> + * @parent:	parent node
> + * @compatible:	compatible string
> + *
> + * Lookup child node whose compatible property contains the given compatible
> + * string.
> + *
> + * Returns a node pointer with refcount incremented, use of_node_put() on it
> + * when done; or NULL if not found.
> + */
> +struct device_node *of_get_compatible_child(const struct device_node *parent,
> +				const char *compatible)
> +{
> +	struct device_node *child;
> +
> +	for_each_child_of_node(parent, child) {
> +		if (of_device_is_compatible(child, compatible))
> +			break;
> +	}

for_each_child_of_node() goes down to list_for_each_entry(). On an empty
list child will point to the list head after leaving the loop. Return
child explicitly when it's compatible and NULL when leaving the loop
which is better readable as well.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux