Skip to contentSkip to conversation

iio: light: acpi-als: Check ACPI_COMPANION() against NULL

PATCH In review Rafael J. Wysocki 3 participants 3 messages May 12 – May 16

Subsystems (2)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 iio: light: acpi-als: Check ACPI_COMPANION() against NULL

From: "Rafael J. Wysocki" <[email protected]>

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")
---
 drivers/iio/light/acpi-als.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/light/acpi-als.c +5 -1
@@ -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;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Rafael J. Wysocki

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.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
Quoted 7 lines · On Tue, 12 May 2026 19:47:48 +0300 Andy Shevchenko…
Quoted 5 lines · Rafael J. Wysocki

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.

Quoted 5 lines
Quoted 2 lines

Accordingly, add a requisite ACPI_COMPANION() check against NULL to the acpi-als IIO driver.

Applied thanks.

Jonathan