Hi Mehmet,

On 2026-10-07T14:45:38, Mehmet Fide <[email protected]> wrote:
> dm: core: add ofnode_get_alias_seq()
>
> The sequence number an aliases entry gives a node can only be looked up
> for a device, through dev_read_alias_seq(). A driver that has to know
> the number of a node it does not own, one it reached through a phandle
> for instance, has no livetree call for it and is left with fdtdec.
>
> Move the body of dev_read_alias_seq() to the ofnode level and let both
> of its variants call it. No functional change, so the moved lines keep
> the ENOTSUPP return, the #if and the fdtdec call they had, which is what
> checkpatch complains about here.

The checkpatch remark is for reviewers, not the commit log. Ideally
this would go below the --- line

>
> A test checks the lookup on the live and on the flat tree.
>
> Signed-off-by: Mehmet Fide <[email protected]>
>
> drivers/core/ofnode.c | 20 ++++++++++++++++++++
>  drivers/core/read.c   | 20 ++------------------
>  include/dm/ofnode.h   | 13 +++++++++++++
>  include/dm/read.h     |  8 ++------
>  test/dm/ofnode.c      | 20 ++++++++++++++++++++
>  5 files changed, 57 insertions(+), 24 deletions(-)

> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
> @@ -1233,6 +1233,26 @@ ofnode ofnode_get_aliases_node(const char *name)
> +     if (ofnode_is_np(node)) {
> +             ret = of_alias_get_id(ofnode_to_np(node), stem);
> +             if (ret >= 0) {
> +                     *seqp = ret;
> +                     ret = 0;
> +             }
> +     } else {
> +#if CONFIG_IS_ENABLED(OF_CONTROL)
> +             ret = fdtdec_get_alias_seq(ofnode_to_fdt(node), stem,
> +                                        ofnode_to_offset(node), seqp);
> +#endif

The two branches handle the stem differently. of_alias_get_id() does a
strcmp() against the stem split off by of_alias_scan(), so the stem
must match exactly. fdtdec_get_alias_seq() just does strncmp(name,
base, base_len) and then trailing_strtol(), so any alias starting with
the stem matches. For example,
ofnode_get_alias_seq(ofnode_path("/some-bus"), "test", &seq) returns 0
with seq = 3 on the flat tree (from testbus3) but -ENODEV on the live
tree.

This was mostly hidden while the only caller passed a uclass name for
the device's own node. Now that the function is public and works on
any node it matters, and patch 5 depends on it: it passes
dev->uclass->uc_drv->name, i.e. 'usb', for the PHY node whose alias is
'usbphy0'. That works on colibri_vf with the flat tree only because of
the prefix match, and would fail with OF_LIVE. I think patch 5 should
pass 'usbphy'.

Please can you also say in the header comment that the stem must match
exactly, and add a negative test with a prefix stem like the one
above, so the two implementations are tested against each other?
Making fdtdec_get_alias_seq() check that the stem is followed by a
digit would be a separate fix, but worth doing. What do you think?

> diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
> @@ -523,6 +523,26 @@ static int dm_test_ofnode_read_aliases(struct 
> unit_test_state *uts)
> +     ut_assert(ofnode_get_alias_seq(ofnode_path("/i2c@0"), "spi", &seq) < 0);
> +     ut_assert(ofnode_get_alias_seq(ofnode_path("/some-bus"), "testfdt",
> +                                    &seq) < 0);

Since the flat path now uses ofnode_to_fdt() rather than gd->fdt_blob,
it would be good to also check a node in another tree, i.e. a variant
using oftree_path() with UTF_OTHER_FDT, like the other *_ot tests in
this file.

Regards,
Simon

Reply via email to