]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iio: light: acpi-als: Check ACPI_COMPANION() against NULL
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 May 2026 16:28:26 +0000 (18:28 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 16 May 2026 18:25:33 +0000 (19:25 +0100)
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 a requisite ACPI_COMPANION() check against NULL to the
acpi-als IIO driver.

Fixes: d4243cb08a27 ("iio: light: acpi-als: Convert ACPI driver to a platform one")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/light/acpi-als.c

index ab229318dce94cf0c7e7a5f7e3317b4c0cda8321..1983a7f17aa9307f04377b5e4bacdee7582ca0fb 100644 (file)
@@ -179,11 +179,15 @@ out:
 static int acpi_als_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
-       struct acpi_device *device = ACPI_COMPANION(dev);
+       struct acpi_device *device;
        struct iio_dev *indio_dev;
        struct acpi_als *als;
        int ret;
 
+       device = ACPI_COMPANION(dev);
+       if (!device)
+               return -ENODEV;
+
        indio_dev = devm_iio_device_alloc(dev, sizeof(*als));
        if (!indio_dev)
                return -ENOMEM;