Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (acpi_power_meter) Use acpi_bus_get_acpi_device()

In read_domain_devices(), acpi_bus_get_device() is called to obtain
the ACPI device object attached to the given ACPI handle and
subsequently that object is passed to get_device() for reference
counting, but there is a window between the acpi_bus_get_device()
and get_device() calls in which the ACPI device object in question
may go away.

To address this issue, make read_domain_devices() use
acpi_bus_get_acpi_device() to reference count and return the given
ACPI device object in one go and export that function to modules.

While at it, also make read_domain_devices() and
remove_domain_devices() use acpi_dev_put() instead of calling
put_device() directly on the ACPI device objects returned by
acpi_bus_get_acpi_device().

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/11871063.O9o76ZdvQC@kreacher
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Rafael J. Wysocki and committed by
Guenter Roeck
2c59a32d b1986c8e

+6 -8
+1
drivers/acpi/scan.c
··· 608 608 { 609 609 return handle_to_device(handle, get_acpi_device); 610 610 } 611 + EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device); 611 612 612 613 static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id) 613 614 {
+5 -8
drivers/hwmon/acpi_power_meter.c
··· 535 535 536 536 sysfs_remove_link(resource->holders_dir, 537 537 kobject_name(&obj->dev.kobj)); 538 - put_device(&obj->dev); 538 + acpi_dev_put(obj); 539 539 } 540 540 541 541 kfree(resource->domain_devices); ··· 597 597 continue; 598 598 599 599 /* Create a symlink to domain objects */ 600 - resource->domain_devices[i] = NULL; 601 - if (acpi_bus_get_device(element->reference.handle, 602 - &resource->domain_devices[i])) 600 + obj = acpi_bus_get_acpi_device(element->reference.handle); 601 + resource->domain_devices[i] = obj; 602 + if (!obj) 603 603 continue; 604 - 605 - obj = resource->domain_devices[i]; 606 - get_device(&obj->dev); 607 604 608 605 res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj, 609 606 kobject_name(&obj->dev.kobj)); 610 607 if (res) { 611 - put_device(&obj->dev); 608 + acpi_dev_put(obj); 612 609 resource->domain_devices[i] = NULL; 613 610 } 614 611 }