Re: [PATCH 1/2] device property: Add optional nargs_prop for get_reference_args

Andy Shevchenko
2025-04-08T08:37:25Z

On Mon, Apr 07, 2025 at 06:37:13PM -0400, Sean Anderson wrote:
> get_reference_args does not permit falling back to nargs when nargs_prop
> is missing. This makes it difficult to support older devicetrees where
> nargs_prop may not be present. Add support for this by converting nargs
> to a signed value. Where before nargs was ignored if nargs_prop was
> passed, now nargs is only ignored if it is strictly negative. When it is
> positive, nargs represents the fallback cells to use if nargs_prop is
> absent.

And what is the case to support old DTs on most likely outdated hardware?

...

> ret = fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop,
> - nargs, index, args);
> + nargs_prop ? -1 : nargs, index, args);

> return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, nargs_prop,
> - nargs, index, args);
> + nargs_prop ? -1 : nargs, index, args);

I don't understand why it's needed here. The nargs_prop is passed to the callee.

...

> - unsigned int nargs, unsigned int index,
> + int nargs, unsigned int index,

As per above.

...

> error = property_entry_read_int_array(ref->node->properties,
> nargs_prop, sizeof(u32),
> &nargs_prop_val, 1);
> - if (error)

> +

Stray blank line.

> + if (error == -EINVAL) {

Why do we need an explicit error code check? This is fragile. Just check the
parameter before calling the above.

> + if (nargs < 0)
> + return error;
> + } else if (error) {
> return error;
> -
> - nargs = nargs_prop_val;
> + } else {
> + nargs = nargs_prop_val;
> + }

...

> of_fwnode_get_reference_args(const struct fwnode_handle *fwnode,
> const char *prop, const char *nargs_prop,
> - unsigned int nargs, unsigned int index,
> + int nargs, unsigned int index,
> struct fwnode_reference_args *args)

Same comments as per above.

--
With Best Regards,
Andy Shevchenko