Re: [PATCH 5/9] of: property: implement the .property_get_names() fwnode operation

From: Bartosz Golaszewski

Date: Tue Nov 10 2026 - 09:26:31 EST


On Tue, Nov 10, 2026 at 12:51:53PM +0200, Andy Shevchenko wrote:
> On Tue, Nov 10, 2026 at 11:50 AM Bartosz Golaszewski <brgl@xxxxxxxxxx> wrote:
> > On Tue, Nov 10, 2026 at 11:12:02AM +0200, Andy Shevchenko wrote:
> > > On Tue, Nov 10, 2026 at 11:00 AM Bartosz Golaszewski <brgl@xxxxxxxxxx> wrote:
> > > > On Mon, Nov 09, 2026 at 07:28:33PM +0200, Andy Shevchenko wrote:
> > > > > On Mon, Nov 09, 2026 at 02:07:46PM +0100, Bartosz Golaszewski wrote:
> > > > > > On Wed, Nov 04, 2026 at 11:21:15PM +0200, Andy Shevchenko wrote:
> > > > > > > On Wed, Nov 04, 2026 at 03:03:47PM +0100, Bartosz Golaszewski wrote:
>
> ...
>
> > > > PS: is there a way of using match_string() with non-const data?
> > >
> > > Why? It's an input parameter, it returns an index. Whatever you
> > > provide will be not modified.
>
>
> > What I mean is that the following change
>
> > + ret = match_string(merged, n1, sec_props.array[i]);
> > + if (ret >= n1) {
> > merged[count++] = sec_props.array[i];
> > sec_props.array[i] = NULL;
> > }
> >
> > Results in:
>
> > drivers/base/property.c: In function ‘fwnode_property_get_names’:
> > drivers/base/property.c:607:36: error: passing argument 1 of ‘match_string’ from incompatible pointer type [-Wincompatible-pointer-types]
>
> > And I don't see a good way of working around it without doing:
> >
> > match_string((const char *const)merged, n1, sec_props.array[i]));
> >
> > which is ugly.
>
> Ah, got it! But why is the "merges" char ** and not char * const *? I
> believe that will fix the issue.

Then you won't be able to assign dynamically allocated strings from
prim_props and sec_props to members of "merged".

CC drivers/base/property.o
drivers/base/property.c: In function ‘fwnode_property_get_names’:
drivers/base/property.c:601:27: error: assignment of read-only location ‘*(merged + (sizetype)((long unsigned int)i * 8))’
601 | merged[i] = prim_props.array[i];
| ^
drivers/base/property.c:614:41: error: assignment of read-only location ‘*(merged + (sizetype)((long unsigned int)count++ * 8))’
614 | merged[count++] = sec_props.array[i];
| ^
drivers/base/property.c:619:16: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
619 | *props = merged;
| ^
make[4]: *** [scripts/Makefile.build:321: drivers/base/property.o] Error 1
make[3]: *** [scripts/Makefile.build:603: drivers/base] Error 2
make[2]: *** [scripts/Makefile.build:603: drivers] Error 2

This is where we could use kstrdup_const() but we'd have to keep track
of these strings now in error paths and that complicated things. I'll
just keep the existing loop I have.

The alternative is of course relaxing match_string() or introducing a
non-const variant or even hiding the variant behind a macro using
_Generic(). But that's work for another series I think.

Bart