Re: [PATCH 09/17] overlay: only apply compatible trees

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

 




On 10.03.21 14:28, Sascha Hauer wrote:
> This adds support for a global.of_overlay_compatible variable which is a
> space separated list of compatible strings. Device tree overlays not
> matching any won't be applied (unless the overlay doesn't have a
> compatible property at all).
> 
> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> ---
>  drivers/of/overlay.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
> index 8f4ee3f0a2..7a89cbe948 100644
> --- a/drivers/of/overlay.c
> +++ b/drivers/of/overlay.c
> @@ -11,6 +11,9 @@
>  #include <common.h>
>  #include <of.h>
>  #include <errno.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
> +#include <string.h>
>  
>  static struct device_node *find_target(struct device_node *root,
>  				       struct device_node *fragment)
> @@ -160,6 +163,33 @@ static int of_overlay_apply_fragment(struct device_node *root,
>  	return of_overlay_apply(target, overlay);
>  }
>  
> +static char *of_overlay_compatible;
> +
> +static bool of_overlay_is_compatible(struct device_node *ovl)
> +{
> +	char *p, *n, *compatibles;
> +	bool res = false;
> +
> +	if (!of_overlay_compatible || !*of_overlay_compatible)
> +		return true;
> +	if (!of_find_property(ovl, "compatible", NULL))
> +		return true;
> +
> +	p = compatibles = xstrdup(of_overlay_compatible);
> +
> +	while ((n = strsep_unescaped(&p, " "))) {

This returns an empty string when two delimiters are in a row and it seems
of_device_is_compatible will return true when comparing with the empty
string. Probably not what you want here.

> +		if (of_device_is_compatible(ovl, n)) {
> +			res = true;
> +			break;
> +		}
> +	}
> +
> +	free(compatibles);
> +
> +	return res;
> +}
> +
> +
>  /**
>   * Apply the overlay on the passed devicetree root
>   * @root: the devicetree onto which the overlay will be applied
> @@ -172,6 +202,9 @@ int of_overlay_apply_tree(struct device_node *root,
>  	struct device_node *fragment;
>  	int err = 0;
>  
> +	if (!of_overlay_is_compatible(overlay))
> +		return -ENODEV;
> +
>  	resolved = of_resolve_phandles(root, overlay);
>  	if (!resolved)
>  		return -EINVAL;
> @@ -250,3 +283,13 @@ int of_register_overlay(struct device_node *overlay)
>  {
>  	return of_register_fixup(of_overlay_fixup, overlay);
>  }
> +
> +static int of_overlay_init(void)
> +{
> +	globalvar_add_simple_string("of_overlay_compatible", &of_overlay_compatible);
> +
> +	return 0;
> +}
> +device_initcall(of_overlay_init);
> +
> +BAREBOX_MAGICVAR(global.of_overlay_compatible, "space separated list of compatibles an overlay must match");
> 

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