* [PATCH 00/12] notifier: add device-managed registration APIs and convert drivers
@ 2026-07-23 17:53 Eliav Farber
2026-07-23 17:53 ` [PATCH 01/12] notifier: add device-managed registration APIs Eliav Farber
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eliav Farber @ 2026-07-23 17:53 UTC (permalink / raw)
To: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
laurent.pinchart, linusw, brgl, orsonzhai, baolin.wang,
zhang.lyra, jic23, dlechner, nuno.sa, andy, dmitry.torokhov,
hansg, ilpo.jarvinen, W_Armin, ukleinek, fabio.m.de.francesco,
kaihengf, ankita, leitao, farbere, jason, pedro.pbg, paulmck,
frederic, kees, linux-acpi, linux-kernel, linux-gpio, linux-pwm,
linux-iio, linux-input, platform-driver-x86
Many drivers repeat the same boilerplate when registering notifiers with
device lifetime:
1. Register the notifier with *_notifier_chain_register()
2. Check for error
3. Register a devm action to unregister on teardown
4. Implement a per-driver static unregister callback
This series adds devm_atomic_notifier_chain_register(),
devm_blocking_notifier_chain_register(), and
devm_raw_notifier_chain_register() that automatically unregister the
notifier when the device is unbound, then converts 11 drivers to use
them.
Each conversion eliminates a per-driver unregister callback and the
associated devm_add_action_or_reset() call, reducing code by ~15 lines
per driver.
The implementation follows the established devres pattern used by other
device-managed kernel APIs.
Checkpatch reports 6 CHECKs (0 errors, 0 warnings) on patch 1:
- "extern prototypes should be avoided in .h files"
- "Alignment should match open parenthesis"
Both are intentional to match the existing coding style in notifier.h,
where all declarations use 'extern' and tab-indented continuation lines.
Eliav Farber (12):
notifier: add device-managed registration APIs
pwm: iqs620a: use devm_blocking_notifier_chain_register()
iio: light: iqs621-als: use devm_blocking_notifier_chain_register()
iio: position: iqs624: use devm_blocking_notifier_chain_register()
gpio: adp5585: use devm_blocking_notifier_chain_register()
platform/x86: bitland-mifs-wmi: use
devm_blocking_notifier_chain_register()
Input: adp5585: use devm_blocking_notifier_chain_register()
ACPI: APEI: GHES: use devm_blocking_notifier_chain_register()
platform/x86: uniwill-wmi: use devm_blocking_notifier_chain_register()
gpio: eic-sprd: use devm_atomic_notifier_chain_register()
gpio: gpiolib-kunit: use devm_blocking_notifier_chain_register()
reboot: use devm_blocking_notifier_chain_register()
drivers/acpi/apei/ghes.c | 15 +-
drivers/gpio/gpio-adp5585.c | 20 +--
drivers/gpio/gpio-eic-sprd.c | 17 +--
drivers/gpio/gpiolib-kunit.c | 14 +-
drivers/iio/light/iqs621-als.c | 24 +---
drivers/iio/position/iqs624-pos.c | 24 +---
drivers/input/keyboard/adp5585-keys.c | 18 +--
drivers/platform/x86/bitland-mifs-wmi.c | 17 +--
drivers/platform/x86/uniwill/uniwill-wmi.c | 17 +--
drivers/pwm/pwm-iqs620a.c | 21 +--
include/linux/notifier.h | 10 ++
kernel/notifier.c | 151 +++++++++++++++++++++
kernel/reboot.c | 24 +---
13 files changed, 191 insertions(+), 181 deletions(-)
--
2.47.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 01/12] notifier: add device-managed registration APIs
2026-07-23 17:53 [PATCH 00/12] notifier: add device-managed registration APIs and convert drivers Eliav Farber
@ 2026-07-23 17:53 ` Eliav Farber
2026-07-23 17:53 ` [PATCH 02/12] pwm: iqs620a: use devm_blocking_notifier_chain_register() Eliav Farber
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eliav Farber @ 2026-07-23 17:53 UTC (permalink / raw)
To: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
laurent.pinchart, linusw, brgl, orsonzhai, baolin.wang,
zhang.lyra, jic23, dlechner, nuno.sa, andy, dmitry.torokhov,
hansg, ilpo.jarvinen, W_Armin, ukleinek, fabio.m.de.francesco,
kaihengf, ankita, leitao, farbere, jason, pedro.pbg, paulmck,
frederic, kees, linux-acpi, linux-kernel, linux-gpio, linux-pwm,
linux-iio, linux-input, platform-driver-x86
Add devm_atomic_notifier_chain_register(),
devm_blocking_notifier_chain_register(), and
devm_raw_notifier_chain_register() that automatically unregister the
notifier when the device is unbound.
Many drivers repeat the same boilerplate pattern:
1. Register the notifier with *_notifier_chain_register()
2. Check for error
3. Register a devm action to unregister on teardown
4. Implement a per-driver static unregister callback
With the new devm_*_notifier_chain_register() APIs, this reduces to a
single call with one error path, eliminating per-driver unregister
callbacks entirely.
The implementation follows the established devres pattern used by other
device-managed kernel APIs.
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
include/linux/notifier.h | 10 +++
kernel/notifier.c | 151 +++++++++++++++++++++++++++++++++++++++
2 files changed, 161 insertions(+)
diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 01b6c9d9956f..aa3745d7459b 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -46,6 +46,7 @@
* often but notifier_blocks will seldom be removed.
*/
+struct device;
struct notifier_block;
typedef int (*notifier_fn_t)(struct notifier_block *nb,
@@ -145,10 +146,19 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
struct notifier_block *nb);
+extern int devm_atomic_notifier_chain_register(struct device *dev,
+ struct atomic_notifier_head *nh,
+ struct notifier_block *nb);
extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
struct notifier_block *nb);
+extern int devm_blocking_notifier_chain_register(struct device *dev,
+ struct blocking_notifier_head *nh,
+ struct notifier_block *nb);
extern int raw_notifier_chain_register(struct raw_notifier_head *nh,
struct notifier_block *nb);
+extern int devm_raw_notifier_chain_register(struct device *dev,
+ struct raw_notifier_head *nh,
+ struct notifier_block *nb);
extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
struct notifier_block *nb);
diff --git a/kernel/notifier.c b/kernel/notifier.c
index 2f9fe7c30287..b811638aa878 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/device.h>
#include <linux/kdebug.h>
#include <linux/kprobes.h>
#include <linux/export.h>
@@ -197,6 +198,55 @@ int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
}
EXPORT_SYMBOL_GPL(atomic_notifier_chain_unregister);
+struct atomic_notifier_chain_devres {
+ struct atomic_notifier_head *nh;
+ struct notifier_block *nb;
+};
+
+static void devm_atomic_notifier_chain_unregister(struct device *dev, void *res)
+{
+ struct atomic_notifier_chain_devres *dr = res;
+
+ atomic_notifier_chain_unregister(dr->nh, dr->nb);
+}
+
+/**
+ * devm_atomic_notifier_chain_register - Device-managed atomic notifier registration
+ * @dev: Device to tie the notifier lifetime to
+ * @nh: Pointer to head of the atomic notifier chain
+ * @n: New entry in notifier chain
+ *
+ * Adds a notifier to an atomic notifier chain and registers a cleanup
+ * action to automatically unregister it when @dev is unbound.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+int devm_atomic_notifier_chain_register(struct device *dev,
+ struct atomic_notifier_head *nh,
+ struct notifier_block *n)
+{
+ struct atomic_notifier_chain_devres *dr;
+ int ret;
+
+ dr = devres_alloc(devm_atomic_notifier_chain_unregister,
+ sizeof(*dr), GFP_KERNEL);
+ if (!dr)
+ return -ENOMEM;
+
+ ret = atomic_notifier_chain_register(nh, n);
+ if (ret) {
+ devres_free(dr);
+ return ret;
+ }
+
+ dr->nh = nh;
+ dr->nb = n;
+ devres_add(dev, dr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_atomic_notifier_chain_register);
+
/**
* atomic_notifier_call_chain - Call functions in an atomic notifier chain
* @nh: Pointer to head of the atomic notifier chain
@@ -349,6 +399,57 @@ int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
}
EXPORT_SYMBOL_GPL(blocking_notifier_call_chain_robust);
+struct blocking_notifier_chain_devres {
+ struct blocking_notifier_head *nh;
+ struct notifier_block *nb;
+};
+
+static void devm_blocking_notifier_chain_unregister(struct device *dev,
+ void *res)
+{
+ struct blocking_notifier_chain_devres *dr = res;
+
+ blocking_notifier_chain_unregister(dr->nh, dr->nb);
+}
+
+/**
+ * devm_blocking_notifier_chain_register - Device-managed blocking notifier registration
+ * @dev: Device to tie the notifier lifetime to
+ * @nh: Pointer to head of the blocking notifier chain
+ * @n: New entry in notifier chain
+ *
+ * Adds a notifier to a blocking notifier chain and registers a cleanup
+ * action to automatically unregister it when @dev is unbound.
+ * Must be called in process context.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+int devm_blocking_notifier_chain_register(struct device *dev,
+ struct blocking_notifier_head *nh,
+ struct notifier_block *n)
+{
+ struct blocking_notifier_chain_devres *dr;
+ int ret;
+
+ dr = devres_alloc(devm_blocking_notifier_chain_unregister,
+ sizeof(*dr), GFP_KERNEL);
+ if (!dr)
+ return -ENOMEM;
+
+ ret = blocking_notifier_chain_register(nh, n);
+ if (ret) {
+ devres_free(dr);
+ return ret;
+ }
+
+ dr->nh = nh;
+ dr->nb = n;
+ devres_add(dev, dr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_blocking_notifier_chain_register);
+
/**
* blocking_notifier_call_chain - Call functions in a blocking notifier chain
* @nh: Pointer to head of the blocking notifier chain
@@ -430,6 +531,56 @@ int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
}
EXPORT_SYMBOL_GPL(raw_notifier_call_chain_robust);
+struct raw_notifier_chain_devres {
+ struct raw_notifier_head *nh;
+ struct notifier_block *nb;
+};
+
+static void devm_raw_notifier_chain_unregister(struct device *dev, void *res)
+{
+ struct raw_notifier_chain_devres *dr = res;
+
+ raw_notifier_chain_unregister(dr->nh, dr->nb);
+}
+
+/**
+ * devm_raw_notifier_chain_register - Device-managed raw notifier registration
+ * @dev: Device to tie the notifier lifetime to
+ * @nh: Pointer to head of the raw notifier chain
+ * @n: New entry in notifier chain
+ *
+ * Adds a notifier to a raw notifier chain and registers a cleanup
+ * action to automatically unregister it when @dev is unbound.
+ * All locking must be provided by the caller.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+int devm_raw_notifier_chain_register(struct device *dev,
+ struct raw_notifier_head *nh,
+ struct notifier_block *n)
+{
+ struct raw_notifier_chain_devres *dr;
+ int ret;
+
+ dr = devres_alloc(devm_raw_notifier_chain_unregister,
+ sizeof(*dr), GFP_KERNEL);
+ if (!dr)
+ return -ENOMEM;
+
+ ret = raw_notifier_chain_register(nh, n);
+ if (ret) {
+ devres_free(dr);
+ return ret;
+ }
+
+ dr->nh = nh;
+ dr->nb = n;
+ devres_add(dev, dr);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(devm_raw_notifier_chain_register);
+
/**
* raw_notifier_call_chain - Call functions in a raw notifier chain
* @nh: Pointer to head of the raw notifier chain
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 02/12] pwm: iqs620a: use devm_blocking_notifier_chain_register()
2026-07-23 17:53 [PATCH 00/12] notifier: add device-managed registration APIs and convert drivers Eliav Farber
2026-07-23 17:53 ` [PATCH 01/12] notifier: add device-managed registration APIs Eliav Farber
@ 2026-07-23 17:53 ` Eliav Farber
2026-07-23 17:53 ` [PATCH 03/12] iio: light: iqs621-als: " Eliav Farber
2026-07-23 17:53 ` [PATCH 04/12] iio: position: iqs624: " Eliav Farber
3 siblings, 0 replies; 5+ messages in thread
From: Eliav Farber @ 2026-07-23 17:53 UTC (permalink / raw)
To: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
laurent.pinchart, linusw, brgl, orsonzhai, baolin.wang,
zhang.lyra, jic23, dlechner, nuno.sa, andy, dmitry.torokhov,
hansg, ilpo.jarvinen, W_Armin, ukleinek, fabio.m.de.francesco,
kaihengf, ankita, leitao, farbere, jason, pedro.pbg, paulmck,
frederic, kees, linux-acpi, linux-kernel, linux-gpio, linux-pwm,
linux-iio, linux-input, platform-driver-x86
Replace the blocking_notifier_chain_register() +
devm_add_action_or_reset() pattern with a single call to
devm_blocking_notifier_chain_register(), removing the
iqs620_pwm_notifier_unregister() callback.
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
drivers/pwm/pwm-iqs620a.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/drivers/pwm/pwm-iqs620a.c b/drivers/pwm/pwm-iqs620a.c
index 13e5e138c8e9..12f7b1415ed4 100644
--- a/drivers/pwm/pwm-iqs620a.c
+++ b/drivers/pwm/pwm-iqs620a.c
@@ -173,17 +173,7 @@ static const struct pwm_ops iqs620_pwm_ops = {
.get_state = iqs620_pwm_get_state,
};
-static void iqs620_pwm_notifier_unregister(void *context)
-{
- struct iqs620_pwm_private *iqs620_pwm = context;
- int ret;
- ret = blocking_notifier_chain_unregister(&iqs620_pwm->iqs62x->nh,
- &iqs620_pwm->notifier);
- if (ret)
- dev_err(iqs620_pwm->dev,
- "Failed to unregister notifier: %d\n", ret);
-}
static int iqs620_pwm_probe(struct platform_device *pdev)
{
@@ -218,19 +208,14 @@ static int iqs620_pwm_probe(struct platform_device *pdev)
mutex_init(&iqs620_pwm->lock);
iqs620_pwm->notifier.notifier_call = iqs620_pwm_notifier;
- ret = blocking_notifier_chain_register(&iqs620_pwm->iqs62x->nh,
- &iqs620_pwm->notifier);
+ ret = devm_blocking_notifier_chain_register(&pdev->dev,
+ &iqs620_pwm->iqs62x->nh,
+ &iqs620_pwm->notifier);
if (ret) {
dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret);
return ret;
}
- ret = devm_add_action_or_reset(&pdev->dev,
- iqs620_pwm_notifier_unregister,
- iqs620_pwm);
- if (ret)
- return ret;
-
ret = devm_pwmchip_add(&pdev->dev, chip);
if (ret)
dev_err(&pdev->dev, "Failed to add device: %d\n", ret);
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 03/12] iio: light: iqs621-als: use devm_blocking_notifier_chain_register()
2026-07-23 17:53 [PATCH 00/12] notifier: add device-managed registration APIs and convert drivers Eliav Farber
2026-07-23 17:53 ` [PATCH 01/12] notifier: add device-managed registration APIs Eliav Farber
2026-07-23 17:53 ` [PATCH 02/12] pwm: iqs620a: use devm_blocking_notifier_chain_register() Eliav Farber
@ 2026-07-23 17:53 ` Eliav Farber
2026-07-23 17:53 ` [PATCH 04/12] iio: position: iqs624: " Eliav Farber
3 siblings, 0 replies; 5+ messages in thread
From: Eliav Farber @ 2026-07-23 17:53 UTC (permalink / raw)
To: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
laurent.pinchart, linusw, brgl, orsonzhai, baolin.wang,
zhang.lyra, jic23, dlechner, nuno.sa, andy, dmitry.torokhov,
hansg, ilpo.jarvinen, W_Armin, ukleinek, fabio.m.de.francesco,
kaihengf, ankita, leitao, farbere, jason, pedro.pbg, paulmck,
frederic, kees, linux-acpi, linux-kernel, linux-gpio, linux-pwm,
linux-iio, linux-input, platform-driver-x86
Replace the blocking_notifier_chain_register() +
devm_add_action_or_reset() pattern with a single call to
devm_blocking_notifier_chain_register(), removing the
iqs621_als_notifier_unregister() callback.
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
drivers/iio/light/iqs621-als.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/drivers/iio/light/iqs621-als.c b/drivers/iio/light/iqs621-als.c
index cd5843e3e2c3..f9d215ef1970 100644
--- a/drivers/iio/light/iqs621-als.c
+++ b/drivers/iio/light/iqs621-als.c
@@ -179,19 +179,6 @@ static int iqs621_als_notifier(struct notifier_block *notifier,
return NOTIFY_OK;
}
-static void iqs621_als_notifier_unregister(void *context)
-{
- struct iqs621_als_private *iqs621_als = context;
- struct iio_dev *indio_dev = iqs621_als->indio_dev;
- int ret;
-
- ret = blocking_notifier_chain_unregister(&iqs621_als->iqs62x->nh,
- &iqs621_als->notifier);
- if (ret)
- dev_err(indio_dev->dev.parent,
- "Failed to unregister notifier: %d\n", ret);
-}
-
static int iqs621_als_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -563,19 +550,14 @@ static int iqs621_als_probe(struct platform_device *pdev)
mutex_init(&iqs621_als->lock);
iqs621_als->notifier.notifier_call = iqs621_als_notifier;
- ret = blocking_notifier_chain_register(&iqs621_als->iqs62x->nh,
- &iqs621_als->notifier);
+ ret = devm_blocking_notifier_chain_register(&pdev->dev,
+ &iqs621_als->iqs62x->nh,
+ &iqs621_als->notifier);
if (ret) {
dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret);
return ret;
}
- ret = devm_add_action_or_reset(&pdev->dev,
- iqs621_als_notifier_unregister,
- iqs621_als);
- if (ret)
- return ret;
-
return devm_iio_device_register(&pdev->dev, indio_dev);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 04/12] iio: position: iqs624: use devm_blocking_notifier_chain_register()
2026-07-23 17:53 [PATCH 00/12] notifier: add device-managed registration APIs and convert drivers Eliav Farber
` (2 preceding siblings ...)
2026-07-23 17:53 ` [PATCH 03/12] iio: light: iqs621-als: " Eliav Farber
@ 2026-07-23 17:53 ` Eliav Farber
3 siblings, 0 replies; 5+ messages in thread
From: Eliav Farber @ 2026-07-23 17:53 UTC (permalink / raw)
To: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
laurent.pinchart, linusw, brgl, orsonzhai, baolin.wang,
zhang.lyra, jic23, dlechner, nuno.sa, andy, dmitry.torokhov,
hansg, ilpo.jarvinen, W_Armin, ukleinek, fabio.m.de.francesco,
kaihengf, ankita, leitao, farbere, jason, pedro.pbg, paulmck,
frederic, kees, linux-acpi, linux-kernel, linux-gpio, linux-pwm,
linux-iio, linux-input, platform-driver-x86
Replace the blocking_notifier_chain_register() +
devm_add_action_or_reset() pattern with a single call to
devm_blocking_notifier_chain_register(), removing the
iqs624_pos_notifier_unregister() callback.
Signed-off-by: Eliav Farber <farbere@amazon.com>
---
drivers/iio/position/iqs624-pos.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git a/drivers/iio/position/iqs624-pos.c b/drivers/iio/position/iqs624-pos.c
index 8239239c6ee2..d2aa2df71457 100644
--- a/drivers/iio/position/iqs624-pos.c
+++ b/drivers/iio/position/iqs624-pos.c
@@ -96,19 +96,6 @@ static int iqs624_pos_notifier(struct notifier_block *notifier,
return ret;
}
-static void iqs624_pos_notifier_unregister(void *context)
-{
- struct iqs624_pos_private *iqs624_pos = context;
- struct iio_dev *indio_dev = iqs624_pos->indio_dev;
- int ret;
-
- ret = blocking_notifier_chain_unregister(&iqs624_pos->iqs62x->nh,
- &iqs624_pos->notifier);
- if (ret)
- dev_err(indio_dev->dev.parent,
- "Failed to unregister notifier: %d\n", ret);
-}
-
static int iqs624_pos_angle_get(struct iqs62x_core *iqs62x, unsigned int *val)
{
int ret;
@@ -255,19 +242,14 @@ static int iqs624_pos_probe(struct platform_device *pdev)
mutex_init(&iqs624_pos->lock);
iqs624_pos->notifier.notifier_call = iqs624_pos_notifier;
- ret = blocking_notifier_chain_register(&iqs624_pos->iqs62x->nh,
- &iqs624_pos->notifier);
+ ret = devm_blocking_notifier_chain_register(&pdev->dev,
+ &iqs624_pos->iqs62x->nh,
+ &iqs624_pos->notifier);
if (ret) {
dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret);
return ret;
}
- ret = devm_add_action_or_reset(&pdev->dev,
- iqs624_pos_notifier_unregister,
- iqs624_pos);
- if (ret)
- return ret;
-
return devm_iio_device_register(&pdev->dev, indio_dev);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-23 17:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23 17:53 [PATCH 00/12] notifier: add device-managed registration APIs and convert drivers Eliav Farber
2026-07-23 17:53 ` [PATCH 01/12] notifier: add device-managed registration APIs Eliav Farber
2026-07-23 17:53 ` [PATCH 02/12] pwm: iqs620a: use devm_blocking_notifier_chain_register() Eliav Farber
2026-07-23 17:53 ` [PATCH 03/12] iio: light: iqs621-als: " Eliav Farber
2026-07-23 17:53 ` [PATCH 04/12] iio: position: iqs624: " Eliav Farber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox