notifier: add device-managed registration APIs and convert drivers
cover notifier: add device-managed registration APIs and convert drivers
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(-)
Signature · 1 line
2.47.3
PATCH 1/12 notifier: add device-managed registration APIs
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.
--- include/linux/notifier.h | 10 +++ kernel/notifier.c | 151 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+)
include/linux/notifier.h +10 -0
@@ -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);
kernel/notifier.c +151 -0
173 lines not on this page · raw message
Signature · 1 line
2.47.3
Bartosz Golaszewski
maintainerRe: [PATCH 01/12] notifier: add device-managed registration APIs
Quoted 38 lines · Eliav Farber
Add
devm_atomic_notifier_chain_register(),devm_blocking_notifier_chain_register(), anddevm_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 callbackWith 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 <[email protected]>--- include/linux/notifier.h | 10 +++ kernel/notifier.c | 151 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+)include/linux/notifier.h +1
-0@@ -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,
include/linux/notifier.h extern void srcu_init_notifier_head(struct srcu_notifier_head *nh); · line 151
Quoted 6 lines
include/linux/notifier.h +3
-0@@ -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);
Please don't use extern with function prototypes in new code.
Quoted 39 lines
include/linux/notifier.h +6
-0extern 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);kernel/notifier.c +13
-0@@ -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); +} +
kernel/notifier.c int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, · line 222
Quoted 10 lines
kernel/notifier.c +10
-0+/** +* 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.
Should be:
Returns:
0 on success...
Bart
RE: [PATCH 01/12] notifier: add device-managed registration APIs
Quoted 7 lines
Quoted 7 lines
include/linux/notifier.h +1
-0+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);
Quoted 7 lines
include/linux/notifier.h extern void srcu_init_notifier_head(struct srcu_notifier_head *nh); · line 151
Quoted 5 lines
include/linux/notifier.h +3
-0extern 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);Please don't use extern with function prototypes in new code.
Fixed in v2
Quoted 11 lines
kernel/notifier.c int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, · line 222
Quoted 10 lines
kernel/notifier.c +10
-0+/** +* 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.
Quoted 4 lines
Should be:
Returns:
0 on success...
Fixed in v2
Thanks, Eliav
PATCH 2/12 pwm: iqs620a: use devm_blocking_notifier_chain_register()
In reply to Eliav FarberReplace 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.
--- drivers/pwm/pwm-iqs620a.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
drivers/pwm/pwm-iqs620a.c +3 -18
@@ -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);
Signature · 1 line
2.47.3
PATCH 3/12 iio: light: iqs621-als: use devm_blocking_notifier_chain_register()
In reply to Eliav FarberReplace 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.
--- drivers/iio/light/iqs621-als.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/iio/light/iqs621-als.c +3 -21
@@ -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); }
Signature · 1 line
2.47.3
Re: [PATCH 03/12] iio: light: iqs621-als: use devm_blocking_notifier_chain_register()
Quoted 6 lines · On Thu, 23 Jul 2026 17:53:16 +0000 Eliav Farber <[email protected]> wrote:
Replace the
blocking_notifier_chain_register()+devm_add_action_or_reset()pattern with a single call todevm_blocking_notifier_chain_register(), removing theiqs621_als_notifier_unregister()callback.Signed-off-by Eliav Farber <[email protected]>
Seems relatively unlikely to cause a merge conflict if these changes go through non subsystem trees - hence the Ack rather than asking for an immutable branch with patch 1 on it.
Thanks,
Jonathan
PATCH 4/12 iio: position: iqs624: use devm_blocking_notifier_chain_register()
In reply to Eliav FarberReplace 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.
--- drivers/iio/position/iqs624-pos.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/iio/position/iqs624-pos.c +3 -21
@@ -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); }
Signature · 1 line
2.47.3
Re: [PATCH 04/12] iio: position: iqs624: use devm_blocking_notifier_chain_register()
Quoted 6 lines · On Thu, 23 Jul 2026 17:53:17 +0000 Eliav Farber <[email protected]> wrote:
Replace the
blocking_notifier_chain_register()+devm_add_action_or_reset()pattern with a single call todevm_blocking_notifier_chain_register(), removing theiqs624_pos_notifier_unregister()callback.Signed-off-by Eliav Farber <[email protected]>
Bartosz Golaszewski
maintainerQuoted 21 lines · Eliav Farber
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 callbackThis series adds
devm_atomic_notifier_chain_register(),devm_blocking_notifier_chain_register(), anddevm_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.
Quoted 7 lines
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.
What is the merging strategy? Acks and all patches go through driver core?
Bartosz