[PATCH v1] iio: light: acpi-als: Check ACPI_COMPANION() against NULL

Rafael J. Wysocki posted 1 patch 1 month ago
drivers/iio/light/acpi-als.c |    6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
[PATCH v1] iio: light: acpi-als: Check ACPI_COMPANION() against NULL
Posted by Rafael J. Wysocki 1 month ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

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>
---
 drivers/iio/light/acpi-als.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -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;
Re: [PATCH v1] iio: light: acpi-als: Check ACPI_COMPANION() against NULL
Posted by Andy Shevchenko 1 month ago
On Tue, May 12, 2026 at 06:28: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 a requisite ACPI_COMPANION() check against NULL to the
> acpi-als IIO driver.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v1] iio: light: acpi-als: Check ACPI_COMPANION() against NULL
Posted by Jonathan Cameron 3 weeks, 6 days ago
On Tue, 12 May 2026 19:47:48 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Tue, May 12, 2026 at 06:28: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 a requisite ACPI_COMPANION() check against NULL to the
> > acpi-als IIO driver.  
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 

Applied thanks.

Jonathan