[PATCH v1] watchdog: ni903x_wdt: Check ACPI_COMPANION() against NULL

Rafael J. Wysocki posted 1 patch 1 month ago
drivers/watchdog/ni903x_wdt.c |    7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
[PATCH v1] watchdog: ni903x_wdt: 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
ni903x_wdt watchdog driver.

Fixes: d37ec2fbab55 ("watchdog: ni903x_wdt: Convert to a platform driver")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/watchdog/ni903x_wdt.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/drivers/watchdog/ni903x_wdt.c
+++ b/drivers/watchdog/ni903x_wdt.c
@@ -183,9 +183,14 @@ static int ni903x_acpi_probe(struct plat
 	struct device *dev = &pdev->dev;
 	struct watchdog_device *wdd;
 	struct ni903x_wdt *wdt;
+	acpi_handle handle;
 	acpi_status status;
 	int ret;
 
+	handle = ACPI_HANDLE(dev);
+	if (!handle)
+		return -ENODEV;
+
 	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
@@ -193,7 +198,7 @@ static int ni903x_acpi_probe(struct plat
 	platform_set_drvdata(pdev, wdt);
 	wdt->dev = dev;
 
-	status = acpi_walk_resources(ACPI_HANDLE(dev), METHOD_NAME__CRS,
+	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
 				     ni903x_resources, wdt);
 	if (ACPI_FAILURE(status) || wdt->io_base == 0) {
 		dev_err(dev, "failed to get resources\n");
Re: [PATCH v1] watchdog: ni903x_wdt: Check ACPI_COMPANION() against NULL
Posted by Guenter Roeck 1 month ago
On Tue, May 12, 2026 at 06:22:57PM +0200, Rafael J. Wysocki wrote:
> 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
> ni903x_wdt watchdog driver.
> 
> Fixes: d37ec2fbab55 ("watchdog: ni903x_wdt: Convert to a platform driver")
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Applied.

Thanks,
Guenter
Re: [PATCH v1] watchdog: ni903x_wdt: Check ACPI_COMPANION() against NULL
Posted by Andy Shevchenko 1 month ago
On Tue, May 12, 2026 at 06:22:57PM +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
> ni903x_wdt watchdog driver.

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

...

> -	status = acpi_walk_resources(ACPI_HANDLE(dev), METHOD_NAME__CRS,
> +	status = acpi_walk_resources(handle, METHOD_NAME__CRS,
>  				     ni903x_resources, wdt);

This smells like we can move to regular acpi_dev_*() resource APIs rather than
custom walking via _CRS. But I haven't looked into the code.

-- 
With Best Regards,
Andy Shevchenko