Re: libfdt / fdt_check_node_offset_ with VALID_INPUT

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



On Wed, Aug 12, 2020 at 05:48:56PM +0200, Frank Mehnert wrote:
> Hi all,
> 
> I'm not sure if I found a bug or if I mis-use libfdt.
> 
> I have a valid Linux device tree in memory and want to recursively scan
> thru it. The device tree contains a root node and several subnodes.
> 
> First, I start with the root node:
> 
>   int root = fdt_next_node(fdt, -1, NULL);

Tangential aside: the offset of the root node is *always* 0, you don't
need to "find" it with code like this.

> Here, root is set to 0. Now I determine the offset of the first sub node:
> 
>   int subnode = fdt_first_subnode(fdt, root);
> 
> Here, subnode is either 0 if FDT_ASSUME_MASK contains ASSUME_VALID_INPUT
> or 164 (in my case) if FDT_ASSUME_MASK does not contain ASSUME_VALID_INPUT.

That certainly sounds like a bug.  Adding things to FDT_ASSUME_MASK
shouldn't change behaviour for valid inputs.

> As far as I understand, fdt_first_subnode() should not return the node
> offset of the current node if there are subnodes available.

That's correct.

> I think the problem origins at fdt_check_node_offset_() in fdt.c: If
> VALID_INPUT is set, the whole code in that function is skipped. If that
> flag is not set then fdt_next_tag(fdt, offset, &offset) is called and
> the resulting 'offset' is returned.
> 
> In other words, fdt_check_node_offset_() has a side effect which depends
> on the VALID_INPUT flag.

Right.  Looks like the problem is that the next if *looks* like just
an error/sanity check, which can_assume(VALID_INPUT) is bypassing.
However, it also has the fdt_next_tag() call which alters offset.

I was afraid of this sort of thing when we added the assumptions
stuff.  Really we need to be running the testsuite with different
assumptions masks, but it's fiddly to do.

Care to send a patch?

[Another aside: why are you using ASSUME_VALID_INPUT - it's really
only of value if you have to run your code in an *extremely* space
limited environment, I don't recommend it as a rule]

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