[PATCH 1/2] of: base: factor out duplication for property formatting

Sascha Hauer sha at pengutronix.de
Mon Aug 8 04:18:49 PDT 2022


On Mon, Aug 08, 2022 at 08:56:38AM +0200, Ahmad Fatoum wrote:
> We have the same chunk of code with minuscule difference in both
> __of_print_nodes and __of_print_property. Factor it out to simplify
> the follow-up commit.
> 
> No functional change.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/of/base.c | 33 +++++++++++++++++++--------------
>  1 file changed, 19 insertions(+), 14 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 101b2f74c74f..ac5a14f49919 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2006,6 +2006,22 @@ int of_property_read_string_helper(const struct device_node *np,
>  	return i <= 0 ? -ENODATA : i;
>  }
>  
> +static void __of_print_property_prefixed(const struct property *p, int indent,
> +					 const char *prefix)
> +{
> +	unsigned length;
> +
> +	printf("%s%*s%s", prefix, indent * 8, "", p->name);
> +
> +	length = p->length;
> +	if (length) {
> +		printf(" = ");
> +		of_print_property(of_property_get_value(p), length);
> +	}
> +
> +	printf(";\n");
> +}
> +
>  static int __of_print_nodes(struct device_node *node, int indent, const char *prefix)
>  {
>  	struct device_node *n;
> @@ -2020,14 +2036,8 @@ static int __of_print_nodes(struct device_node *node, int indent, const char *pr
>  
>  	printf("%s%*s%s%s\n", prefix, indent * 8, "", node->name, node->name ? " {" : "{");
>  
> -	list_for_each_entry(p, &node->properties, list) {
> -		printf("%s%*s%s", prefix, (indent + 1) * 8, "", p->name);
> -		if (p->length) {
> -			printf(" = ");
> -			of_print_property(of_property_get_value(p), p->length);
> -		}
> -		printf(";\n");
> -	}
> +	list_for_each_entry(p, &node->properties, list)
> +		__of_print_property_prefixed(p, indent + 1, prefix);
>  
>  	if (ctrlc())
>  		return -EINTR;
> @@ -2049,12 +2059,7 @@ void of_print_nodes(struct device_node *node, int indent)
>  
>  static void __of_print_property(struct property *p, int indent)
>  {
> -	printf("%*s%s", indent * 8, "", p->name);
> -	if (p->length) {
> -		printf(" = ");
> -		of_print_property(of_property_get_value(p), p->length);
> -	}
> -	printf(";\n");
> +	__of_print_property_prefixed(p, indent, "");
>  }
>  
>  void of_print_properties(struct device_node *node)
> -- 
> 2.30.2
> 
> 
> 

-- 
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 |



More information about the barebox mailing list