* [PATCH v1 00/17] ACPI: driver: Use devres-based resource management
@ 2026-05-21 13:57 Rafael J. Wysocki
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
` (16 more replies)
0 siblings, 17 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 13:57 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
Hi All,
This series adds devm_acpi_install_notify_handler() for installing an
ACPI notify handler along with a devm action to remove it automatically
on driver removal and switches over a few core ACPI drivers using
acpi_dev_install_notify_handler() superseded by the above to using
devres-based resource management.
This allows some some hard to maintain and error prone driver code to
be shaved off.
Thanks!
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler()
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
@ 2026-05-21 13:59 ` Rafael J. Wysocki
2026-06-02 18:50 ` Andy Shevchenko
2026-05-21 14:01 ` [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler() Rafael J. Wysocki
` (15 subsequent siblings)
16 siblings, 1 reply; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 13:59 UTC (permalink / raw)
To: Linux ACPI
Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf, Dan Williams,
Vishal Verma, Dave Jiang, Ira Weiny, nvdimm
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Introduce devm_acpi_install_notify_handler() for installing an ACPI
notify handler managed by devres that will be removed automatically on
driver detach.
It installs the notify handler on the device object in the ACPI
namespace that corresponds to the owner device's ACPI companion, if
present (an error is returned if the owner device doesn't have an ACPI
companion).
Currently, there is no way to manually remove the notify handler
installed by it because none of its users brought on subsequently
will need to do that.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/bus.c | 67 +++++++++++++++++++++++++++++++++++++++++
include/acpi/acpi_bus.h | 2 ++
2 files changed, 69 insertions(+)
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 2ec095e2009e..84f0ab47fd40 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -679,6 +679,73 @@ void acpi_dev_remove_notify_handler(struct acpi_device *adev,
}
EXPORT_SYMBOL_GPL(acpi_dev_remove_notify_handler);
+struct acpi_notify_handler_devres {
+ acpi_notify_handler handler;
+ u32 handler_type;
+};
+
+static void devm_acpi_notify_handler_release(struct device *dev, void *res)
+{
+ struct acpi_notify_handler_devres *dr = res;
+
+ acpi_dev_remove_notify_handler(ACPI_COMPANION(dev), dr->handler_type,
+ dr->handler);
+}
+
+/**
+ * devm_acpi_install_notify_handler - Install an ACPI notify handler for a
+ * managed device
+ * @dev: Device to install a notify handler for
+ * @handler_type: Type of the notify handler
+ * @handler: Handler function to install
+ * @context: Data passed back to the handler function
+ *
+ * This function performs the same function as acpi_dev_install_notify_handler()
+ * called for the ACPI companion of @dev with the same @handler_type, @handler,
+ * and @context arguments, but the ACPI notify handler installed by it will be
+ * automatically removed on driver detach.
+ *
+ * Callers should ensure that all resources used by @handler have been allocated
+ * prior to invoking this function, in which case those resources should be
+ * devres-managed so that they won't be released before the notify handler
+ * removal. Otherwise, special synchronization between @handler and the
+ * management of those resources is required.
+ *
+ * When the request fails, an error message is printed with contextual
+ * information (device name, handler function and error code). Don't add extra
+ * error messages at the call sites.
+ *
+ * Return: 0 on success or a negative error number.
+ */
+int devm_acpi_install_notify_handler(struct device *dev, u32 handler_type,
+ acpi_notify_handler handler, void *context)
+{
+ struct acpi_notify_handler_devres *dr;
+ struct acpi_device *adev;
+ int ret;
+
+ adev = ACPI_COMPANION(dev);
+ if (!adev)
+ return dev_err_probe(dev, -ENODEV, "No ACPI companion in %s()\n", __func__);
+
+ dr = devres_alloc(devm_acpi_notify_handler_release, sizeof(*dr), GFP_KERNEL);
+ if (!dr)
+ return -ENOMEM;
+
+ ret = acpi_dev_install_notify_handler(adev, handler_type, handler, context);
+ if (ret) {
+ devres_free(dr);
+ return dev_err_probe(dev, ret, "Failed to install an ACPI notify handler\n");
+ }
+
+ dr->handler = handler;
+ dr->handler_type = handler_type;
+ devres_add(dev, dr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_acpi_install_notify_handler);
+
/* Handle events targeting \_SB device (at present only graceful shutdown) */
#define ACPI_SB_NOTIFY_SHUTDOWN_REQUEST 0x81
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index c41d9a7565cf..7e57f9698f7c 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -629,6 +629,8 @@ int acpi_dev_install_notify_handler(struct acpi_device *adev,
void acpi_dev_remove_notify_handler(struct acpi_device *adev,
u32 handler_type,
acpi_notify_handler handler);
+int devm_acpi_install_notify_handler(struct device *dev, u32 handler_type,
+ acpi_notify_handler handler, void *context);
extern int acpi_notifier_call_chain(const char *device_class,
const char *bus_id, u32 type, u32 data);
extern int register_acpi_notifier(struct notifier_block *);
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler()
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
@ 2026-05-21 14:01 ` Rafael J. Wysocki
2026-05-25 15:40 ` Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management Rafael J. Wysocki
` (14 subsequent siblings)
16 siblings, 1 reply; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:01 UTC (permalink / raw)
To: Linux ACPI
Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf, Dan Williams,
Vishal Verma, Dave Jiang, Ira Weiny, nvdimm
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Now that devm_acpi_install_notify_handler() is available, use it in
acpi_nfit_probe() instead of a custom devm action removing an ACPI
notify handler installed via acpi_dev_install_notify_handler().
Also drop the explicit ACPI_COMPANION() check against NULL that is
not necessary any more becuase devm_acpi_install_notify_handler()
carries out an equivalent check internally and use ACPI_HANDLE() to
retrieve the platform device's ACPI handle.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/nfit/core.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
index 9304ac996d41..5cab62f618c8 100644
--- a/drivers/acpi/nfit/core.c
+++ b/drivers/acpi/nfit/core.c
@@ -3298,14 +3298,6 @@ static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data)
device_unlock(dev);
}
-static void acpi_nfit_remove_notify_handler(void *data)
-{
- struct acpi_device *adev = data;
-
- acpi_dev_remove_notify_handler(adev, ACPI_DEVICE_NOTIFY,
- acpi_nfit_notify);
-}
-
void acpi_nfit_shutdown(void *data)
{
struct acpi_nfit_desc *acpi_desc = data;
@@ -3342,22 +3334,12 @@ static int acpi_nfit_probe(struct platform_device *pdev)
struct acpi_nfit_desc *acpi_desc;
struct device *dev = &pdev->dev;
struct acpi_table_header *tbl;
- struct acpi_device *adev;
acpi_status status = AE_OK;
acpi_size sz;
int rc = 0;
- adev = ACPI_COMPANION(&pdev->dev);
- if (!adev)
- return -ENODEV;
-
- rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
- acpi_nfit_notify, dev);
- if (rc)
- return rc;
-
- rc = devm_add_action_or_reset(dev, acpi_nfit_remove_notify_handler,
- adev);
+ rc = devm_acpi_install_notify_handler(dev, ACPI_DEVICE_NOTIFY,
+ acpi_nfit_notify, dev);
if (rc)
return rc;
@@ -3388,7 +3370,7 @@ static int acpi_nfit_probe(struct platform_device *pdev)
acpi_desc->acpi_header = *tbl;
/* Evaluate _FIT and override with that if present */
- status = acpi_evaluate_object(adev->handle, "_FIT", NULL, &buf);
+ status = acpi_evaluate_object(ACPI_HANDLE(dev), "_FIT", NULL, &buf);
if (ACPI_SUCCESS(status) && buf.length > 0) {
union acpi_object *obj = buf.pointer;
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-05-21 14:01 ` [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler() Rafael J. Wysocki
@ 2026-05-21 14:02 ` Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 04/17] ACPI: battery: " Rafael J. Wysocki
` (13 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:02 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Use devm_kzalloc() for allocating memory, devm_power_supply_register()
for registering a power supply class device and the newly introduced
devm_acpi_install_notify_handler() for installing an ACPI notify handler.
Note that the code ordering change related to the third of the above
modifications does not matter because there is no order dependency
between the battery notifier and the ACPI notify handler.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/ac.c | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 27f31744f29e..f19d6dd43473 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -193,6 +193,7 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {
static int acpi_ac_probe(struct platform_device *pdev)
{
struct power_supply_config psy_cfg = {};
+ struct device *dev = &pdev->dev;
struct acpi_device *adev;
struct acpi_ac *ac;
int result;
@@ -201,7 +202,7 @@ static int acpi_ac_probe(struct platform_device *pdev)
if (!adev)
return -ENODEV;
- ac = kzalloc_obj(struct acpi_ac);
+ ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL);
if (!ac)
return -ENOMEM;
@@ -211,7 +212,7 @@ static int acpi_ac_probe(struct platform_device *pdev)
result = acpi_ac_get_state(ac);
if (result)
- goto err_release_ac;
+ return result;
psy_cfg.drv_data = ac;
@@ -220,33 +221,22 @@ static int acpi_ac_probe(struct platform_device *pdev)
ac->charger_desc.properties = ac_props;
ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
ac->charger_desc.get_property = get_ac_property;
- ac->charger = power_supply_register(&pdev->dev,
- &ac->charger_desc, &psy_cfg);
- if (IS_ERR(ac->charger)) {
- result = PTR_ERR(ac->charger);
- goto err_release_ac;
- }
+ ac->charger = devm_power_supply_register(dev, &ac->charger_desc, &psy_cfg);
+ if (IS_ERR(ac->charger))
+ return PTR_ERR(ac->charger);
pr_info("AC Adapter [%s] (%s-line)\n", acpi_device_bid(adev),
str_on_off(ac->state));
+ result = devm_acpi_install_notify_handler(dev, ACPI_ALL_NOTIFY,
+ acpi_ac_notify, ac);
+ if (result)
+ return result;
+
ac->battery_nb.notifier_call = acpi_ac_battery_notify;
register_acpi_notifier(&ac->battery_nb);
- result = acpi_dev_install_notify_handler(adev, ACPI_ALL_NOTIFY,
- acpi_ac_notify, ac);
- if (result)
- goto err_unregister;
-
return 0;
-
-err_unregister:
- power_supply_unregister(ac->charger);
- unregister_acpi_notifier(&ac->battery_nb);
-err_release_ac:
- kfree(ac);
-
- return result;
}
#ifdef CONFIG_PM_SLEEP
@@ -271,12 +261,7 @@ static void acpi_ac_remove(struct platform_device *pdev)
{
struct acpi_ac *ac = platform_get_drvdata(pdev);
- acpi_dev_remove_notify_handler(ac->device, ACPI_ALL_NOTIFY,
- acpi_ac_notify);
- power_supply_unregister(ac->charger);
unregister_acpi_notifier(&ac->battery_nb);
-
- kfree(ac);
}
static struct platform_driver acpi_ac_driver = {
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 04/17] ACPI: battery: Switch over to devres-based resource management
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (2 preceding siblings ...)
2026-05-21 14:02 ` [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management Rafael J. Wysocki
@ 2026-05-21 14:02 ` Rafael J. Wysocki
2026-05-21 14:03 ` [PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance Rafael J. Wysocki
` (12 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:02 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
The ACPI battery driver already uses devm_kzalloc() for allocating
memory and devm_mutex_init() for mutex initialization, but it still
carries out some manual rollback in acpi_battery_probe().
Switch it over to devres-based resource management completely by
making three changes:
* Rename acpi_battery_update_retry() to devm_acpi_battery_update_retry(),
turn sysfs_battery_cleanup() into a devm action and modify the former
to add it.
* Add devm_acpi_battery_init_wakeup() for initializing the wakeup
source and make it add a custom devm action to automatically remove
the wakeup source registered by it.
* Make acpi_battery_probe() use devm_acpi_install_notify_handler()
that has just been introduced for installing an ACPI notify handler.
Note that the code ordering change related to the last of the above
changes does not matter because there is no functional dependency
between the PM notifier and the wakeup source or the ACPI notify
handler.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/battery.c | 75 ++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 36 deletions(-)
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index b82dd67d98c9..f5e0eb299610 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1182,6 +1182,26 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
{},
};
+static void acpi_battery_wakeup_cleanup(void *data)
+{
+ device_init_wakeup(data, false);
+}
+
+static int devm_acpi_battery_init_wakeup(struct device *dev)
+{
+ device_init_wakeup(dev, true);
+ return devm_add_action_or_reset(dev, acpi_battery_wakeup_cleanup, dev);
+}
+
+static void sysfs_battery_cleanup(void *data)
+{
+ struct acpi_battery *battery = data;
+
+ guard(mutex)(&battery->update_lock);
+
+ sysfs_remove_battery(battery);
+}
+
/*
* Some machines'(E,G Lenovo Z480) ECs are not stable
* during boot up and this causes battery driver fails to be
@@ -1190,10 +1210,15 @@ static const struct dmi_system_id bat_dmi_table[] __initconst = {
* may work. So add retry code here and 20ms sleep between
* every retries.
*/
-static int acpi_battery_update_retry(struct acpi_battery *battery)
+static int devm_acpi_battery_update_retry(struct device *dev,
+ struct acpi_battery *battery)
{
int retry, ret;
+ ret = devm_add_action(dev, sysfs_battery_cleanup, battery);
+ if (ret)
+ return ret;
+
guard(mutex)(&battery->update_lock);
for (retry = 5; retry; retry--) {
@@ -1206,27 +1231,21 @@ static int acpi_battery_update_retry(struct acpi_battery *battery)
return ret;
}
-static void sysfs_battery_cleanup(struct acpi_battery *battery)
-{
- guard(mutex)(&battery->update_lock);
-
- sysfs_remove_battery(battery);
-}
-
static int acpi_battery_probe(struct platform_device *pdev)
{
+ struct device *dev = &pdev->dev;
struct acpi_battery *battery;
struct acpi_device *device;
int result;
- device = ACPI_COMPANION(&pdev->dev);
+ device = ACPI_COMPANION(dev);
if (!device)
return -ENODEV;
if (device->dep_unmet)
return -EPROBE_DEFER;
- battery = devm_kzalloc(&pdev->dev, sizeof(*battery), GFP_KERNEL);
+ battery = devm_kzalloc(dev, sizeof(*battery), GFP_KERNEL);
if (!battery)
return -ENOMEM;
@@ -1235,54 +1254,38 @@ static int acpi_battery_probe(struct platform_device *pdev)
battery->phys_dev = &pdev->dev;
battery->device = device;
- result = devm_mutex_init(&pdev->dev, &battery->update_lock);
+ result = devm_mutex_init(dev, &battery->update_lock);
if (result)
return result;
if (acpi_has_method(battery->device->handle, "_BIX"))
set_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
- result = acpi_battery_update_retry(battery);
+ result = devm_acpi_battery_update_retry(dev, battery);
if (result)
- goto fail;
+ return result;
pr_info("Slot [%s] (battery %s)\n", acpi_device_bid(device),
device->status.battery_present ? "present" : "absent");
- battery->pm_nb.notifier_call = battery_notify;
- result = register_pm_notifier(&battery->pm_nb);
+ result = devm_acpi_battery_init_wakeup(dev);
if (result)
- goto fail;
-
- device_init_wakeup(&pdev->dev, true);
+ return result;
- result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
- acpi_battery_notify, battery);
+ result = devm_acpi_install_notify_handler(dev, ACPI_ALL_NOTIFY,
+ acpi_battery_notify, battery);
if (result)
- goto fail_pm;
-
- return 0;
-
-fail_pm:
- device_init_wakeup(&pdev->dev, false);
- unregister_pm_notifier(&battery->pm_nb);
-fail:
- sysfs_battery_cleanup(battery);
+ return result;
- return result;
+ battery->pm_nb.notifier_call = battery_notify;
+ return register_pm_notifier(&battery->pm_nb);
}
static void acpi_battery_remove(struct platform_device *pdev)
{
struct acpi_battery *battery = platform_get_drvdata(pdev);
- acpi_dev_remove_notify_handler(battery->device, ACPI_ALL_NOTIFY,
- acpi_battery_notify);
-
- device_init_wakeup(&pdev->dev, false);
unregister_pm_notifier(&battery->pm_nb);
-
- sysfs_battery_cleanup(battery);
}
/* this is needed to learn about changes made in suspended state */
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (3 preceding siblings ...)
2026-05-21 14:02 ` [PATCH v1 04/17] ACPI: battery: " Rafael J. Wysocki
@ 2026-05-21 14:03 ` Rafael J. Wysocki
2026-05-21 14:04 ` [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management Rafael J. Wysocki
` (11 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:03 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
There can be only one ACPI hardware event device (HED) in use at a time,
so acpi_hed_probe() uses static variable hed_handle for guarding against
adding a second HED instance, but there is no reason for that variable
to hold an ACPI handle, so change it to a bool one.
While at it also set that variable at the end of acpi_hed_probe() to
avouid the need to clear it when installing the ACPI notify handler
fails.
Note that ACPI devices are enumerated sequentially, so there's no need
for additional locking around the accesses to that variable.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/hed.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/acpi/hed.c b/drivers/acpi/hed.c
index 060e8d670f5d..4b5dc95922ea 100644
--- a/drivers/acpi/hed.c
+++ b/drivers/acpi/hed.c
@@ -22,7 +22,7 @@ static const struct acpi_device_id acpi_hed_ids[] = {
};
MODULE_DEVICE_TABLE(acpi, acpi_hed_ids);
-static acpi_handle hed_handle;
+static bool hed_present;
static BLOCKING_NOTIFIER_HEAD(acpi_hed_notify_list);
@@ -58,25 +58,25 @@ static int acpi_hed_probe(struct platform_device *pdev)
return -ENODEV;
/* Only one hardware error device */
- if (hed_handle)
+ if (hed_present)
return -EINVAL;
- hed_handle = device->handle;
err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
acpi_hed_notify, device);
if (err)
- hed_handle = NULL;
+ return err;
- return err;
+ hed_present = true;
+ return 0;
}
static void acpi_hed_remove(struct platform_device *pdev)
{
struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+ hed_present = false;
acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
acpi_hed_notify);
- hed_handle = NULL;
}
static struct platform_driver acpi_hed_driver = {
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (4 preceding siblings ...)
2026-05-21 14:03 ` [PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance Rafael J. Wysocki
@ 2026-05-21 14:04 ` Rafael J. Wysocki
2026-06-02 22:10 ` Andy Shevchenko
2026-05-21 14:04 ` [PATCH v1 07/17] ACPI: thermal: " Rafael J. Wysocki
` (10 subsequent siblings)
16 siblings, 1 reply; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:04 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Use the newly introduced devm_acpi_install_notify_handler() for
installing an ACPI notify handler and since that function checks the
ACPI companion of the owner device against NULL internally, remove the
the explicit ACPI companion check from acpi_hed_probe().
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/hed.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/drivers/acpi/hed.c b/drivers/acpi/hed.c
index 4b5dc95922ea..48562f53d3ab 100644
--- a/drivers/acpi/hed.c
+++ b/drivers/acpi/hed.c
@@ -50,19 +50,14 @@ static void acpi_hed_notify(acpi_handle handle, u32 event, void *data)
static int acpi_hed_probe(struct platform_device *pdev)
{
- struct acpi_device *device;
int err;
- device = ACPI_COMPANION(&pdev->dev);
- if (!device)
- return -ENODEV;
-
/* Only one hardware error device */
if (hed_present)
return -EINVAL;
- err = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
- acpi_hed_notify, device);
+ err = devm_acpi_install_notify_handler(&pdev->dev, ACPI_DEVICE_NOTIFY,
+ acpi_hed_notify, NULL);
if (err)
return err;
@@ -72,11 +67,7 @@ static int acpi_hed_probe(struct platform_device *pdev)
static void acpi_hed_remove(struct platform_device *pdev)
{
- struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
-
hed_present = false;
- acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
- acpi_hed_notify);
}
static struct platform_driver acpi_hed_driver = {
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 07/17] ACPI: thermal: Switch over to devres-based resource management
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (5 preceding siblings ...)
2026-05-21 14:04 ` [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management Rafael J. Wysocki
@ 2026-05-21 14:04 ` Rafael J. Wysocki
2026-05-21 14:05 ` [PATCH v1 08/17] ACPI: PAD: Rearrange acpi_pad_notify() Rafael J. Wysocki
` (9 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:04 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Switch over the ACPI thermal zone driver to devres-based resource
management by making the following changes:
* Turn acpi_thermal_zone_free() into a devm action added from
acpi_thermal_probe() after allocating the struct acpi_thermal object.
* Rename acpi_thermal_unregister_thermal_zone() to
acpi_thermal_zone_unregister(), add acpi_thermal_pm_queue flushing to
it, and turn it into a devm action added by acpi_thermal_probe()
after calling acpi_thermal_register_thermal_zone().
* Use the newly introduced devm_acpi_install_notify_handler() for
installing an ACPI notify handler.
* Drop acpi_thermal_remove() that is not necessary any more.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/thermal.c | 53 +++++++++++++++++-------------------------
1 file changed, 21 insertions(+), 32 deletions(-)
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index dfc7daa809b5..dd7666c176a0 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -655,8 +655,12 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz,
return result;
}
-static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
+static void acpi_thermal_zone_unregister(void *data)
{
+ struct acpi_thermal *tz = data;
+
+ flush_workqueue(acpi_thermal_pm_queue);
+
thermal_zone_device_disable(tz->thermal_zone);
acpi_thermal_zone_sysfs_remove(tz);
thermal_zone_device_unregister(tz->thermal_zone);
@@ -765,8 +769,9 @@ static void acpi_thermal_check_fn(struct work_struct *work)
mutex_unlock(&tz->thermal_check_lock);
}
-static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
+static void acpi_thermal_zone_free(void *data)
{
+ struct acpi_thermal *tz = data;
int i;
acpi_handle_list_free(&tz->trips.passive.trip.devices);
@@ -779,7 +784,8 @@ static void acpi_thermal_free_thermal_zone(struct acpi_thermal *tz)
static int acpi_thermal_probe(struct platform_device *pdev)
{
struct thermal_trip trip_table[ACPI_THERMAL_MAX_NR_TRIPS] = { 0 };
- struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+ struct device *dev = &pdev->dev;
+ struct acpi_device *device = ACPI_COMPANION(dev);
struct acpi_thermal_trip *acpi_trip;
struct thermal_trip *trip;
struct acpi_thermal *tz;
@@ -795,6 +801,10 @@ static int acpi_thermal_probe(struct platform_device *pdev)
if (!tz)
return -ENOMEM;
+ result = devm_add_action_or_reset(dev, acpi_thermal_zone_free, tz);
+ if (result)
+ return result;
+
platform_set_drvdata(pdev, tz);
tz->device = device;
@@ -817,7 +827,7 @@ static int acpi_thermal_probe(struct platform_device *pdev)
/* Get temperature [_TMP] (required). */
result = acpi_thermal_get_temperature(tz);
if (result)
- goto free_memory;
+ return result;
/* Determine the default polling frequency [_TZP]. */
if (tzp)
@@ -870,7 +880,11 @@ static int acpi_thermal_probe(struct platform_device *pdev)
trip - trip_table,
passive_delay);
if (result)
- goto free_memory;
+ return result;
+
+ result = devm_add_action_or_reset(dev, acpi_thermal_zone_unregister, tz);
+ if (result)
+ return result;
refcount_set(&tz->thermal_check_count, 3);
mutex_init(&tz->thermal_check_lock);
@@ -879,32 +893,8 @@ static int acpi_thermal_probe(struct platform_device *pdev)
pr_info("Thermal Zone [%s] (%ld C)\n", acpi_device_bid(device),
deci_kelvin_to_celsius(tz->temp_dk));
- result = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
- acpi_thermal_notify, tz);
- if (result)
- goto flush_wq;
-
- return 0;
-
-flush_wq:
- flush_workqueue(acpi_thermal_pm_queue);
- acpi_thermal_unregister_thermal_zone(tz);
-free_memory:
- acpi_thermal_free_thermal_zone(tz);
-
- return result;
-}
-
-static void acpi_thermal_remove(struct platform_device *pdev)
-{
- struct acpi_thermal *tz = platform_get_drvdata(pdev);
-
- acpi_dev_remove_notify_handler(tz->device, ACPI_DEVICE_NOTIFY,
- acpi_thermal_notify);
-
- flush_workqueue(acpi_thermal_pm_queue);
- acpi_thermal_unregister_thermal_zone(tz);
- acpi_thermal_free_thermal_zone(tz);
+ return devm_acpi_install_notify_handler(dev, ACPI_DEVICE_NOTIFY,
+ acpi_thermal_notify, tz);
}
#ifdef CONFIG_PM_SLEEP
@@ -937,7 +927,6 @@ MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
static struct platform_driver acpi_thermal_driver = {
.probe = acpi_thermal_probe,
- .remove = acpi_thermal_remove,
.driver = {
.name = "acpi-thermal",
.acpi_match_table = thermal_device_ids,
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 08/17] ACPI: PAD: Rearrange acpi_pad_notify()
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (6 preceding siblings ...)
2026-05-21 14:04 ` [PATCH v1 07/17] ACPI: thermal: " Rafael J. Wysocki
@ 2026-05-21 14:05 ` Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 09/17] ACPI: PAD: Pass struct device pointer to acpi_pad_notify() Rafael J. Wysocki
` (8 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:05 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Use an if () in acpi_pad_notify() instead of a switch () statement to
make the code somewhat easier to follow and reduce its indentation
level.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_pad.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index ec94b09bb747..91d32da76f8f 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -409,16 +409,13 @@ static void acpi_pad_notify(acpi_handle handle, u32 event, void *data)
{
struct acpi_device *adev = data;
- switch (event) {
- case ACPI_PROCESSOR_AGGREGATOR_NOTIFY:
- acpi_pad_handle_notify(handle);
- acpi_bus_generate_netlink_event("acpi_pad",
- dev_name(&adev->dev), event, 0);
- break;
- default:
+ if (event != ACPI_PROCESSOR_AGGREGATOR_NOTIFY) {
pr_warn("Unsupported event [0x%x]\n", event);
- break;
+ return;
}
+
+ acpi_pad_handle_notify(handle);
+ acpi_bus_generate_netlink_event("acpi_pad", dev_name(&adev->dev), event, 0);
}
static int acpi_pad_probe(struct platform_device *pdev)
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 09/17] ACPI: PAD: Pass struct device pointer to acpi_pad_notify()
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (7 preceding siblings ...)
2026-05-21 14:05 ` [PATCH v1 08/17] ACPI: PAD: Rearrange acpi_pad_notify() Rafael J. Wysocki
@ 2026-05-21 14:06 ` Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 10/17] ACPI: PAD: Fix teardown ordering in acpi_pad_remove() Rafael J. Wysocki
` (7 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:06 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Use the struct device pointer to the dev member in the struct
platform_device object representing the platform device used for driver
binding as the last argument of acpi_dev_install_notify_handler() and
accordingly update acpi_pad_notify() to pass that pointer directly to
dev_name() when generating the netlink event.
Since the dev_name() value for an ACPI-enumerated platform device is the
same as the dev_name() value for the dev member of its ACPI companion
object, as per acpi_create_platform_device(), the above code modification
is not expected to cause functionality to change.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_pad.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 91d32da76f8f..b0a6723fb854 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -407,15 +407,13 @@ static void acpi_pad_handle_notify(acpi_handle handle)
static void acpi_pad_notify(acpi_handle handle, u32 event, void *data)
{
- struct acpi_device *adev = data;
-
if (event != ACPI_PROCESSOR_AGGREGATOR_NOTIFY) {
pr_warn("Unsupported event [0x%x]\n", event);
return;
}
acpi_pad_handle_notify(handle);
- acpi_bus_generate_netlink_event("acpi_pad", dev_name(&adev->dev), event, 0);
+ acpi_bus_generate_netlink_event("acpi_pad", dev_name(data), event, 0);
}
static int acpi_pad_probe(struct platform_device *pdev)
@@ -427,7 +425,7 @@ static int acpi_pad_probe(struct platform_device *pdev)
return -ENODEV;
return acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
- acpi_pad_notify, adev);
+ acpi_pad_notify, &pdev->dev);
}
static void acpi_pad_remove(struct platform_device *pdev)
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 10/17] ACPI: PAD: Fix teardown ordering in acpi_pad_remove()
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (8 preceding siblings ...)
2026-05-21 14:06 ` [PATCH v1 09/17] ACPI: PAD: Pass struct device pointer to acpi_pad_notify() Rafael J. Wysocki
@ 2026-05-21 14:06 ` Rafael J. Wysocki
2026-05-21 14:07 ` [PATCH v1 11/17] ACPI: PAD: Switch over to devres-based resource management Rafael J. Wysocki
` (6 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:06 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
The ACPI notify handler installed by acpi_pad_probe() needs to be
removed before calling acpi_pad_idle_cpus() in acpi_pad_remove()
so it doesn't schedule idle time injection on some CPUs again.
Fixes: 8e0af5141ab9 ("ACPI: create Processor Aggregator Device driver")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_pad.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index b0a6723fb854..48c00ee61ed2 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -430,12 +430,12 @@ static int acpi_pad_probe(struct platform_device *pdev)
static void acpi_pad_remove(struct platform_device *pdev)
{
+ acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
+ ACPI_DEVICE_NOTIFY, acpi_pad_notify);
+
mutex_lock(&isolated_cpus_lock);
acpi_pad_idle_cpus(0);
mutex_unlock(&isolated_cpus_lock);
-
- acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
- ACPI_DEVICE_NOTIFY, acpi_pad_notify);
}
static const struct acpi_device_id pad_device_ids[] = {
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 11/17] ACPI: PAD: Switch over to devres-based resource management
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (9 preceding siblings ...)
2026-05-21 14:06 ` [PATCH v1 10/17] ACPI: PAD: Fix teardown ordering in acpi_pad_remove() Rafael J. Wysocki
@ 2026-05-21 14:07 ` Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 12/17] ACPI: video: Reduce the number of auxiliary device dereferences Rafael J. Wysocki
` (5 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:07 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Use the newly introduced devm_acpi_install_notify_handler() for
installing an ACPI notify handler and since that function checks the
ACPI companion of the owner device against NULL internally, remove the
the explicit ACPI companion check from acpi_pad_probe().
However, to prevent the notify handler from running acpi_pad_idle_cpus()
with the number of idle CPUs greater than zero after acpi_pad_remove()
has returned, add a bool static variable for synchronization between
the two.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_pad.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index 48c00ee61ed2..5792f93d3534 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -31,6 +31,8 @@
static DEFINE_MUTEX(isolated_cpus_lock);
static DEFINE_MUTEX(round_robin_lock);
+static bool acpi_pad_teardown;
+
static unsigned int power_saving_mwait_eax;
static unsigned char tsc_detected_unstable;
@@ -359,6 +361,9 @@ static int acpi_pad_pur(acpi_handle handle)
union acpi_object *package;
int num = -1;
+ if (unlikely(acpi_pad_teardown))
+ return -1;
+
if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer)))
return num;
@@ -418,22 +423,16 @@ static void acpi_pad_notify(acpi_handle handle, u32 event, void *data)
static int acpi_pad_probe(struct platform_device *pdev)
{
- struct acpi_device *adev;
+ acpi_pad_teardown = false;
- adev = ACPI_COMPANION(&pdev->dev);
- if (!adev)
- return -ENODEV;
-
- return acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
- acpi_pad_notify, &pdev->dev);
+ return devm_acpi_install_notify_handler(&pdev->dev, ACPI_DEVICE_NOTIFY,
+ acpi_pad_notify, &pdev->dev);
}
static void acpi_pad_remove(struct platform_device *pdev)
{
- acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
- ACPI_DEVICE_NOTIFY, acpi_pad_notify);
-
mutex_lock(&isolated_cpus_lock);
+ acpi_pad_teardown = true;
acpi_pad_idle_cpus(0);
mutex_unlock(&isolated_cpus_lock);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 12/17] ACPI: video: Reduce the number of auxiliary device dereferences
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (10 preceding siblings ...)
2026-05-21 14:07 ` [PATCH v1 11/17] ACPI: PAD: Switch over to devres-based resource management Rafael J. Wysocki
@ 2026-05-21 14:08 ` Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 13/17] ACPI: video: Rearrange probe and remove code Rafael J. Wysocki
` (4 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:08 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Store the &aux_dev->dev pointer in a separate local variable in
acpi_video_bus_probe() to avoid dereferencing aux_dev many times.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_video.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 05793ddef787..bdc3f4933abf 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1978,7 +1978,8 @@ static bool acpi_video_bus_dev_is_duplicate(struct device *dev)
static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
const struct auxiliary_device_id *id_unused)
{
- struct acpi_device *device = ACPI_COMPANION(&aux_dev->dev);
+ struct device *dev = &aux_dev->dev;
+ struct acpi_device *device = ACPI_COMPANION(dev);
static DEFINE_MUTEX(probe_lock);
struct acpi_video_bus *video;
static int instance;
@@ -1988,7 +1989,7 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
/* Probe one video bus device at a time in case there are duplicates. */
guard(mutex)(&probe_lock);
- if (!allow_duplicates && acpi_video_bus_dev_is_duplicate(&aux_dev->dev)) {
+ if (!allow_duplicates && acpi_video_bus_dev_is_duplicate(dev)) {
pr_info(FW_BUG
"Duplicate ACPI video bus devices for the"
" same VGA controller, please try module "
@@ -2059,7 +2060,7 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
!auto_detect)
acpi_video_bus_register_backlight(video);
- error = acpi_video_bus_add_notify_handler(video, &aux_dev->dev);
+ error = acpi_video_bus_add_notify_handler(video, dev);
if (error)
goto err_del;
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 13/17] ACPI: video: Rearrange probe and remove code
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (11 preceding siblings ...)
2026-05-21 14:08 ` [PATCH v1 12/17] ACPI: video: Reduce the number of auxiliary device dereferences Rafael J. Wysocki
@ 2026-05-21 14:08 ` Rafael J. Wysocki
2026-05-21 14:09 ` [PATCH v1 14/17] ACPI: video: Use devm action for video bus object cleanup Rafael J. Wysocki
` (3 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:08 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Rearrange some ACPI video bus probe and remove code so that it is more
clear that the probe and removal are carried in reverse orders, which
will also facilitate subsequent changes.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_video.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index bdc3f4933abf..ca2bee967946 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -2002,6 +2002,9 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
if (!video)
return -ENOMEM;
+ video->device = device;
+ device->driver_data = video;
+
/*
* A hack to fix the duplicate name "VID" problem on T61 and the
* duplicate name "VGA" problem on Pa 3553.
@@ -2016,9 +2019,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
auxiliary_set_drvdata(aux_dev, video);
- video->device = device;
- device->driver_data = video;
-
acpi_video_bus_find_cap(video);
error = acpi_video_bus_check(video);
if (error)
@@ -2041,10 +2041,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
acpi_device_bid(device), str_yes_no(video->flags.multihead),
str_yes_no(video->flags.rom), str_yes_no(video->flags.post));
- mutex_lock(&video_list_lock);
- list_add_tail(&video->entry, &video_bus_head);
- mutex_unlock(&video_list_lock);
-
/*
* If backlight-type auto-detection is used then a native backlight may
* show up later and this may change the result from video to native.
@@ -2060,6 +2056,10 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
!auto_detect)
acpi_video_bus_register_backlight(video);
+ mutex_lock(&video_list_lock);
+ list_add_tail(&video->entry, &video_bus_head);
+ mutex_unlock(&video_list_lock);
+
error = acpi_video_bus_add_notify_handler(video, dev);
if (error)
goto err_del;
@@ -2096,15 +2096,15 @@ static void acpi_video_bus_remove(struct auxiliary_device *aux_dev)
acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
acpi_video_bus_notify);
+ acpi_video_bus_remove_notify_handler(video);
+
mutex_lock(&video_list_lock);
list_del(&video->entry);
mutex_unlock(&video_list_lock);
-
- acpi_video_bus_remove_notify_handler(video);
acpi_video_bus_unregister_backlight(video);
acpi_video_bus_put_devices(video);
-
kfree(video->attached_array);
+
kfree(video);
device->driver_data = NULL;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 14/17] ACPI: video: Use devm action for video bus object cleanup
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (12 preceding siblings ...)
2026-05-21 14:08 ` [PATCH v1 13/17] ACPI: video: Rearrange probe and remove code Rafael J. Wysocki
@ 2026-05-21 14:09 ` Rafael J. Wysocki
2026-05-21 14:10 ` [PATCH v1 15/17] ACPI: video: Use devm action for freeing video devices Rafael J. Wysocki
` (2 subsequent siblings)
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:09 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Introduce acpi_video_bus_free() for freeing video bus object memory
and reversing changes related to it made during ACPI video bus device
probe, modify acpi_video_bus_probe() to add acpi_video_bus_free() as
a devm action, and remove the code superseded by it from
acpi_video_bus_remove().
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_video.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index ca2bee967946..11dd00614f6b 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1953,6 +1953,14 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
return 0;
}
+static void acpi_video_bus_free(void *data)
+{
+ struct acpi_video_bus *video = data;
+
+ video->device->driver_data = NULL;
+ kfree(video);
+}
+
static int duplicate_dev_check(struct device *sibling, void *data)
{
struct acpi_video_bus *video;
@@ -2005,6 +2013,10 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
video->device = device;
device->driver_data = video;
+ error = devm_add_action_or_reset(dev, acpi_video_bus_free, video);
+ if (error)
+ return error;
+
/*
* A hack to fix the duplicate name "VID" problem on T61 and the
* duplicate name "VGA" problem on Pa 3553.
@@ -2022,7 +2034,7 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
acpi_video_bus_find_cap(video);
error = acpi_video_bus_check(video);
if (error)
- goto err_free_video;
+ return error;
mutex_init(&video->device_list_lock);
INIT_LIST_HEAD(&video->video_device_list);
@@ -2081,9 +2093,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
err_put_video:
acpi_video_bus_put_devices(video);
kfree(video->attached_array);
-err_free_video:
- kfree(video);
- device->driver_data = NULL;
return error;
}
@@ -2104,9 +2113,6 @@ static void acpi_video_bus_remove(struct auxiliary_device *aux_dev)
acpi_video_bus_unregister_backlight(video);
acpi_video_bus_put_devices(video);
kfree(video->attached_array);
-
- kfree(video);
- device->driver_data = NULL;
}
static int __init is_i740(struct pci_dev *dev)
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 15/17] ACPI: video: Use devm action for freeing video devices
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (13 preceding siblings ...)
2026-05-21 14:09 ` [PATCH v1 14/17] ACPI: video: Use devm action for video bus object cleanup Rafael J. Wysocki
@ 2026-05-21 14:10 ` Rafael J. Wysocki
2026-05-21 14:10 ` [PATCH v1 16/17] ACPI: video: Use devm for video->entry and backlight cleanup Rafael J. Wysocki
2026-05-21 14:11 ` [PATCH v1 17/17] ACPI: video: Switch over to devres-based resource management Rafael J. Wysocki
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:10 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Rename acpi_video_bus_put_devices() to devm_acpi_video_bus_get_devices()
and turn acpi_video_bus_put_devices() into a devm action added by it for
freeing the video devices allocated by it and the attached_array memory.
Accordingly, remove the acpi_video_bus_put_devices() calls and
attached_array freeing from acpi_video_bus_remove() and the rollback
path in acpi_video_bus_probe().
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_video.c | 53 +++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 25 deletions(-)
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 11dd00614f6b..a02eaf13f5d8 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1494,10 +1494,31 @@ int acpi_video_get_edid(struct acpi_device *device, int type, int device_id,
}
EXPORT_SYMBOL(acpi_video_get_edid);
-static int
-acpi_video_bus_get_devices(struct acpi_video_bus *video,
- struct acpi_device *device)
+static void acpi_video_bus_put_devices(void *data)
+{
+ struct acpi_video_bus *video = data;
+ struct acpi_video_device *dev, *next;
+
+ mutex_lock(&video->device_list_lock);
+ list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
+ list_del(&dev->entry);
+ kfree(dev);
+ }
+ mutex_unlock(&video->device_list_lock);
+
+ kfree(video->attached_array);
+ video->attached_array = NULL;
+}
+
+static int devm_acpi_video_bus_get_devices(struct device *dev,
+ struct acpi_video_bus *video)
{
+ int ret;
+
+ ret = devm_add_action(dev, acpi_video_bus_put_devices, video);
+ if (ret)
+ return ret;
+
/*
* There are systems where video module known to work fine regardless
* of broken _DOD and ignoring returned value here doesn't cause
@@ -1505,7 +1526,8 @@ acpi_video_bus_get_devices(struct acpi_video_bus *video,
*/
acpi_video_device_enumerate(video);
- return acpi_dev_for_each_child(device, acpi_video_bus_get_one_device, video);
+ return acpi_dev_for_each_child(video->device,
+ acpi_video_bus_get_one_device, video);
}
/* acpi_video interface */
@@ -1939,20 +1961,6 @@ static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
video->input = NULL;
}
-static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
-{
- struct acpi_video_device *dev, *next;
-
- mutex_lock(&video->device_list_lock);
- list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
- list_del(&dev->entry);
- kfree(dev);
- }
- mutex_unlock(&video->device_list_lock);
-
- return 0;
-}
-
static void acpi_video_bus_free(void *data)
{
struct acpi_video_bus *video = data;
@@ -2039,9 +2047,9 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
mutex_init(&video->device_list_lock);
INIT_LIST_HEAD(&video->video_device_list);
- error = acpi_video_bus_get_devices(video, device);
+ error = devm_acpi_video_bus_get_devices(dev, video);
if (error)
- goto err_put_video;
+ return error;
/*
* HP ZBook Fury 16 G10 requires ACPI video's child devices have _PS0
@@ -2090,9 +2098,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
list_del(&video->entry);
mutex_unlock(&video_list_lock);
acpi_video_bus_unregister_backlight(video);
-err_put_video:
- acpi_video_bus_put_devices(video);
- kfree(video->attached_array);
return error;
}
@@ -2111,8 +2116,6 @@ static void acpi_video_bus_remove(struct auxiliary_device *aux_dev)
list_del(&video->entry);
mutex_unlock(&video_list_lock);
acpi_video_bus_unregister_backlight(video);
- acpi_video_bus_put_devices(video);
- kfree(video->attached_array);
}
static int __init is_i740(struct pci_dev *dev)
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 16/17] ACPI: video: Use devm for video->entry and backlight cleanup
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (14 preceding siblings ...)
2026-05-21 14:10 ` [PATCH v1 15/17] ACPI: video: Use devm action for freeing video devices Rafael J. Wysocki
@ 2026-05-21 14:10 ` Rafael J. Wysocki
2026-05-21 14:11 ` [PATCH v1 17/17] ACPI: video: Switch over to devres-based resource management Rafael J. Wysocki
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:10 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Introduce acpi_video_bus_del() for removing the video bus object
from the video_bus_head list and unregistering backlight and make
acpi_video_bus_probe() add it as a devm action after adding the
video bus object to the video_bus_head list.
Accordingly, remove the code superseded by it from
acpi_video_bus_remove() and from the rollback path in
acpi_video_bus_probe().
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_video.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index a02eaf13f5d8..e0da168a1df3 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1969,6 +1969,17 @@ static void acpi_video_bus_free(void *data)
kfree(video);
}
+static void acpi_video_bus_del(void *data)
+{
+ struct acpi_video_bus *video = data;
+
+ mutex_lock(&video_list_lock);
+ list_del(&video->entry);
+ mutex_unlock(&video_list_lock);
+
+ acpi_video_bus_unregister_backlight(video);
+}
+
static int duplicate_dev_check(struct device *sibling, void *data)
{
struct acpi_video_bus *video;
@@ -2080,9 +2091,13 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
list_add_tail(&video->entry, &video_bus_head);
mutex_unlock(&video_list_lock);
+ error = devm_add_action_or_reset(dev, acpi_video_bus_del, video);
+ if (error)
+ return error;
+
error = acpi_video_bus_add_notify_handler(video, dev);
if (error)
- goto err_del;
+ return error;
error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
acpi_video_bus_notify, video);
@@ -2093,11 +2108,6 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
err_remove:
acpi_video_bus_remove_notify_handler(video);
-err_del:
- mutex_lock(&video_list_lock);
- list_del(&video->entry);
- mutex_unlock(&video_list_lock);
- acpi_video_bus_unregister_backlight(video);
return error;
}
@@ -2111,11 +2121,6 @@ static void acpi_video_bus_remove(struct auxiliary_device *aux_dev)
acpi_video_bus_notify);
acpi_video_bus_remove_notify_handler(video);
-
- mutex_lock(&video_list_lock);
- list_del(&video->entry);
- mutex_unlock(&video_list_lock);
- acpi_video_bus_unregister_backlight(video);
}
static int __init is_i740(struct pci_dev *dev)
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v1 17/17] ACPI: video: Switch over to devres-based resource management
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
` (15 preceding siblings ...)
2026-05-21 14:10 ` [PATCH v1 16/17] ACPI: video: Use devm for video->entry and backlight cleanup Rafael J. Wysocki
@ 2026-05-21 14:11 ` Rafael J. Wysocki
16 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-21 14:11 UTC (permalink / raw)
To: Linux ACPI; +Cc: LKML, Andy Shevchenko, Hans de Goede, Armin Wolf
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Turn acpi_video_bus_remove_notify_handler() into a devm
action added by acpi_video_bus_probe() after calling
acpi_video_bus_add_notify_handler and use the newly introduced
devm_acpi_install_notify_handler() to install an ACPI notify
handler for the video bus device.
This replaces the rollback path remnant in acpi_video_bus_probe()
and allows acpi_video_bus_remove() to be dropped altogether.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/acpi_video.c | 30 +++++++-----------------------
1 file changed, 7 insertions(+), 23 deletions(-)
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index e0da168a1df3..e5a0b03f06b3 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -76,7 +76,6 @@ static DEFINE_MUTEX(video_list_lock);
static LIST_HEAD(video_bus_head);
static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
const struct auxiliary_device_id *id);
-static void acpi_video_bus_remove(struct auxiliary_device *aux);
static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data);
/*
@@ -99,7 +98,6 @@ MODULE_DEVICE_TABLE(auxiliary, video_bus_auxiliary_id_table);
static struct auxiliary_driver acpi_video_bus = {
.probe = acpi_video_bus_probe,
- .remove = acpi_video_bus_remove,
.id_table = video_bus_auxiliary_id_table,
};
@@ -1945,8 +1943,9 @@ static void acpi_video_dev_remove_notify_handler(struct acpi_video_device *dev)
}
}
-static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus *video)
+static void acpi_video_bus_remove_notify_handler(void *data)
{
+ struct acpi_video_bus *video = data;
struct acpi_video_device *dev;
mutex_lock(&video->device_list_lock);
@@ -2099,28 +2098,13 @@ static int acpi_video_bus_probe(struct auxiliary_device *aux_dev,
if (error)
return error;
- error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
- acpi_video_bus_notify, video);
+ error = devm_add_action_or_reset(dev, acpi_video_bus_remove_notify_handler,
+ video);
if (error)
- goto err_remove;
-
- return 0;
-
-err_remove:
- acpi_video_bus_remove_notify_handler(video);
-
- return error;
-}
-
-static void acpi_video_bus_remove(struct auxiliary_device *aux_dev)
-{
- struct acpi_video_bus *video = auxiliary_get_drvdata(aux_dev);
- struct acpi_device *device = ACPI_COMPANION(&aux_dev->dev);
-
- acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
- acpi_video_bus_notify);
+ return error;
- acpi_video_bus_remove_notify_handler(video);
+ return devm_acpi_install_notify_handler(dev, ACPI_DEVICE_NOTIFY,
+ acpi_video_bus_notify, video);
}
static int __init is_i740(struct pci_dev *dev)
--
2.51.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler()
2026-05-21 14:01 ` [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler() Rafael J. Wysocki
@ 2026-05-25 15:40 ` Rafael J. Wysocki
0 siblings, 0 replies; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-05-25 15:40 UTC (permalink / raw)
To: Dave Jiang, Ira Weiny, Vishal Verma
Cc: Linux ACPI, LKML, Andy Shevchenko, Hans de Goede, Armin Wolf,
Dan Williams, nvdimm
On Thu, May 21, 2026 at 4:13 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> Now that devm_acpi_install_notify_handler() is available, use it in
> acpi_nfit_probe() instead of a custom devm action removing an ACPI
> notify handler installed via acpi_dev_install_notify_handler().
>
> Also drop the explicit ACPI_COMPANION() check against NULL that is
> not necessary any more becuase devm_acpi_install_notify_handler()
> carries out an equivalent check internally and use ACPI_HANDLE() to
> retrieve the platform device's ACPI handle.
>
> No intentional functional impact.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/acpi/nfit/core.c | 24 +++---------------------
> 1 file changed, 3 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c
> index 9304ac996d41..5cab62f618c8 100644
> --- a/drivers/acpi/nfit/core.c
> +++ b/drivers/acpi/nfit/core.c
> @@ -3298,14 +3298,6 @@ static void acpi_nfit_notify(acpi_handle handle, u32 event, void *data)
> device_unlock(dev);
> }
>
> -static void acpi_nfit_remove_notify_handler(void *data)
> -{
> - struct acpi_device *adev = data;
> -
> - acpi_dev_remove_notify_handler(adev, ACPI_DEVICE_NOTIFY,
> - acpi_nfit_notify);
> -}
> -
> void acpi_nfit_shutdown(void *data)
> {
> struct acpi_nfit_desc *acpi_desc = data;
> @@ -3342,22 +3334,12 @@ static int acpi_nfit_probe(struct platform_device *pdev)
> struct acpi_nfit_desc *acpi_desc;
> struct device *dev = &pdev->dev;
> struct acpi_table_header *tbl;
> - struct acpi_device *adev;
> acpi_status status = AE_OK;
> acpi_size sz;
> int rc = 0;
>
> - adev = ACPI_COMPANION(&pdev->dev);
> - if (!adev)
> - return -ENODEV;
> -
> - rc = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
> - acpi_nfit_notify, dev);
> - if (rc)
> - return rc;
> -
> - rc = devm_add_action_or_reset(dev, acpi_nfit_remove_notify_handler,
> - adev);
> + rc = devm_acpi_install_notify_handler(dev, ACPI_DEVICE_NOTIFY,
> + acpi_nfit_notify, dev);
> if (rc)
> return rc;
>
> @@ -3388,7 +3370,7 @@ static int acpi_nfit_probe(struct platform_device *pdev)
> acpi_desc->acpi_header = *tbl;
>
> /* Evaluate _FIT and override with that if present */
> - status = acpi_evaluate_object(adev->handle, "_FIT", NULL, &buf);
> + status = acpi_evaluate_object(ACPI_HANDLE(dev), "_FIT", NULL, &buf);
> if (ACPI_SUCCESS(status) && buf.length > 0) {
> union acpi_object *obj = buf.pointer;
>
> --
I would appreciate feedback on this, but the change is
straightforward, so in the absence of any I'll pick it up assuming no
objections.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler()
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
@ 2026-06-02 18:50 ` Andy Shevchenko
2026-06-02 20:57 ` Rafael J. Wysocki
0 siblings, 1 reply; 25+ messages in thread
From: Andy Shevchenko @ 2026-06-02 18:50 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux ACPI, LKML, Hans de Goede, Armin Wolf, Dan Williams,
Vishal Verma, Dave Jiang, Ira Weiny, nvdimm
On Thu, May 21, 2026 at 03:59:50PM +0200, Rafael J. Wysocki wrote:
> Introduce devm_acpi_install_notify_handler() for installing an ACPI
> notify handler managed by devres that will be removed automatically on
> driver detach.
>
> It installs the notify handler on the device object in the ACPI
> namespace that corresponds to the owner device's ACPI companion, if
> present (an error is returned if the owner device doesn't have an ACPI
> companion).
>
> Currently, there is no way to manually remove the notify handler
> installed by it because none of its users brought on subsequently
> will need to do that.
...
> +static void devm_acpi_notify_handler_release(struct device *dev, void *res)
> +{
> + struct acpi_notify_handler_devres *dr = res;
'dr' is usually associated with internal devres structures and might be
misleading in here, I would rename to something like handler_devres.
> + acpi_dev_remove_notify_handler(ACPI_COMPANION(dev), dr->handler_type,
acpi_dev might be also part of the same data structure, so you won't need to
take dev again and derive adev from it.
> + dr->handler);
> +}
...
> +/**
> + * devm_acpi_install_notify_handler - Install an ACPI notify handler for a
> + * managed device
There is a stray space just after asterisk.
> + * @dev: Device to install a notify handler for
> + * @handler_type: Type of the notify handler
> + * @handler: Handler function to install
> + * @context: Data passed back to the handler function
> + *
> + * This function performs the same function as acpi_dev_install_notify_handler()
> + * called for the ACPI companion of @dev with the same @handler_type, @handler,
> + * and @context arguments, but the ACPI notify handler installed by it will be
> + * automatically removed on driver detach.
> + *
> + * Callers should ensure that all resources used by @handler have been allocated
> + * prior to invoking this function, in which case those resources should be
> + * devres-managed so that they won't be released before the notify handler
> + * removal. Otherwise, special synchronization between @handler and the
> + * management of those resources is required.
> + *
> + * When the request fails, an error message is printed with contextual
> + * information (device name, handler function and error code). Don't add extra
This "handler function" points to __func__? If so, it seems misleading.
> + * error messages at the call sites.
> + *
> + * Return: 0 on success or a negative error number.
> + */
> +int devm_acpi_install_notify_handler(struct device *dev, u32 handler_type,
> + acpi_notify_handler handler, void *context)
> +{
> + struct acpi_notify_handler_devres *dr;
> + struct acpi_device *adev;
> + int ret;
> +
> + adev = ACPI_COMPANION(dev);
> + if (!adev)
> + return dev_err_probe(dev, -ENODEV, "No ACPI companion in %s()\n", __func__);
Not sure how __func__ may help here. We will have a device instance to be
printed. It's obvious then how to find the culprit call.
> + dr = devres_alloc(devm_acpi_notify_handler_release, sizeof(*dr), GFP_KERNEL);
> + if (!dr)
> + return -ENOMEM;
> +
> + ret = acpi_dev_install_notify_handler(adev, handler_type, handler, context);
> + if (ret) {
> + devres_free(dr);
> + return dev_err_probe(dev, ret, "Failed to install an ACPI notify handler\n");
> + }
> +
> + dr->handler = handler;
> + dr->handler_type = handler_type;
> + devres_add(dev, dr);
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler()
2026-06-02 18:50 ` Andy Shevchenko
@ 2026-06-02 20:57 ` Rafael J. Wysocki
2026-06-02 21:58 ` Andy Shevchenko
0 siblings, 1 reply; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-06-02 20:57 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Rafael J. Wysocki, Linux ACPI, LKML, Hans de Goede, Armin Wolf,
Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, nvdimm
On Tue, Jun 2, 2026 at 8:50 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, May 21, 2026 at 03:59:50PM +0200, Rafael J. Wysocki wrote:
>
> > Introduce devm_acpi_install_notify_handler() for installing an ACPI
> > notify handler managed by devres that will be removed automatically on
> > driver detach.
> >
> > It installs the notify handler on the device object in the ACPI
> > namespace that corresponds to the owner device's ACPI companion, if
> > present (an error is returned if the owner device doesn't have an ACPI
> > companion).
> >
> > Currently, there is no way to manually remove the notify handler
> > installed by it because none of its users brought on subsequently
> > will need to do that.
>
> ...
>
> > +static void devm_acpi_notify_handler_release(struct device *dev, void *res)
> > +{
> > + struct acpi_notify_handler_devres *dr = res;
>
> 'dr' is usually associated with internal devres structures and might be
> misleading in here, I would rename to something like handler_devres.
Well, whatever.
> > + acpi_dev_remove_notify_handler(ACPI_COMPANION(dev), dr->handler_type,
>
> acpi_dev might be also part of the same data structure, so you won't need to
> take dev again and derive adev from it.
I'm not sure what you mean.
Put acpi_dev into struct acpi_notify_handler_devres? That can be done
in a follow-up patch.
> > + dr->handler);
> > +}
>
> ...
>
> > +/**
> > + * devm_acpi_install_notify_handler - Install an ACPI notify handler for a
> > + * managed device
>
> There is a stray space just after asterisk.
Which asterisk?
> > + * @dev: Device to install a notify handler for
> > + * @handler_type: Type of the notify handler
> > + * @handler: Handler function to install
> > + * @context: Data passed back to the handler function
> > + *
> > + * This function performs the same function as acpi_dev_install_notify_handler()
> > + * called for the ACPI companion of @dev with the same @handler_type, @handler,
> > + * and @context arguments, but the ACPI notify handler installed by it will be
> > + * automatically removed on driver detach.
> > + *
> > + * Callers should ensure that all resources used by @handler have been allocated
> > + * prior to invoking this function, in which case those resources should be
> > + * devres-managed so that they won't be released before the notify handler
> > + * removal. Otherwise, special synchronization between @handler and the
> > + * management of those resources is required.
> > + *
> > + * When the request fails, an error message is printed with contextual
> > + * information (device name, handler function and error code). Don't add extra
>
> This "handler function" points to __func__? If so, it seems misleading.
Yes, this sentence should just be "When the request fails, an error
message is printed" without the "contextual information" part.
> > + * error messages at the call sites.
> > + *
> > + * Return: 0 on success or a negative error number.
> > + */
> > +int devm_acpi_install_notify_handler(struct device *dev, u32 handler_type,
> > + acpi_notify_handler handler, void *context)
> > +{
> > + struct acpi_notify_handler_devres *dr;
> > + struct acpi_device *adev;
> > + int ret;
> > +
> > + adev = ACPI_COMPANION(dev);
> > + if (!adev)
> > + return dev_err_probe(dev, -ENODEV, "No ACPI companion in %s()\n", __func__);
>
> Not sure how __func__ may help here. We will have a device instance to be
> printed. It's obvious then how to find the culprit call.
But it doesn't hurt either, does it?
> > + dr = devres_alloc(devm_acpi_notify_handler_release, sizeof(*dr), GFP_KERNEL);
> > + if (!dr)
> > + return -ENOMEM;
> > +
> > + ret = acpi_dev_install_notify_handler(adev, handler_type, handler, context);
> > + if (ret) {
> > + devres_free(dr);
> > + return dev_err_probe(dev, ret, "Failed to install an ACPI notify handler\n");
> > + }
> > +
> > + dr->handler = handler;
> > + dr->handler_type = handler_type;
> > + devres_add(dev, dr);
>
> > + return 0;
> > +}
>
> --
So thanks for the review, but I don't think I want to send a v2 at this point.
I'd rather send a follow-up patch to clean up these things.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler()
2026-06-02 20:57 ` Rafael J. Wysocki
@ 2026-06-02 21:58 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-06-02 21:58 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux ACPI, LKML, Hans de Goede, Armin Wolf, Dan Williams,
Vishal Verma, Dave Jiang, Ira Weiny, nvdimm
On Tue, Jun 02, 2026 at 10:57:23PM +0200, Rafael J. Wysocki wrote:
> On Tue, Jun 2, 2026 at 8:50 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, May 21, 2026 at 03:59:50PM +0200, Rafael J. Wysocki wrote:
...
> > > + acpi_dev_remove_notify_handler(ACPI_COMPANION(dev), dr->handler_type,
> >
> > acpi_dev might be also part of the same data structure, so you won't need to
> > take dev again and derive adev from it.
>
> I'm not sure what you mean.
>
> Put acpi_dev into struct acpi_notify_handler_devres?
Yes.
> > > + dr->handler);
...
> > > + * devm_acpi_install_notify_handler - Install an ACPI notify handler for a
> > > + * managed device
> >
> > There is a stray space just after asterisk.
>
> Which asterisk?
The line above has "<space>*<space>(sic!)<tab><tab> ... managed device".
The <space> after the asterisk is a stray one.
...
> > > + return dev_err_probe(dev, -ENODEV, "No ACPI companion in %s()\n", __func__);
> >
> > Not sure how __func__ may help here. We will have a device instance to be
> > printed. It's obvious then how to find the culprit call.
>
> But it doesn't hurt either, does it?
From my p.o.v. it's just extra information that's not needed. But I'm not going
fight to death against it.
...
> So thanks for the review, but I don't think I want to send a v2 at this point.
>
> I'd rather send a follow-up patch to clean up these things.
Okay!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management
2026-05-21 14:04 ` [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management Rafael J. Wysocki
@ 2026-06-02 22:10 ` Andy Shevchenko
2026-06-03 10:51 ` Rafael J. Wysocki
0 siblings, 1 reply; 25+ messages in thread
From: Andy Shevchenko @ 2026-06-02 22:10 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux ACPI, LKML, Hans de Goede, Armin Wolf
On Thu, May 21, 2026 at 04:04:03PM +0200, Rafael J. Wysocki wrote:
> Use the newly introduced devm_acpi_install_notify_handler() for
> installing an ACPI notify handler and since that function checks the
> ACPI companion of the owner device against NULL internally, remove the
> the explicit ACPI companion check from acpi_hed_probe().
>
> No intentional functional impact.
...
> static void acpi_hed_remove(struct platform_device *pdev)
> {
> - struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
> -
> hed_present = false;
> - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
> - acpi_hed_notify);
> }
devm will be cleaned after this, right? So, here is a window that if one tries
to unbind device from the driver in one thread and do the opposite in another
they will see the flag false while resources are still allocated for the old
one. It seems that hed_present should be also devm:ed?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management
2026-06-02 22:10 ` Andy Shevchenko
@ 2026-06-03 10:51 ` Rafael J. Wysocki
2026-06-03 11:12 ` Andy Shevchenko
0 siblings, 1 reply; 25+ messages in thread
From: Rafael J. Wysocki @ 2026-06-03 10:51 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Rafael J. Wysocki, Linux ACPI, LKML, Hans de Goede, Armin Wolf
On Wed, Jun 3, 2026 at 12:10 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, May 21, 2026 at 04:04:03PM +0200, Rafael J. Wysocki wrote:
>
> > Use the newly introduced devm_acpi_install_notify_handler() for
> > installing an ACPI notify handler and since that function checks the
> > ACPI companion of the owner device against NULL internally, remove the
> > the explicit ACPI companion check from acpi_hed_probe().
> >
> > No intentional functional impact.
>
> ...
>
> > static void acpi_hed_remove(struct platform_device *pdev)
> > {
> > - struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
> > -
> > hed_present = false;
> > - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
> > - acpi_hed_notify);
> > }
>
> devm will be cleaned after this, right?
Yes.
> So, here is a window that if one tries
> to unbind device from the driver in one thread and do the opposite in another
> they will see the flag false while resources are still allocated for the old
> one. It seems that hed_present should be also devm:ed?
If this is the same device, both binding and unbinding (including
devm) take place under its device lock which will serialize all of
that.
If they are different devices with different ACPI companions, there's
no resource conflict. If they are both valid HEDs (which would be a
stretch already) and they both trigger a notification exactly at the
"wrong" time (more stretch), worst-case stuff will be called twice in
a row via blocking_notifier_call_chain().
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management
2026-06-03 10:51 ` Rafael J. Wysocki
@ 2026-06-03 11:12 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-06-03 11:12 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: Linux ACPI, LKML, Hans de Goede, Armin Wolf
On Wed, Jun 03, 2026 at 12:51:20PM +0200, Rafael J. Wysocki wrote:
> On Wed, Jun 3, 2026 at 12:10 AM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, May 21, 2026 at 04:04:03PM +0200, Rafael J. Wysocki wrote:
...
> > > static void acpi_hed_remove(struct platform_device *pdev)
> > > {
> > > - struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
> > > -
> > > hed_present = false;
> > > - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
> > > - acpi_hed_notify);
> > > }
> >
> > devm will be cleaned after this, right?
>
> Yes.
>
> > So, here is a window that if one tries
> > to unbind device from the driver in one thread and do the opposite in another
> > they will see the flag false while resources are still allocated for the old
> > one. It seems that hed_present should be also devm:ed?
>
> If this is the same device, both binding and unbinding (including
> devm) take place under its device lock which will serialize all of
> that.
>
> If they are different devices with different ACPI companions, there's
> no resource conflict. If they are both valid HEDs (which would be a
> stretch already) and they both trigger a notification exactly at the
> "wrong" time (more stretch), worst-case stuff will be called twice in
> a row via blocking_notifier_call_chain().
Thanks for elaborating. We are good then.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2026-06-03 11:12 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-06-02 18:50 ` Andy Shevchenko
2026-06-02 20:57 ` Rafael J. Wysocki
2026-06-02 21:58 ` Andy Shevchenko
2026-05-21 14:01 ` [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-05-25 15:40 ` Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 04/17] ACPI: battery: " Rafael J. Wysocki
2026-05-21 14:03 ` [PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance Rafael J. Wysocki
2026-05-21 14:04 ` [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management Rafael J. Wysocki
2026-06-02 22:10 ` Andy Shevchenko
2026-06-03 10:51 ` Rafael J. Wysocki
2026-06-03 11:12 ` Andy Shevchenko
2026-05-21 14:04 ` [PATCH v1 07/17] ACPI: thermal: " Rafael J. Wysocki
2026-05-21 14:05 ` [PATCH v1 08/17] ACPI: PAD: Rearrange acpi_pad_notify() Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 09/17] ACPI: PAD: Pass struct device pointer to acpi_pad_notify() Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 10/17] ACPI: PAD: Fix teardown ordering in acpi_pad_remove() Rafael J. Wysocki
2026-05-21 14:07 ` [PATCH v1 11/17] ACPI: PAD: Switch over to devres-based resource management Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 12/17] ACPI: video: Reduce the number of auxiliary device dereferences Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 13/17] ACPI: video: Rearrange probe and remove code Rafael J. Wysocki
2026-05-21 14:09 ` [PATCH v1 14/17] ACPI: video: Use devm action for video bus object cleanup Rafael J. Wysocki
2026-05-21 14:10 ` [PATCH v1 15/17] ACPI: video: Use devm action for freeing video devices Rafael J. Wysocki
2026-05-21 14:10 ` [PATCH v1 16/17] ACPI: video: Use devm for video->entry and backlight cleanup Rafael J. Wysocki
2026-05-21 14:11 ` [PATCH v1 17/17] ACPI: video: Switch over to devres-based resource management Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox