Skip to content

Commit 2c59a32

Browse files
rafaeljwgroeck
authored andcommitted
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 <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/11871063.O9o76ZdvQC@kreacher Signed-off-by: Guenter Roeck <[email protected]>
1 parent b1986c8 commit 2c59a32

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

drivers/acpi/scan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
608608
{
609609
return handle_to_device(handle, get_acpi_device);
610610
}
611+
EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device);
611612

612613
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
613614
{

drivers/hwmon/acpi_power_meter.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static void remove_domain_devices(struct acpi_power_meter_resource *resource)
535535

536536
sysfs_remove_link(resource->holders_dir,
537537
kobject_name(&obj->dev.kobj));
538-
put_device(&obj->dev);
538+
acpi_dev_put(obj);
539539
}
540540

541541
kfree(resource->domain_devices);
@@ -597,18 +597,15 @@ static int read_domain_devices(struct acpi_power_meter_resource *resource)
597597
continue;
598598

599599
/* 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)
603603
continue;
604604

605-
obj = resource->domain_devices[i];
606-
get_device(&obj->dev);
607-
608605
res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj,
609606
kobject_name(&obj->dev.kobj));
610607
if (res) {
611-
put_device(&obj->dev);
608+
acpi_dev_put(obj);
612609
resource->domain_devices[i] = NULL;
613610
}
614611
}

0 commit comments

Comments
 (0)