Re: [PATCH v5 2/9] of: update /aliases lookup on reconfig notifications

From: Geert Uytterhoeven

Date: Wed Aug 05 2026 - 04:34:30 EST


Hi Abdurrahman,

On Thu, 23 Jul 2026 at 05:19, Abdurrahman Hussain
<abdurrahman@xxxxxxxxxx> wrote:
> Aliases added by overlays never make it into aliases_lookup, which is
> only filled by of_alias_scan() at boot. of_alias_get_id() returns
> -ENODEV for them and drivers using alias based numbering (i2c, spi,
> tty, mmc) fall back to dynamic ids.
>
> Register a reconfig notifier and mirror /aliases property changes
> into aliases_lookup. The notifier chain covers changesets and
> overlays, so no overlay specific hook is needed. Same approach as
> Geert's 2015 series [1], which was never reposted;
> of_alias_create()/of_alias_destroy() keep its names.
>
> The /aliases node is matched by name and root parent instead of the
> of_aliases pointer, which is still NULL when an overlay creates the
> node on a system without a boot-time /aliases. The name match is
> exact, of_node_name_eq() would also match "aliases@1". ATTACH stores
> the node in of_aliases with a reference held, DETACH drops it again
> and flushes aliases_lookup; the pointer updates happen under
> devtree_lock to pair with the reader in of_find_node_opts_by_path().
> Nodes attached with properties already set are not scanned, as
> before.
>
> Lookup entries are created by of_alias_scan()'s old loop body, moved
> into of_alias_create(). Entries created at runtime have kstrdup'ed
> names and an of_node_get'ed target and are flagged "owned" so
> of_alias_destroy() knows what to kfree(); boot entries live in
> memblock and are only unlinked. Removal matches entries regardless of
> ownership so updating a boot-time alias does not leave duplicates
> behind, which was Grant's main concern on the old series [2].
>
> A new aliases_mutex protects the list. of_mutex does not work here:
> the notifier runs under it on the overlay path but outside of it on
> the of_add_property() path.

Thanks for your patch!

> The rework also fixes an out-of-bounds read in the old stem parser,
> which tested isdigit(*(end - 1)) before checking end > start and so
> read one byte before the property name when the name was empty or all
> digits. Such names are skipped now instead of getting an empty stem.

I think this part should be a separate patch.

> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c

> @@ -1960,42 +2124,8 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
> if (!of_aliases)
> return;
>
> - for_each_property_of_node(of_aliases, pp) {
> - const char *start = pp->name;
> - const char *end = start + strlen(start);

[...]

> - /* walk the alias backwards to extract the id and work out
> - * the 'stem' string */
> - while (isdigit(*(end-1)) && end > start)
> - end--;
> - len = end - start;
> -


Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds