* [PATCH] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device()
@ 2021-10-12 17:30 Rafael J. Wysocki
2021-10-12 19:01 ` Andy Shevchenko
2021-10-13 16:04 ` [PATCH v2] " Rafael J. Wysocki
0 siblings, 2 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-10-12 17:30 UTC (permalink / raw)
To: Linux ACPI
Cc: linux-hwmon, LKML, Jean Delvare, Guenter Roeck, Andy Shevchenko
From: Rafael J. Wysocki <rafael@kernel.org>
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@kernel.org>
---
drivers/acpi/scan.c | 1 +
drivers/hwmon/acpi_power_meter.c | 13 +++++--------
2 files changed, 6 insertions(+), 8 deletions(-)
Index: linux-pm/drivers/hwmon/acpi_power_meter.c
===================================================================
--- linux-pm.orig/drivers/hwmon/acpi_power_meter.c
+++ linux-pm/drivers/hwmon/acpi_power_meter.c
@@ -535,7 +535,7 @@ static void remove_domain_devices(struct
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 ac
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;
}
}
Index: linux-pm/drivers/acpi/scan.c
===================================================================
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -608,6 +608,7 @@ struct acpi_device *acpi_bus_get_acpi_de
{
return handle_to_device(handle, get_acpi_device);
}
+EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device);
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
{
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device()
2021-10-12 17:30 [PATCH] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device() Rafael J. Wysocki
@ 2021-10-12 19:01 ` Andy Shevchenko
2021-10-13 16:04 ` [PATCH v2] " Rafael J. Wysocki
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-10-12 19:01 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux ACPI, linux-hwmon, LKML, Jean Delvare, Guenter Roeck
On Tue, Oct 12, 2021 at 07:30:40PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael@kernel.org>
>
> 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().
Good catch!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Rafael J. Wysocki <rafael@kernel.org>
> ---
> drivers/acpi/scan.c | 1 +
> drivers/hwmon/acpi_power_meter.c | 13 +++++--------
> 2 files changed, 6 insertions(+), 8 deletions(-)
>
> Index: linux-pm/drivers/hwmon/acpi_power_meter.c
> ===================================================================
> --- linux-pm.orig/drivers/hwmon/acpi_power_meter.c
> +++ linux-pm/drivers/hwmon/acpi_power_meter.c
> @@ -535,7 +535,7 @@ static void remove_domain_devices(struct
>
> 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 ac
> 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;
> }
> }
> Index: linux-pm/drivers/acpi/scan.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/scan.c
> +++ linux-pm/drivers/acpi/scan.c
> @@ -608,6 +608,7 @@ struct acpi_device *acpi_bus_get_acpi_de
> {
> return handle_to_device(handle, get_acpi_device);
> }
> +EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device);
>
> static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
> {
>
>
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device()
2021-10-12 17:30 [PATCH] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device() Rafael J. Wysocki
2021-10-12 19:01 ` Andy Shevchenko
@ 2021-10-13 16:04 ` Rafael J. Wysocki
2021-10-13 18:50 ` Guenter Roeck
1 sibling, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-10-13 16:04 UTC (permalink / raw)
To: Linux ACPI
Cc: linux-hwmon, LKML, Jean Delvare, Guenter Roeck, Andy Shevchenko
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
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>
---
-> v2: Resend with a different From and S-o-b address and with R-by
from Andy. No other changes.
---
drivers/acpi/scan.c | 1 +
drivers/hwmon/acpi_power_meter.c | 13 +++++--------
2 files changed, 6 insertions(+), 8 deletions(-)
Index: linux-pm/drivers/hwmon/acpi_power_meter.c
===================================================================
--- linux-pm.orig/drivers/hwmon/acpi_power_meter.c
+++ linux-pm/drivers/hwmon/acpi_power_meter.c
@@ -535,7 +535,7 @@ static void remove_domain_devices(struct
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 ac
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;
}
}
Index: linux-pm/drivers/acpi/scan.c
===================================================================
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -608,6 +608,7 @@ struct acpi_device *acpi_bus_get_acpi_de
{
return handle_to_device(handle, get_acpi_device);
}
+EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device);
static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
{
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device()
2021-10-13 16:04 ` [PATCH v2] " Rafael J. Wysocki
@ 2021-10-13 18:50 ` Guenter Roeck
0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2021-10-13 18:50 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux ACPI, linux-hwmon, LKML, Jean Delvare, Andy Shevchenko
On Wed, Oct 13, 2021 at 06:04:09PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> 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>
Applied.
Thanks,
Guenter
> ---
>
> -> v2: Resend with a different From and S-o-b address and with R-by
> from Andy. No other changes.
>
> ---
> drivers/acpi/scan.c | 1 +
> drivers/hwmon/acpi_power_meter.c | 13 +++++--------
> 2 files changed, 6 insertions(+), 8 deletions(-)
>
> Index: linux-pm/drivers/hwmon/acpi_power_meter.c
> ===================================================================
> --- linux-pm.orig/drivers/hwmon/acpi_power_meter.c
> +++ linux-pm/drivers/hwmon/acpi_power_meter.c
> @@ -535,7 +535,7 @@ static void remove_domain_devices(struct
>
> 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 ac
> 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;
> }
> }
> Index: linux-pm/drivers/acpi/scan.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/scan.c
> +++ linux-pm/drivers/acpi/scan.c
> @@ -608,6 +608,7 @@ struct acpi_device *acpi_bus_get_acpi_de
> {
> return handle_to_device(handle, get_acpi_device);
> }
> +EXPORT_SYMBOL_GPL(acpi_bus_get_acpi_device);
>
> static struct acpi_device_bus_id *acpi_device_bus_id_match(const char *dev_id)
> {
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-13 18:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 17:30 [PATCH] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device() Rafael J. Wysocki
2021-10-12 19:01 ` Andy Shevchenko
2021-10-13 16:04 ` [PATCH v2] " Rafael J. Wysocki
2021-10-13 18:50 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.