Re: [PATCH v1] platform/x86: Check ACPI_COMPANION() against NULL during probe

From: Rafael J. Wysocki

Date: Tue May 12 2026 - 05:50:34 EST


On Tue, May 12, 2026 at 9:25 AM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> On Mon, May 11, 2026 at 09:48:26PM +0200, Rafael J. Wysocki wrote:
>
> > Every platform driver can be forced to match a device that doesn't match
> > its list of device IDs because of device_match_driver_override(), so
> > platform drivers that rely on the existence of a device's ACPI companion
> > object need to verify its presence.
> >
> > Accordingly, add requisite ACPI_COMPANION() or ACPI_HANDLE() checks
> > against NULL to multiple platform/x86 drivers that have been converted
> > to platform drivers from ACPI drivers recently.
>
> > Fixes: 578bc2a53ae2 ("platform/wmi: Convert drivers to use wmidev_invoke_procedure()")
> > Fixes: f7e648027d7e ("platform/x86: asus-wireless: Convert ACPI driver to a platform one")
> > Fixes: ba19eb10170b ("platform/x86: asus-laptop: Convert ACPI driver to a platform one")
> > Fixes: 3a96c7915d93 ("platform/x86: toshiba_haps: Convert ACPI driver to a platform one")
> > Fixes: 553b2ac59fbb ("platform/x86: toshiba_bluetooth: Convert ACPI driver to a platform one")
> > Fixes: 246d6cefe525 ("platform/x86: toshiba_acpi: Convert ACPI driver to a platform one")
> > Fixes: 19ebacfb442b ("platform/x86: dell/dell-rbtn: Convert ACPI driver to a platform one")
> > Fixes: 80b8f68b94ab ("platform/x86: system76: Convert ACPI driver to a platform one")
> > Fixes: de6837243af0 ("platform/x86: panasonic-laptop: Convert ACPI driver to a platform one")
> > Fixes: 6da22b031a3c ("platform/x86: fujitsu: Convert laptop driver to a platform one")
> > Fixes: d5c9212ccfaa ("platform/x86: fujitsu: Convert backlight driver to a platform one")
> > Fixes: bd13b265d386 ("platform/x86: fujitsu-tablet: Convert ACPI driver to a platform one")
> > Fixes: 8507277ef132 ("platform/x86: wireless-hotkey: Convert ACPI driver to a platform one")
> > Fixes: 3471415c8186 ("platform/x86: topstar-laptop: Convert ACPI driver to a platform one")
> > Fixes: 138db7ee58c0 ("platform/x86: sony-laptop: Convert PIC driver to a platform one")
> > Fixes: 14004dd31caa ("platform/x86: sony-laptop: Convert NC driver to a platform one")
> > Fixes: 2d9cb20610f7 ("platform/x86: lg-laptop: Convert ACPI driver to a platform one")
> > Fixes: 8a44bd3ffdb2 ("platform/x86: intel/smartconnect: Convert ACPI driver to a platform one")
> > Fixes: 163a68a31f74 ("platform/x86: intel/rst: Convert ACPI driver to a platform one")
> > Fixes: 079b59fd2d79 ("platform/x86: eeepc-laptop: Convert ACPI driver to a platform one")
> > Fixes: b30a462720ad ("platform/x86: acer-wireless: Convert ACPI driver to a platform one")
>
> Looking at this I would rather see the series, but am not a maintainer here and
> I'm fine with the result. As a single patch or as a series
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
>
> ...
>
> > static int acpi_fujitsu_probe(struct platform_device *pdev)
> > {
> > - struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
> > + struct acpi_device *adev;
> > acpi_status status;
> > int error;
> >
> > + adev = ACPI_COMPANION(&pdev->dev);
> > + if (!adev)
> > + return -ENODEV;
> > +
> > status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
>
> Don't you want ACPI_HANDLE() actually? (Note it's not directly related
> to this change, but perhaps a material for further improvements.)

>From the code flow perspective it doesn't really matter at all because
ACPI_COMPANION(dev) needs to be dereferenced anyway to get
ACPI_HANDLE(dev) sooner or later and when that happens isn't really
that important. And since acpi_handle really is a (void *) in
disguise, I slightly prefer using (struct acpi_device *) for a local
var unless the handle is used more than once in the given piece of
code.