Skip to contentSkip to conversation

hwmon: (asus_atk0110) Check ACPI_COMPANION() against NULL

PATCH Applied Rafael J. Wysocki 3 participants 3 messages May 11 – May 13

Subsystems (3)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 hwmon: (asus_atk0110) 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_HANDLE() check against NULL to the asus_atk0110 hwmon driver.

Fixes ee1752590733 ("hwmon: (asus_atk0110) Convert ACPI driver to a platform one")
---
 drivers/hwmon/asus_atk0110.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/hwmon/asus_atk0110.c +6 -1
@@ -1273,15 +1273,20 @@ static int atk_probe(struct platform_dev
 	struct acpi_buffer buf;
 	union acpi_object *obj;
 	struct atk_data *data;
+	acpi_handle handle;
 
 	dev_dbg(&pdev->dev, "adding...\n");
 
+	handle = ACPI_HANDLE(&pdev->dev);
+	if (!handle)
+		return -ENODEV;
+
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
 	data->dev = &pdev->dev;
-	data->atk_handle = ACPI_HANDLE(&pdev->dev);
+	data->atk_handle = handle;
 	INIT_LIST_HEAD(&data->sensor_list);
 	data->disable_ec = false;
 
maintainer Applied
#1 lore raw
Quoted 7 lines · Rafael J. Wysocki

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.

Quoted 5 lines

Accordingly, add a requisite ACPI_HANDLE() check against NULL to the asus_atk0110 hwmon driver.

Fixes ee1752590733 ("hwmon: (asus_atk0110) Convert ACPI driver to a platform one")

Applied.

Thanks,
Guenter

#2 lore raw
In reply to Rafael J. Wysocki
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Concurrent sysfs reads cause data races and potentially unsafe ACPI evaluations due to lack of…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Concurrent sysfs reads cause data races and potentially unsafe ACPI evaluations due to lack of locking.
- [High] The logic for restoring the EC (Embedded Controller) state on driver unload is completely inverted, erroneously disabling the EC if it was previously enabled. --

commit c755ab3a5c2ef6bd47ed195b3ed8df92657bc3c8
Author: Rafael J. Wysocki <[email protected]>

hwmon: (asus_atk0110) Check ACPI_COMPANION() against NULL

Platform drivers can be forced to match a device that doesn't match its list of device IDs using device_match_driver_override(). This commit adds a requisite check to ensure the ACPI companion object exists before continuing with the probe.

Quoted 15 lines
drivers/hwmon/asus_atk0110.c +4 -0
index 5688ff5f7c28d..109318b0434d9 100644
@@ -1273,15 +1273,20 @@ static int atk_probe(struct platform_device *pdev)
 	struct acpi_buffer buf;
 	union acpi_object *obj;
 	struct atk_data *data;
+	acpi_handle handle;
 
 	dev_dbg(&pdev->dev, "adding...\n");
 
+	handle = ACPI_HANDLE(&pdev->dev);
+	if (!handle)
+		return -ENODEV;

drivers/hwmon/asus_atk0110.c static int atk_probe(struct platform_device *pdev) · line 1291

Quoted 10 lines
drivers/hwmon/asus_atk0110.c +2 -1
+
 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
 	data->dev = &pdev->dev;
-	data->atk_handle = ACPI_HANDLE(&pdev->dev);
+	data->atk_handle = handle;
 	INIT_LIST_HEAD(&data->sensor_list);
 	data->disable_ec = false;

This isn't a regression, but is the logic for restoring the EC state inverted?

In atk_enumerate_new_hwmon(), atk_ec_enabled() returns 1 if the EC is enabled and 0 if disabled, and this result is assigned directly to data->disable_ec:

drivers/hwmon/asus_atk0110.c:atk_enumerate_new_hwmon() {
        ...
		err = atk_ec_enabled(data);
		if (err < 0)
			return err;
		/* If the EC was disabled we will disable it again on unload */
		data->disable_ec = err;
        ...
}

Later, during atk_remove() or error paths, the driver checks this flag and disables the EC:

drivers/hwmon/asus_atk0110.c:atk_probe() {
        ...
out:
	if (data->disable_ec)
		atk_ec_ctl(data, 0);
	return err;
}

Will this incorrectly disable the EC on exit if it was running before probe, and leave it enabled if it was initially stopped?

Also not a regression, but does this driver need to implement its own locking to serialize sysfs reads?

The hardware monitoring subsystem requires drivers registering attributes via hwmon_device_register_with_groups() to implement their own locking. In atk_read_value(), fields like sensor->is_valid, sensor->last_updated, and sensor->cached_value are accessed and modified concurrently:

drivers/hwmon/asus_atk0110.c:atk_read_value() {
	if (!sensor->is_valid ||
	    time_after(jiffies, sensor->last_updated + CACHE_TIME)) {
		...
		sensor->is_valid = true;
		sensor->last_updated = jiffies;
		sensor->cached_value = *value;
	} else {
		*value = sensor->cached_value;
	}
    ...
}

Could concurrent reads bypass the cache, trigger concurrent ACPI method evaluations, and cause torn reads or writes on 64-bit cached values?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1