Re: [PATCH 1/1] Remove trailing zero from the overlay path

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



On Tue, Nov 05, 2019 at 10:09:52AM +0200, Stefan Mavrodiev wrote:
> When libfdt applies overlay, which has aliases, they are added to
> the __symbols__ node. Since the overlay path is string, it ends with
> trailing zero. However, when calculating path length, this symbol should
> be excluded. The effect is, that the property is threated as integer
> instead of string.
> 
> Here is a simple example. Using test/overlay_base:
> / {
>     test-node {
> 	...
>     };
>     __symbols__ {
>         test = "/test-node";
>         ...
>     };
> };
> 
> Compaling simple overlay with alias node:
> / {
>     fragment@0 {
>         target = <0xffffffff>;
>         __overlay__ {
>             foo {
>                 bar = "bar";
>                 phandle = <0x00000001>;
>             };
>         };
>     };
>     __symbols__ {
>         foo = "/fragment@0/__overlay__/foo";
>     };
>     __fixups__ {
>         test = "/fragment@0:target:0";
>     };
> };
> 
> After merge:
> / {
>    ...
>     __symbols__ {
>         foo = <0x2f746573 0x742d6e6f 0x64652f66 0x6f6f0000>;
>         ...
>     };
> };
> 
> You can see that the foo value is wrong. It's parsed as int, instead of string. Same
> test with the fix:
> 
> / {
>    ...
>     __symbols__ {
>         foo = "/test-node/foo";
>         ...
>     };
> };
> 
> Signed-off-by: Stefan Mavrodiev <stefan@xxxxxxxxxx>

LGTM, but it'd be great if you could add a test case for this as well.

> ---
>  libfdt/fdt_overlay.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libfdt/fdt_overlay.c b/libfdt/fdt_overlay.c
> index be71873..b310e49 100644
> --- a/libfdt/fdt_overlay.c
> +++ b/libfdt/fdt_overlay.c
> @@ -752,7 +752,7 @@ static int overlay_symbol_update(void *fdt, void *fdto)
>  		if ((e - s) > len && (memcmp(s, "/__overlay__/", len) == 0)) {
>  			/* /<fragment-name>/__overlay__/<relative-subnode-path> */
>  			rel_path = s + len;
> -			rel_path_len = e - rel_path;
> +			rel_path_len = e - rel_path - 1;
>  		} else if ((e - s) == len
>  			   && (memcmp(s, "/__overlay__", len - 1) == 0)) {
>  			/* /<fragment-name>/__overlay__ */

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux