Re: [PATCH v1 2/6] device property: Add fwnode_property_match_property_string()

From: Andy Shevchenko
Date: Thu Aug 10 2023 - 09:27:11 EST


On Wed, Aug 09, 2023 at 06:59:44PM +0100, Jonathan Cameron wrote:
> On Tue, 8 Aug 2023 19:27:56 +0300
> Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:

...

> > +int fwnode_property_match_property_string(const struct fwnode_handle *fwnode,
> > + const char *propname, const char * const *array, size_t n)
>
> Hi Andy,
>
> Whilst I'm not 100% sold on adding ever increasing complexity to what we
> match, this one feels like a common enough thing to be worth providing.

Yep, that's why I considered it's good to add (and because of new comers).

> Looking at the usecases I wonder if it would be better to pass in
> an unsigned int *ret which is only updated on a match?

So the question is here are we going to match (pun intended) the prototype to
the device_property_match*() family of functions or to device_property_read_*()
one. If the latter, this has to be renamed, but then it probably will contradict
the semantics as we are _matching_ against something and not just _reading_
something.

That said, do you agree that current implementation is (slightly) better from
these aspects? Anyway, look at the below.

> That way the common properties approach of not checking the return value
> if we have an optional property would apply.
>
> e.g. patch 3

Only?

> would end up with a block that looks like:
>
> st->input_mode = ADMV1014_IQ_MODE;
> device_property_match_property_string(&spi->dev, "adi,input-mode",
> input_mode_names,
> ARRAY_SIZE(input_mode_names),
> &st->input_mode);
>
> Only neat and tidy if the thing being optionally read into is an unsigned int
> though (otherwise you still need a local variable)

We also can have a hybrid variant, returning in both sides

int device_property_match_property_string(..., size_t *index)
{
if (index)
*index = ret;
return ret;
}

(also note the correct return type as it has to match to @n).

Would it be still okay or too over engineered?

--
With Best Regards,
Andy Shevchenko