Re: [PATCH 1/3] ACPI: Make acpi_fwnode_handle safer

Sakari Ailus
2021-11-04T13:16:38Z

On Wed, Nov 03, 2021 at 06:55:17PM +0100, Rafael J. Wysocki wrote:
> On Wed, Nov 3, 2021 at 2:33 PM Sakari Ailus
> <sakari.ailus@linux.intel.com> wrote:
> >
> > Check that the fwnode argument passed to acpi_fwnode_handle is non-NULL,
> > and return NULL if it is, otherwise the fwnode. Thus the caller doesn't
> > have to ensure the argument is a valid non-NULL fwnode.
> >
> > Cc: stable@vger.kernel.org # v5.15 and up
>
> Why?
>
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>
> That's because you want to avoid a NULL check in the second patch and
> it adds a ton of redundant NULL checks all over the place.
>
> Like for example in include/acpi/acpi.h:
>
> #define ACPI_COMPANION_SET(dev, adev) set_primary_fwnode(dev, (adev) ? \
> acpi_fwnode_handle(adev) : NULL)
>
> You should at least get rid of this one.

I went through the users and it seems they don't actually even benefit from
this. So I'll drop the patch.

Most of these little macros are made safer that way but in this case it
seems callers have already acpi_device around, or do checks for other
purposes as well.

--
Sakari Ailus