Re: [PATCH v2 2/2] software node: Fix software_node_get_reference_args() with index -1
From: Andy Shevchenko
Date: Mon Jun 29 2026 - 09:46:46 EST
On Mon, Jun 29, 2026 at 08:33:24PM +0800, Zijun Hu wrote:
> On 6/29/26 15:30, Andy Shevchenko wrote:
...
> >> who will use UINT_MAX ?
> >>
> >> This function is a interface function. the best fix should check
> >> input parameter @index and return -EINVAL if it is not expected?
> > And how do you know which index is allowed without doing that division?
> > Basically this patch does what you asked for: check input parameter for
> > the allowed range (which is dynamic, depending on the property length and
> > size of the reference structure.
>
> Introduce a common macro to limit the max reference handle count and put it
> in include/linux/fwnode.h with the following macro.
> #define NR_FWNODE_REFERENCE_ARGS 16
>
> OR introduce a macro for software node only.
The property can be still smaller that capacity. I agree that division is not
the best approach performance-wise, but in my eyes it makes less checks needed
to be done. Let's see what others think about this?
--
With Best Regards,
Andy Shevchenko