From 2c59a32d12201b4aeaef5c0cc04698670e164dc3 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 13 Oct 2021 18:04:09 +0200 Subject: 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 Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/11871063.O9o76ZdvQC@kreacher Signed-off-by: Guenter Roeck --- drivers/hwmon/acpi_power_meter.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'drivers/hwmon') diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index 014505b1faf7..c405a5869581 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c @@ -535,7 +535,7 @@ static void remove_domain_devices(struct acpi_power_meter_resource *resource) sysfs_remove_link(resource->holders_dir, kobject_name(&obj->dev.kobj)); - put_device(&obj->dev); + acpi_dev_put(obj); } kfree(resource->domain_devices); @@ -597,18 +597,15 @@ static int read_domain_devices(struct acpi_power_meter_resource *resource) continue; /* Create a symlink to domain objects */ - resource->domain_devices[i] = NULL; - if (acpi_bus_get_device(element->reference.handle, - &resource->domain_devices[i])) + obj = acpi_bus_get_acpi_device(element->reference.handle); + resource->domain_devices[i] = obj; + if (!obj) continue; - obj = resource->domain_devices[i]; - get_device(&obj->dev); - res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj, kobject_name(&obj->dev.kobj)); if (res) { - put_device(&obj->dev); + acpi_dev_put(obj); resource->domain_devices[i] = NULL; } } -- cgit v1.2.3