On Thu, Feb 22, 2024 at 08:22:48AM +0100, Uwe Kleine-König wrote: > Hello David, > > On Thu, Feb 22, 2024 at 05:32:10PM +1100, David Gibson wrote: > > On Fri, Feb 16, 2024 at 07:19:20PM +0100, Uwe Kleine-König wrote: > > > [...] > > > diff --git a/libfdt/fdt_overlay.c b/libfdt/fdt_overlay.c > > > index 5c0c3981b89d..914acc5b14a6 100644 > > > --- a/libfdt/fdt_overlay.c > > > +++ b/libfdt/fdt_overlay.c > > > @@ -520,6 +520,228 @@ static int overlay_fixup_phandles(void *fdt, void *fdto) > > > return 0; > > > } > > > > > > > All of these new functions could do with descriptive comments saying > > what they do (see the existing code for examples). > > Yeah, I was lazy. I didn't expect this patch to go in without comments > and avoided investing time documenting functions that maybe will change > in the course of the review-resend loop. :-) > > > > [...] > > > +static int overlay_update_node_conflicting_references(void *fdto, int tree_node, > > > + int fixup_node, > > > + uint32_t fdt_phandle, > > > + uint32_t fdto_phandle) > > > +{ > > > + int fixup_prop; > > > + int fixup_child; > > > + int ret; > > > + > > > + fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) { > > > + > > > > Extraneous blank line. > > > > > + const fdt32_t *fixup_val; > > > + const char *tree_val; > > > > libfdt style is to use tab indents, looks like most of this block has > > space indents instead. > > Huh, I'm surprised about myself that I didn't notice this alone. > > > > + > > > + /* > > > + * phandles to fixup can be unaligned. > > > + * > > > + * Use a memcpy for the architectures that do > > > + * not support unaligned accesses. > > > + */ > > > + memcpy(&adj_val, tree_val + poffset, sizeof(adj_val)); > > > > And here you can use fdt32_ld() which has unaligned access handling > > built in. > > I copied this from somewhere, so I guess there is some potential for > improvement in existing code. Will take a look. > > > > [...] > > > + > > > +static int overlay_prevent_phandle_overwrite_node(void *fdt, int fdtnode, > > > + void *fdto, int fdtonode) > > > > Maybe "overlay_resolve_phandle_conflict()" for a slightly shorter > > function name. > > Sounds good, wasn't too lucky with > overlay_prevent_phandle_overwrite_node() either. > > > > +{ > > > + uint32_t fdt_phandle, fdto_phandle; > > > + int fdtochild; > > > + > > > + fdt_phandle = fdt_get_phandle(fdt, fdtnode); > > > + fdto_phandle = fdt_get_phandle(fdto, fdtonode); > > > + > > > + if (fdt_phandle && fdto_phandle) { > > > + int ret; > > > + > > > + ret = overlay_adjust_local_conflicting_phandle(fdto, > > > + fdt_phandle, > > > + fdto_phandle); > > > + if (ret) > > > + return ret; > > > > So while, as you've seen, there can be conflicting phandles between > > the fdt and the fdto, within the fdto a particular phandle should only > > appear on a single node. If a phandle is duplicated across nodes > > witin a single fdto, you have bigger problems. Therefore, having > > found a conflict, you're already found the only place you need to > > change the phandle property itself - you don't need to scan the full > > fdto again. > > > > So I believe you can replace the above call with just setting the > > phandle property on fdtonode. > > Oh right! > > > > [...] > > > /** > > > * overlay_apply_node - Merges a node into the base device tree > > > * @fdt: Base Device Tree blob > > > @@ -824,18 +1046,26 @@ int fdt_overlay_apply(void *fdt, void *fdto) > > > if (ret) > > > goto err; > > > > > > + /* Increase all phandles in the fdto by delta */ > > > ret = overlay_adjust_local_phandles(fdto, delta); > > > if (ret) > > > goto err; > > > > > > + /* Adapt the phandle values in fdto to the above increase */ > > > ret = overlay_update_local_references(fdto, delta); > > > if (ret) > > > goto err; > > > > > > + /* Update fdto's phandles using symbols from fdt */ > > > ret = overlay_fixup_phandles(fdt, fdto); > > > if (ret) > > > goto err; > > > > > > + /* Don't overwrite phandles in fdt */ > > > + ret = overlay_prevent_phandle_overwrite(fdt, fdto); > > > + if (ret) > > > + goto err; > > > > I think this should go above overlay_fixup_phandles(), so that we're > > completing all the __local_fixups__ based adjustments before going to > > the __fixups__ based adjustments. > > This is only to please the reader, right? Or is there a corner case I > failed to see? Correct. At least as far as I've seen, too. > The feedback I removed in this mail I agree with. Expect a v3 soon. > > Thanks for your time to review my patch, > Uwe > -- 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