[PATCH v5 00/13] notifier: add device-managed registration APIs and convert drivers

Eliav Farber posted 13 patches 1 month, 1 week ago
drivers/acpi/apei/ghes.c                   |  27 +-----
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                  |  23 +----
include/acpi/ghes.h                        |  16 ----
include/linux/notifier.h                   |   7 ++
kernel/notifier.c                          | 103 +++++++++++++++++++++
kernel/reboot.c                            |  24 +----
14 files changed, 140 insertions(+), 211 deletions(-)
[PATCH v5 00/13] notifier: add device-managed registration APIs and convert drivers
Posted by Eliav Farber 1 month, 1 week ago
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() and
devm_blocking_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.

Changes in v5:
- Patch 1: rename notifier_block parameter from 'n' to 'nb' to match
  the devres struct field name (Uwe Kleine-König)
- Patch 2: remove extra blank line left after deleting the unregister
  callback (Uwe Kleine-König)

Changes in v4:
- Patch 8: split the removal of unused
  ghes_register_vendor_record_notifier() and
  ghes_unregister_vendor_record_notifier() into a separate preceding
  patch (Andy Shevchenko)

Changes in v3:
- Patch 1: drop devm_raw_notifier_chain_register() since raw notifiers
  require caller-provided locking which is incompatible with the devres
  teardown callback (Sashiko)
- Patch 12: fix commit message to accurately describe the old code as
  using devres_alloc() + register_reboot_notifier() (Sashiko)

Changes in v2:
- Patch 1: drop 'extern' from new function prototypes (Bart Van Assche)
- Patch 1: fix kerneldoc to use 'Return:' format (Bart Van Assche)
- Patch 1: use <linux/device/devres.h> instead of <linux/device.h>
  (Andy Shevchenko)
- Patch 8: also remove unused ghes_register_vendor_record_notifier() and
  ghes_unregister_vendor_record_notifier() along with their exports and
  ghes.h declarations (Jonathan Cameron)

Eliav Farber (13):
  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: remove unused
    ghes_{,un}register_vendor_record_notifier()
  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                   |  27 +-----
 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                  |  23 +----
 include/acpi/ghes.h                        |  16 ----
 include/linux/notifier.h                   |   7 ++
 kernel/notifier.c                          | 103 +++++++++++++++++++++
 kernel/reboot.c                            |  24 +----
 14 files changed, 140 insertions(+), 211 deletions(-)

-- 
2.47.3

[GIT PULL] Base commit for devm_{atomic,blocking}_notifier_chain_register()
Posted by Uwe Kleine-König 1 month, 1 week ago
Hello,

On Sun, Aug 16, 2026 at 06:05:59AM +0000, Eliav Farber wrote:
> 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() and
> devm_blocking_notifier_chain_register() that automatically unregister
> the notifier when the device is unbound, then converts 11 drivers to use
> them.

I applied the first patch on top of v7.2 for you to merge into your
subsystem trees as base for applying the patch(es) from this series that
should go via your tree.

Find it at

  https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git tags/devm_notifier_chain_register-for-7.3

This tag only contains this single commit e38b9eda475f ("notifier: add
device-managed registration APIs"). I intend to include it in my PR for
v7.3-rc1, feel free to do the same.

Best regards
Uwe
Re: [GIT PULL] Base commit for devm_{atomic,blocking}_notifier_chain_register()
Posted by Uwe Kleine-König 1 month, 1 week ago
On Fri, Aug 21, 2026 at 04:07:18PM +0200, Uwe Kleine-König wrote:
> On Sun, Aug 16, 2026 at 06:05:59AM +0000, Eliav Farber wrote:
> > 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() and
> > devm_blocking_notifier_chain_register() that automatically unregister
> > the notifier when the device is unbound, then converts 11 drivers to use
> > them.
> 
> I applied the first patch on top of v7.2 for you to merge into your
> subsystem trees as base for applying the patch(es) from this series that
> should go via your tree.
> 
> Find it at
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git tags/devm_notifier_chain_register-for-7.3
> 
> This tag only contains this single commit e38b9eda475f ("notifier: add
> device-managed registration APIs"). I intend to include it in my PR for
> v7.3-rc1, feel free to do the same.

While I tried to pick up the pwm patch in this series I noticed my
Arithmetic error here 🙄. It should be 7.4 of course. I created

	https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git tags/devm_notifier_chain_register-for-7.4

with a fixed tag message and dropped the 7.3 tag. (Even is someone
already pulled it, nothing bad happens as it points to the same commit.)

Sorry for the confusion.
Uwe
Re: (subset) [PATCH v5 00/13] notifier: add device-managed registration APIs and convert drivers
Posted by Bartosz Golaszewski 1 month ago
On Sun, 16 Aug 2026 06:05:59 +0000, Eliav Farber wrote:
> 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
> 
> [...]

Applied, thanks!

[05/13] gpio: adp5585: use devm_blocking_notifier_chain_register()
        https://git.kernel.org/brgl/c/870f46a42afdc65d39587d2c56cf35eca294d201
[11/13] gpio: eic-sprd: use devm_atomic_notifier_chain_register()
        https://git.kernel.org/brgl/c/32390690610190f63a31f92ca555077f7861657c
[12/13] gpio: gpiolib-kunit: use devm_blocking_notifier_chain_register()
        https://git.kernel.org/brgl/c/df6501bf6fc4b16c9f502a7ab8e785ec91f3f7e3

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>