Skip to contentSkip to conversation

notifier: add device-managed registration APIs and convert drivers

PATCH Superseded Eliav Farber 9 participants 32 messages Jul 26 – Aug 16

Subsystems (12)
ACPI HID GPIO IIO +8 more subsystems

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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() 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 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                  |  21 +----
 include/acpi/ghes.h                        |  16 ----
 include/linux/notifier.h                   |   7 ++
 kernel/notifier.c                          | 103 +++++++++++++++++++++
 kernel/reboot.c                            |  24 +----
 14 files changed, 140 insertions(+), 209 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v4 1/13 notifier: add device-managed registration APIs

Add devm_atomic_notifier_chain_register() and devm_blocking_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.

A devm variant for raw notifier chains is intentionally not included because raw notifiers require the caller to provide all locking. The devres teardown callback has no way to acquire the caller's lock, and devres_alloc() with GFP_KERNEL cannot be used if the caller's lock is a spinlock.

---
Changes in v3:
- Drop devm_raw_notifier_chain_register() since raw notifiers require caller-provided locking which is incompatible with the devres teardown callback (Sashiko)

Changes in v2:
- Drop 'extern' from new function prototypes (Bart Van Assche)
- Fix kerneldoc to use 'Return:' format (Bart Van Assche)
- Use <linux/device/devres.h> instead of <linux/device.h> (Andy Shevchenko)

 include/linux/notifier.h |   7 +++
 kernel/notifier.c        | 103 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
include/linux/notifier.h +7 -0
index 01b6c9d9956f..4eeae9741a6e 100644
@@ -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,8 +146,14 @@ 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);
+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);
+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 srcu_notifier_chain_register(struct srcu_notifier_head *nh,
kernel/notifier.c +103 -0

119 lines not on this page · raw message

Signature · 1 line
2.47.3
#6 lore raw

PATCH v4 2/13 pwm: iqs620a: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

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.

---
 drivers/pwm/pwm-iqs620a.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
drivers/pwm/pwm-iqs620a.c +3 -18
index 13e5e138c8e9..12f7b1415ed4 100644
@@ -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
#8 lore raw

PATCH v4 3/13 iio: light: iqs621-als: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

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.

---
 drivers/iio/light/iqs621-als.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/iio/light/iqs621-als.c +3 -21
index cd5843e3e2c3..f9d215ef1970 100644
@@ -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
#9 lore raw

PATCH v4 4/13 iio: position: iqs624: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

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.

---
 drivers/iio/position/iqs624-pos.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)
drivers/iio/position/iqs624-pos.c +3 -21
index 8239239c6ee2..d2aa2df71457 100644
@@ -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
#10 lore raw

PATCH v4 5/13 gpio: adp5585: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the adp5585_gpio_unreg_notifier() callback.

---
 drivers/gpio/gpio-adp5585.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
drivers/gpio/gpio-adp5585.c +3 -17
index 6f10fc646008..7c04a7e86c8f 100644
@@ -390,16 +390,6 @@ static const struct irq_chip adp5585_irq_chip = {
 	GPIOCHIP_IRQ_RESOURCE_HELPERS,
 };
 
-static void adp5585_gpio_unreg_notifier(void *data)
-{
-	struct adp5585_gpio_dev *adp5585_gpio = data;
-	struct device *dev = adp5585_gpio->gpio_chip.parent;
-	struct adp5585_dev *adp5585 = dev_get_drvdata(dev->parent);
-
-	blocking_notifier_chain_unregister(&adp5585->event_notifier,
-					   &adp5585_gpio->nb);
-}
-
 static int adp5585_gpio_probe(struct platform_device *pdev)
 {
 	struct adp5585_dev *adp5585 = dev_get_drvdata(pdev->dev.parent);
@@ -450,13 +440,9 @@ static int adp5585_gpio_probe(struct platform_device *pdev)
 		girq->threaded = true;
 
 		adp5585_gpio->nb.notifier_call = adp5585_gpio_key_event;
-		ret = blocking_notifier_chain_register(&adp5585->event_notifier,
-						       &adp5585_gpio->nb);
-		if (ret)
-			return ret;
-
-		ret = devm_add_action_or_reset(dev, adp5585_gpio_unreg_notifier,
-					       adp5585_gpio);
+		ret = devm_blocking_notifier_chain_register(dev,
+							    &adp5585->event_notifier,
+							    &adp5585_gpio->nb);
 		if (ret)
 			return ret;
 	}
Signature · 1 line
2.47.3
#12 lore raw

PATCH v4 6/13 platform/x86: bitland-mifs-wmi: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the bitland_notifier_unregister() callback.

---
 drivers/platform/x86/bitland-mifs-wmi.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/platform/x86/bitland-mifs-wmi.c +3 -14
index 3a373184519d..2bcd4f692a74 100644
@@ -623,13 +623,6 @@ static const struct key_entry bitland_mifs_wmi_keymap[] = {
 	{ KE_END, 0 }
 };
 
-static void bitland_notifier_unregister(void *data)
-{
-	struct notifier_block *nb = data;
-
-	blocking_notifier_chain_unregister(&bitland_notifier_list, nb);
-}
-
 static int bitland_notifier_callback(struct notifier_block *nb,
 				     unsigned long action, void *data)
 {
@@ -729,13 +722,9 @@ static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context)
 		return ret;
 
 	drv_data->notifier.notifier_call = bitland_notifier_callback;
-	ret = blocking_notifier_chain_register(&bitland_notifier_list, &drv_data->notifier);
-	if (ret)
-		return ret;
-
-	return devm_add_action_or_reset(&wdev->dev,
-				       bitland_notifier_unregister,
-				       &drv_data->notifier);
+	return devm_blocking_notifier_chain_register(&wdev->dev,
+						     &bitland_notifier_list,
+						     &drv_data->notifier);
 }
 
 static void bitland_mifs_wmi_notify(struct wmi_device *wdev,
Signature · 1 line
2.47.3
#14 lore raw

PATCH v4 7/13 Input: adp5585: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the adp5585_keys_unreg_notifier() callback.

---
 drivers/input/keyboard/adp5585-keys.c | 18 +++---------------
 1 file changed, 3 insertions(+), 15 deletions(-)
drivers/input/keyboard/adp5585-keys.c +3 -15
index 017c95029180..0be4cc234c21 100644
@@ -254,15 +254,6 @@ static int adp5585_keys_ev_handle(struct notifier_block *nb, unsigned long key,
 	return NOTIFY_STOP;
 }
 
-static void adp5585_keys_unreg_notifier(void *data)
-{
-	struct adp5585_kpad *kpad = data;
-	struct adp5585_dev *adp5585 = dev_get_drvdata(kpad->dev->parent);
-
-	blocking_notifier_chain_unregister(&adp5585->event_notifier,
-					   &kpad->nb);
-}
-
 static int adp5585_keys_probe(struct platform_device *pdev)
 {
 	const struct platform_device_id *id = platform_get_device_id(pdev);
@@ -318,12 +309,9 @@ static int adp5585_keys_probe(struct platform_device *pdev)
 		return error;
 
 	kpad->nb.notifier_call = adp5585_keys_ev_handle;
-	error = blocking_notifier_chain_register(&adp5585->event_notifier,
-						 &kpad->nb);
-	if (error)
-		return error;
-
-	error = devm_add_action_or_reset(dev, adp5585_keys_unreg_notifier, kpad);
+	error = devm_blocking_notifier_chain_register(dev,
+						      &adp5585->event_notifier,
+						      &kpad->nb);
 	if (error)
 		return error;
 
Signature · 1 line
2.47.3
#15 lore raw

PATCH v4 8/13 ACPI: APEI: GHES: remove unused ghes_{,un}register_vendor_record_notifier()

In reply to Eliav Farber

Remove ghes_register_vendor_record_notifier() and ghes_unregister_vendor_record_notifier() along with their EXPORT_SYMBOL_GPL()s and ghes.h declarations, since there are no remaining in-tree callers — all users go through devm_ghes_register_vendor_record_notifier() instead.

Inline the register/unregister calls directly into devm_ghes_register_vendor_record_notifier() and its destroy callback.

---
Changes in v4:
- Split from the devm conversion patch into its own commit (Andy Shevchenko)

Changes in v2:
- New patch: remove unused ghes_register_vendor_record_notifier() and ghes_unregister_vendor_record_notifier() along with their EXPORT_SYMBOL_GPL()s and ghes.h declarations, since there are no in-tree callers (Jonathan Cameron)

 drivers/acpi/apei/ghes.c | 16 +++-------------
 include/acpi/ghes.h      | 16 ----------------
 2 files changed, 3 insertions(+), 29 deletions(-)
drivers/acpi/apei/ghes.c +3 -13
index 3236a3ce79d6..4e092f71ca84 100644
@@ -677,29 +677,19 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
 
 static BLOCKING_NOTIFIER_HEAD(vendor_record_notify_list);
 
-int ghes_register_vendor_record_notifier(struct notifier_block *nb)
+static void ghes_vendor_record_notifier_destroy(void *data)
 {
-	return blocking_notifier_chain_register(&vendor_record_notify_list, nb);
-}
-EXPORT_SYMBOL_GPL(ghes_register_vendor_record_notifier);
+	struct notifier_block *nb = data;
 
-void ghes_unregister_vendor_record_notifier(struct notifier_block *nb)
-{
 	blocking_notifier_chain_unregister(&vendor_record_notify_list, nb);
 }
-EXPORT_SYMBOL_GPL(ghes_unregister_vendor_record_notifier);
-
-static void ghes_vendor_record_notifier_destroy(void *nb)
-{
-	ghes_unregister_vendor_record_notifier(nb);
-}
 
 int devm_ghes_register_vendor_record_notifier(struct device *dev,
 					      struct notifier_block *nb)
 {
 	int ret;
 
-	ret = ghes_register_vendor_record_notifier(nb);
+	ret = blocking_notifier_chain_register(&vendor_record_notify_list, nb);
 	if (ret)
 		return ret;
 
include/acpi/ghes.h +0 -16
index 8d7e5caef3f1..3cd13171c14f 100644
@@ -55,22 +55,6 @@ enum {
 };
 
 #ifdef CONFIG_ACPI_APEI_GHES
-/**
- * ghes_register_vendor_record_notifier - register a notifier for vendor
- * records that the kernel would otherwise ignore.
- * @nb: pointer to the notifier_block structure of the event handler.
- *
- * return 0 : SUCCESS, non-zero : FAIL
- */
-int ghes_register_vendor_record_notifier(struct notifier_block *nb);
-
-/**
- * ghes_unregister_vendor_record_notifier - unregister the previously
- * registered vendor record notifier.
- * @nb: pointer to the notifier_block structure of the vendor record handler.
- */
-void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
-
 /**
  * devm_ghes_register_vendor_record_notifier - device-managed vendor
  * record notifier registration.
Signature · 1 line
2.47.3
#17 lore raw

PATCH v4 9/13 ACPI: APEI: GHES: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the ghes_vendor_record_notifier_destroy() callback.

---
Changes in v4:
- Split removal of unused code into a separate preceding patch (Andy Shevchenko)

 drivers/acpi/apei/ghes.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/acpi/apei/ghes.c +3 -14
index 4e092f71ca84..4419d430b7fd 100644
@@ -677,23 +677,12 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
 
 static BLOCKING_NOTIFIER_HEAD(vendor_record_notify_list);
 
-static void ghes_vendor_record_notifier_destroy(void *data)
-{
-	struct notifier_block *nb = data;
-
-	blocking_notifier_chain_unregister(&vendor_record_notify_list, nb);
-}
-
 int devm_ghes_register_vendor_record_notifier(struct device *dev,
 					      struct notifier_block *nb)
 {
-	int ret;
-
-	ret = blocking_notifier_chain_register(&vendor_record_notify_list, nb);
-	if (ret)
-		return ret;
-
-	return devm_add_action_or_reset(dev, ghes_vendor_record_notifier_destroy, nb);
+	return devm_blocking_notifier_chain_register(dev,
+						     &vendor_record_notify_list,
+						     nb);
 }
 EXPORT_SYMBOL_GPL(devm_ghes_register_vendor_record_notifier);
 
Signature · 1 line
2.47.3
#19 lore raw

PATCH v4 10/13 platform/x86: uniwill-wmi: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the devm_uniwill_wmi_unregister_notifier() callback.

---
 drivers/platform/x86/uniwill/uniwill-wmi.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/platform/x86/uniwill/uniwill-wmi.c +3 -14
index afcbfa4f7552..2ffa29a829ee 100644
@@ -26,22 +26,11 @@
 
 static BLOCKING_NOTIFIER_HEAD(uniwill_wmi_chain_head);
 
-static void devm_uniwill_wmi_unregister_notifier(void *data)
-{
-	struct notifier_block *nb = data;
-
-	blocking_notifier_chain_unregister(&uniwill_wmi_chain_head, nb);
-}
-
 int devm_uniwill_wmi_register_notifier(struct device *dev, struct notifier_block *nb)
 {
-	int ret;
-
-	ret = blocking_notifier_chain_register(&uniwill_wmi_chain_head, nb);
-	if (ret < 0)
-		return ret;
-
-	return devm_add_action_or_reset(dev, devm_uniwill_wmi_unregister_notifier, nb);
+	return devm_blocking_notifier_chain_register(dev,
+						     &uniwill_wmi_chain_head,
+						     nb);
 }
 
 static void uniwill_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
Signature · 1 line
2.47.3
#24 lore raw

PATCH v4 11/13 gpio: eic-sprd: use devm_atomic_notifier_chain_register()

In reply to Eliav Farber

Replace the atomic_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_atomic_notifier_chain_register(), removing the sprd_eic_unregister_notifier() callback.

---
 drivers/gpio/gpio-eic-sprd.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
drivers/gpio/gpio-eic-sprd.c +2 -15
index 3b7ebcf12fe7..86eb9624d38a 100644
@@ -601,13 +601,6 @@ static const struct irq_chip sprd_eic_irq = {
 	GPIOCHIP_IRQ_RESOURCE_HELPERS,
 };
 
-static void sprd_eic_unregister_notifier(void *data)
-{
-	struct notifier_block *nb = data;
-
-	atomic_notifier_chain_unregister(&sprd_eic_irq_notifier, nb);
-}
-
 static int sprd_eic_probe(struct platform_device *pdev)
 {
 	const struct sprd_eic_variant_data *pdata;
@@ -690,14 +683,8 @@ static int sprd_eic_probe(struct platform_device *pdev)
 	}
 
 	sprd_eic->irq_nb.notifier_call = sprd_eic_irq_notify;
-	ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
-					     &sprd_eic->irq_nb);
-	if (ret)
-		return dev_err_probe(dev, ret,
-				     "Failed to register with the interrupt notifier");
-
-	return devm_add_action_or_reset(dev, sprd_eic_unregister_notifier,
-					&sprd_eic->irq_nb);
+	return devm_atomic_notifier_chain_register(dev, &sprd_eic_irq_notifier,
+						   &sprd_eic->irq_nb);
 }
 
 static const struct of_device_id sprd_eic_of_match[] = {
Signature · 1 line
2.47.3
#27 lore raw

PATCH v4 12/13 gpio: gpiolib-kunit: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the gpio_unbind_unregister_notifier() callback.

---
 drivers/gpio/gpiolib-kunit.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/gpio/gpiolib-kunit.c +2 -12
index 380b68f879e5..8ce9acc89e29 100644
@@ -237,13 +237,6 @@ static int gpio_unbind_notify(struct notifier_block *nb, unsigned long action,
 	return NOTIFY_OK;
 }
 
-static void gpio_unbind_unregister_notifier(void *data)
-{
-	struct notifier_block *nb = data;
-
-	blocking_notifier_chain_unregister(&gpio_unbind_notifier, nb);
-}
-
 static int gpio_unbind_consumer_probe(struct platform_device *pdev)
 {
 	struct gpio_unbind_consumer_drvdata *data;
@@ -261,11 +254,8 @@ static int gpio_unbind_consumer_probe(struct platform_device *pdev)
 		return PTR_ERR(data->desc);
 
 	data->nb.notifier_call = gpio_unbind_notify;
-	ret = blocking_notifier_chain_register(&gpio_unbind_notifier, &data->nb);
-	if (ret)
-		return ret;
-
-	ret = devm_add_action_or_reset(dev, gpio_unbind_unregister_notifier, &data->nb);
+	ret = devm_blocking_notifier_chain_register(dev, &gpio_unbind_notifier,
+						    &data->nb);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.47.3
#29 lore raw

PATCH v4 13/13 reboot: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Replace the manual devres_alloc() + register_reboot_notifier() pattern with a single call to devm_blocking_notifier_chain_register(), removing the devm_unregister_reboot_notifier() callback.

---
Changes in v3:
- Fix commit message to accurately describe the old code as using devres_alloc() + register_reboot_notifier() (Sashiko)

 kernel/reboot.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)
kernel/reboot.c +2 -22
index 695c33e75efd..557609419989 100644
@@ -136,30 +136,10 @@ int unregister_reboot_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_reboot_notifier);
 
-static void devm_unregister_reboot_notifier(struct device *dev, void *res)
-{
-	WARN_ON(unregister_reboot_notifier(*(struct notifier_block **)res));
-}
-
 int devm_register_reboot_notifier(struct device *dev, struct notifier_block *nb)
 {
-	struct notifier_block **rcnb;
-	int ret;
-
-	rcnb = devres_alloc(devm_unregister_reboot_notifier,
-			    sizeof(*rcnb), GFP_KERNEL);
-	if (!rcnb)
-		return -ENOMEM;
-
-	ret = register_reboot_notifier(nb);
-	if (!ret) {
-		*rcnb = nb;
-		devres_add(dev, rcnb);
-	} else {
-		devres_free(rcnb);
-	}
-
-	return ret;
+	return devm_blocking_notifier_chain_register(dev,
+						     &reboot_notifier_list, nb);
 }
 EXPORT_SYMBOL(devm_register_reboot_notifier);
 
Signature · 1 line
2.47.3
#13 lore raw

Re: [PATCH v4 06/13] platform/x86: bitland-mifs-wmi: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Potential NULL pointer dereference in bitland_mifs_wmi_notify() when handling events for the CONTROL WMI device. --

--- Patch [6]: [PATCH v4 06/13] platform/x86: bitland-mifs-wmi: use devm_blocking_notifier_chain_register() --- commit b97b8d7c2a6f0ffd33788a7a075476a57a269e06
Author: Eliav Farber <[email protected]>

platform/x86: bitland-mifs-wmi: use devm_blocking_notifier_chain_register()

This commit simplifies the driver by replacing the combination of blocking_notifier_chain_register() and devm_add_action_or_reset() with a single call to devm_blocking_notifier_chain_register(). It also removes the now-unused bitland_notifier_unregister() callback.

Quoted 4 lines
drivers/platform/x86/bitland-mifs-wmi.c +0 -0
index b0d06a80e89ef..576d6f3733b4c 100644

[ ... ]

Quoted 7 lines
drivers/platform/x86/bitland-mifs-wmi.c +0 -3
@@ -721,13 +714,9 @@ static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context)
 		return ret;
 
 	drv_data->notifier.notifier_call = bitland_notifier_callback;
-	ret = blocking_notifier_chain_register(&bitland_notifier_list, &drv_data->notifier);
-	if (ret)
-		return ret;

drivers/platform/x86/bitland-mifs-wmi.c static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context) · line 722

Quoted 10 lines
drivers/platform/x86/bitland-mifs-wmi.c +3 -4
-
-	return devm_add_action_or_reset(&wdev->dev,
-				       bitland_notifier_unregister,
-				       &drv_data->notifier);
+	return devm_blocking_notifier_chain_register(&wdev->dev,
+						     &bitland_notifier_list,
+						     &drv_data->notifier);
 }
 
 static void bitland_mifs_wmi_notify(struct wmi_device *wdev,

[Severity: High]
This is a pre-existing issue, but I noticed a potential NULL pointer dereference in the notification handler.

During bitland_mifs_wmi_probe(), data->input_dev is only allocated if the device type is BITLAND_WMI_EVENT. However, if firmware sends a hotkey event to the control device, bitland_mifs_wmi_notify() will run without checking if data->input_dev is actually allocated:

bitland_mifs_wmi_notify()

    ...
    case WMI_EVENT_OPEN_APP:
    case WMI_EVENT_CALCULATOR_START:
    case WMI_EVENT_BROWSER_START: {
        guard(mutex)(&data->lock);
        if (!sparse_keymap_report_event(data->input_dev,
                                        event->event_id, 1, true))

Could this cause a kernel panic in sparse_keymap_report_event() since it doesn't defensively check for a NULL input_dev?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#11 lore raw

Re: [PATCH v4 05/13] gpio: adp5585: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Use-after-free of the gpiochip's IRQ domain during device unbinding due to incorrect devres registration order. --

--- Patch [5]: [PATCH v4 05/13] gpio: adp5585: use devm_blocking_notifier_chain_register() --- commit 44c510dbb3ca8a6273606da82607128231bd2e31
Author: Eliav Farber <[email protected]>

gpio: adp5585: use devm_blocking_notifier_chain_register()

This commit replaces the manual blocking_notifier_chain_register() and devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), dropping the standalone unregister callback.

Quoted 3 lines
drivers/gpio/gpio-adp5585.c +0 -0

[ ... ]

Quoted 4 lines
drivers/gpio/gpio-adp5585.c +0 -0
@@ -450,13 +440,9 @@ static int adp5585_gpio_probe(struct platform_device *pdev)
 		girq->threaded = true;
 
 		adp5585_gpio->nb.notifier_call = adp5585_gpio_key_event;

drivers/gpio/gpio-adp5585.c static int adp5585_gpio_probe(struct platform_device *pdev) · line 445

Quoted 10 lines
drivers/gpio/gpio-adp5585.c +3 -7
-		ret = blocking_notifier_chain_register(&adp5585->event_notifier,
-						       &adp5585_gpio->nb);
-		if (ret)
-			return ret;
-
-		ret = devm_add_action_or_reset(dev, adp5585_gpio_unreg_notifier,
-					       adp5585_gpio);
+		ret = devm_blocking_notifier_chain_register(dev,
+							    &adp5585->event_notifier,
+							    &adp5585_gpio->nb);

[Severity: High]
This is a pre-existing issue, but does this devres registration order create a use-after-free during device unbind?

Because the notifier is registered before the GPIO chip is added via devm_gpiochip_add_data() later in adp5585_gpio_probe(), devres will process the teardown in LIFO order. This means the GPIO chip and its IRQ domain are removed and freed first.

If an interrupt fires after the GPIO chip is removed but before the notifier is unregistered, the notifier callback adp5585_gpio_key_event() will attempt to access the freed domain:

drivers/gpio/gpio-adp5585.c:adp5585_gpio_key_event() {
    ...
	irq = irq_find_mapping(adp5585_gpio->gpio_chip.irq.domain, off);
	if (!irq)
		return NOTIFY_BAD;
    ...
}

Should the notifier registration be moved after devm_gpiochip_add_data() to ensure a safe teardown sequence?

Quoted 3 lines
drivers/gpio/gpio-adp5585.c +0 -0
 		if (ret)
 			return ret;
 	}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#25 lore raw

Re: [PATCH v4 11/13] gpio: eic-sprd: use devm_atomic_notifier_chain_register()

In reply to Eliav Farber
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Unbinding one EIC sub-module will break interrupts for all other active sub-modules sharing the same parent IRQ. --

--- Patch [11]: [PATCH v4 11/13] gpio: eic-sprd: use devm_atomic_notifier_chain_register() --- commit 55c8bafe72677fc98fb136d26d8a1306172a3b1f
Author: Eliav Farber <[email protected]>

gpio: eic-sprd: use devm_atomic_notifier_chain_register()

This commit replaces the atomic_notifier_chain_register() and devm_add_action_or_reset() pattern with a single call to devm_atomic_notifier_chain_register(). This removes the need for the custom sprd_eic_unregister_notifier() callback.

Quoted 4 lines
drivers/gpio/gpio-eic-sprd.c +0 -0
index 3b7ebcf12fe7f..86eb9624d38ac 100644

[ ... ]

drivers/gpio/gpio-eic-sprd.c static int sprd_eic_probe(struct platform_device *pdev)

Quoted 1 line
drivers/gpio/gpio-eic-sprd.c +0 -0
@@ -690,14 +683,8 @@ static int sprd_eic_probe(struct platform_device *pdev)

[Severity: High]
This is a pre-existing issue, but I noticed something about how the parent interrupt is configured earlier in sprd_eic_probe().

The driver sets up the shared parent interrupt line as a non-shared chained handler before registering the gpiochip:

    irq->parent_handler = sprd_eic_irq_handler;

Since the SPRD EIC hardware exposes up to 4 sub-modules that share the same parent interrupt line, does unbinding one of these sub-modules break interrupts for all other active sub-modules?

When a sub-module is unbound via sysfs or fails a late probe step, its devres cleanup invokes gpiochip_remove(). This unconditionally calls irq_set_chained_handler_and_data(parent_irq, NULL, NULL) which clears the shared chained handler completely.

Will this result in a silent loss of GPIO interrupt functionality for the remaining active EIC sub-modules sharing that parent IRQ?

Quoted 14 lines
drivers/gpio/gpio-eic-sprd.c +2 -8
 	}
 
 	sprd_eic->irq_nb.notifier_call = sprd_eic_irq_notify;
-	ret = atomic_notifier_chain_register(&sprd_eic_irq_notifier,
-					     &sprd_eic->irq_nb);
-	if (ret)
-		return dev_err_probe(dev, ret,
-				     "Failed to register with the interrupt notifier");
-
-	return devm_add_action_or_reset(dev, sprd_eic_unregister_notifier,
-					&sprd_eic->irq_nb);
+	return devm_atomic_notifier_chain_register(dev, &sprd_eic_irq_notifier,
+						   &sprd_eic->irq_nb);
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#30 lore raw
In reply to Eliav Farber
Quoted 2 lines · Eliav Farber

Many drivers repeat the same boilerplate when registering notifiers with device lifetime:

From: Documentation/process/submitting-patches.rst

Don't get discouraged - or impatient
------------------------------------

After you have submitted your change, be patient and wait. Reviewers are busy people and may not get to your patch right away.

Once upon a time, patches used to disappear into the void without comment, but the development process works more smoothly than that now. You should receive comments within a week or so; if that does not happen, make sure that you have sent your patches to the right place. Wait for a minimum of

						     ^^^^^^^^^^^^^^^^^^^^^

one week before resubmitting or pinging reviewers - possibly longer during ^^^^^^^^^^^^^^^^^^^^^^^^^^^
busy times like merge windows.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
maintainer Reviewed-by on v4 8/13
#16 lore raw

Re: [PATCH v4 08/13] ACPI: APEI: GHES: remove unused ghes_{,un}register_vendor_record_notifier()

In reply to Eliav Farber
Quoted 10 lines · On Sun, 26 Jul 2026 10:17:34 +0000 Eliav Farber <[email protected]> wrote:

Remove ghes_register_vendor_record_notifier() and ghes_unregister_vendor_record_notifier() along with their EXPORT_SYMBOL_GPL()s and ghes.h declarations, since there are no remaining in-tree callers — all users go through devm_ghes_register_vendor_record_notifier() instead.

Inline the register/unregister calls directly into devm_ghes_register_vendor_record_notifier() and its destroy callback.

+CC Shiju Jose who wrote this code in the first place.

Looks fine to me.

Quoted 79 lines

---
Changes in v4:
- Split from the devm conversion patch into its own commit (Andy Shevchenko)

Changes in v2:
- New patch: remove unused ghes_register_vendor_record_notifier() and ghes_unregister_vendor_record_notifier() along with their EXPORT_SYMBOL_GPL()s and ghes.h declarations, since there are no in-tree callers (Jonathan Cameron)

 drivers/acpi/apei/ghes.c | 16 +++-------------
 include/acpi/ghes.h      | 16 ----------------
 2 files changed, 3 insertions(+), 29 deletions(-)
drivers/acpi/apei/ghes.c +3 -13
index 3236a3ce79d6..4e092f71ca84 100644
@@ -677,29 +677,19 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
 
 static BLOCKING_NOTIFIER_HEAD(vendor_record_notify_list);
 
-int ghes_register_vendor_record_notifier(struct notifier_block *nb)
+static void ghes_vendor_record_notifier_destroy(void *data)
 {
-	return blocking_notifier_chain_register(&vendor_record_notify_list, nb);
-}
-EXPORT_SYMBOL_GPL(ghes_register_vendor_record_notifier);
+	struct notifier_block *nb = data;
 
-void ghes_unregister_vendor_record_notifier(struct notifier_block *nb)
-{
 	blocking_notifier_chain_unregister(&vendor_record_notify_list, nb);
 }
-EXPORT_SYMBOL_GPL(ghes_unregister_vendor_record_notifier);
-
-static void ghes_vendor_record_notifier_destroy(void *nb)
-{
-	ghes_unregister_vendor_record_notifier(nb);
-}
 
 int devm_ghes_register_vendor_record_notifier(struct device *dev,
 					      struct notifier_block *nb)
 {
 	int ret;
 
-	ret = ghes_register_vendor_record_notifier(nb);
+	ret = blocking_notifier_chain_register(&vendor_record_notify_list, nb);
 	if (ret)
 		return ret;
 
include/acpi/ghes.h +0 -16
index 8d7e5caef3f1..3cd13171c14f 100644
@@ -55,22 +55,6 @@ enum {
 };
 
 #ifdef CONFIG_ACPI_APEI_GHES
-/**
- * ghes_register_vendor_record_notifier - register a notifier for vendor
- * records that the kernel would otherwise ignore.
- * @nb: pointer to the notifier_block structure of the event handler.
- *
- * return 0 : SUCCESS, non-zero : FAIL
- */
-int ghes_register_vendor_record_notifier(struct notifier_block *nb);
-
-/**
- * ghes_unregister_vendor_record_notifier - unregister the previously
- * registered vendor record notifier.
- * @nb: pointer to the notifier_block structure of the vendor record handler.
- */
-void ghes_unregister_vendor_record_notifier(struct notifier_block *nb);
-
 /**
  * devm_ghes_register_vendor_record_notifier - device-managed vendor
  * record notifier registration.
maintainer Reviewed-by on v4 9/13
#18 lore raw

Re: [PATCH v4 09/13] ACPI: APEI: GHES: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber
Quoted 6 lines · On Sun, 26 Jul 2026 10:17:35 +0000 Eliav Farber <[email protected]> wrote:

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the ghes_vendor_record_notifier_destroy() callback.

Btw I fully agree with Borislav reply to say slow down!

I'm not sure anyone will like having 3 versions in their inbox when they get in to work tomorrow.

Jonathan

Reviewed-by on v4 11/13
#26 lore raw

Re: [PATCH v4 11/13] gpio: eic-sprd: use devm_atomic_notifier_chain_register()

In reply to Eliav Farber
Quoted 8 lines · Eliav Farber

Replace the atomic_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_atomic_notifier_chain_register(), removing the sprd_eic_unregister_notifier() callback.

---

LGTM.

#31 lore raw
In reply to Borislav Petkov
Quoted 21 lines · Borislav Petkov
Quoted 2 lines · Eliav Farber

Many drivers repeat the same boilerplate when registering notifiers with device lifetime:

From: Documentation/process/submitting-patches.rst

Don't get discouraged - or impatient
------------------------------------

After you have submitted your change, be patient and wait. Reviewers are busy people and may not get to your patch right away.

Once upon a time, patches used to disappear into the void without comment, but the development process works more smoothly than that now. You should receive comments within a week or so; if that does not happen, make sure that you have sent your patches to the right place. Wait for a minimum of

						     ^^^^^^^^^^^^^^^^^^^^^

one week before resubmitting or pinging reviewers - possibly longer during ^^^^^^^^^^^^^^^^^^^^^^^^^^^
busy times like merge windows.

Quoted 6 lines

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

If the above snippet is not clear enough: *do not send three different versions of a series on a Sunday*.

Thanks,
Bartosz

maintainer Acked-by on v4 12/13
#28 lore raw

Re: [PATCH v4 12/13] gpio: gpiolib-kunit: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber
Quoted 7 lines · Eliav Farber

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the gpio_unbind_unregister_notifier() callback.

---

Assuming I'll get an immutable branch OR it doesn't conflict too much:

Otherwise, this should wait until the next cycle if possible.

Bart

maintainer Reviewed-by on v4 10/13
#20 lore raw

Re: [PATCH v4 10/13] platform/x86: uniwill-wmi: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Am 26.07.26 um 12:17 schrieb Eliav Farber:

Quoted 5 lines

Replace the blocking_notifier_chain_register() + devm_add_action_or_reset() pattern with a single call to devm_blocking_notifier_chain_register(), removing the devm_uniwill_wmi_unregister_notifier() callback.

Quoted 35 lines
---
  drivers/platform/x86/uniwill/uniwill-wmi.c | 17 +++--------------
  1 file changed, 3 insertions(+), 14 deletions(-)
drivers/platform/x86/uniwill/uniwill-wmi.c +3 -14
index afcbfa4f7552..2ffa29a829ee 100644
@@ -26,22 +26,11 @@
 
  static BLOCKING_NOTIFIER_HEAD(uniwill_wmi_chain_head);
 
-static void devm_uniwill_wmi_unregister_notifier(void *data)
-{
-	struct notifier_block *nb = data;
-
-	blocking_notifier_chain_unregister(&uniwill_wmi_chain_head, nb);
-}
-
  int devm_uniwill_wmi_register_notifier(struct device *dev, struct notifier_block *nb)
  {
-	int ret;
-
-	ret = blocking_notifier_chain_register(&uniwill_wmi_chain_head, nb);
-	if (ret < 0)
-		return ret;
-
-	return devm_add_action_or_reset(dev, devm_uniwill_wmi_unregister_notifier, nb);
+	return devm_blocking_notifier_chain_register(dev,
+						     &uniwill_wmi_chain_head,
+						     nb);
  }
 
  static void uniwill_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
#21 lore raw

Re: [PATCH v4 10/13] platform/x86: uniwill-wmi: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Hello,

drivers/platform/x86/uniwill/uniwill-wmi.c line 34

Quoted 13 lines · Eliav Farber

int devm_uniwill_wmi_register_notifier(struct device *dev, struct notifier_block *nb) {

drivers/platform/x86/uniwill/uniwill-wmi.c +3 -7
-	int ret;
-
-	ret = blocking_notifier_chain_register(&uniwill_wmi_chain_head, nb);
-	if (ret < 0)
-		return ret;
-
-	return devm_add_action_or_reset(dev, devm_uniwill_wmi_unregister_notifier, nb);
+	return devm_blocking_notifier_chain_register(dev,
+						     &uniwill_wmi_chain_head,
+						     nb);
 }

I'd remove this function and replace calls to it directly by devm_blocking_notifier_chain_register().

Best regards
Uwe

#2 lore raw

Re: [PATCH v4 01/13] notifier: add device-managed registration APIs

In reply to Eliav Farber

Hello,

Quoted 53 lines · Eliav Farber
kernel/notifier.c +40 -0
index 2f9fe7c30287..c1a66fa0c331 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/device/devres.h>
 #include <linux/kdebug.h>
 #include <linux/kprobes.h>
 #include <linux/export.h>
@@ -197,6 +198,56 @@ 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.
+ *
+ *	Return:
+ *	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);

kernel/notifier.c int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, · line 249

Quoted 10 lines
kernel/notifier.c +10 -0
+		return ret;
+	}
+
+	dr->nh = nh;
+	dr->nb = n;
+	devres_add(dev, dr);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_atomic_notifier_chain_register);

IMHO devm_atomic_notifier_chain_register() should look as follows:

	ret = atomic_notifier_chain_register(nh, n);
	if (ret)
		return ret;

	return devm_add_action_or_reset(dev, devm_atomic_notifier_chain_unregister, dr)

which is much easier and includes less details from the inner workings of devm. Same for the blocking variant.

Best regards
Uwe

#7 lore raw

Re: [PATCH v4 02/13] pwm: iqs620a: use devm_blocking_notifier_chain_register()

In reply to Eliav Farber

Hello,

Quoted 20 lines · Eliav Farber

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.

---
 drivers/pwm/pwm-iqs620a.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
drivers/pwm/pwm-iqs620a.c +0 -2
index 13e5e138c8e9..12f7b1415ed4 100644
@@ -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)
-{

drivers/pwm/pwm-iqs620a.c static const struct pwm_ops iqs620_pwm_ops = { · line 177

Quoted 10 lines
drivers/pwm/pwm-iqs620a.c +0 -8
-	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);
-}
 

Too much remaining whitespace here. Other than that looks ok.

There is no specified merge plan yet, and this depends on patch #1, so it cannot get applied yet. Given that IMHO patch #1 should change, I expect there will be a v5 and we can consider application then.

Best regards
Uwe

#3 lore raw

Re: [PATCH v4 01/13] notifier: add device-managed registration APIs

In reply to Uwe Kleine-König
Quoted 1 line · Uwe Kleine-König

On Sun, Jul 26, 2026 at 10:17:27AM +0000, Eliav Farber wrote:

...

Quoted 25 lines
Quoted 12 lines
kernel/notifier.c +12 -0
+{
+	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);

kernel/notifier.c int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, · line 249

Quoted 10 lines
kernel/notifier.c +10 -0
+		return ret;
+	}
+
+	dr->nh = nh;
+	dr->nb = n;
+	devres_add(dev, dr);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_atomic_notifier_chain_register);

IMHO devm_atomic_notifier_chain_register() should look as follows:

Quoted 8 lines
	ret = atomic_notifier_chain_register(nh, n);
	if (ret)
		return ret;

	return devm_add_action_or_reset(dev, devm_atomic_notifier_chain_unregister, dr)

which is much easier and includes less details from the inner workings of devm. Same for the blocking variant.

Won't work. We need more than one parameter and hence the whole devres_alloc(). Please, look closer to the code.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v4 01/13] notifier: add device-managed registration APIs

Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König

On Sun, Jul 26, 2026 at 10:17:27AM +0000, Eliav Farber wrote:

...

Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
kernel/notifier.c +12 -0
+{
+	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);

kernel/notifier.c int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, · line 249

Quoted 10 lines
kernel/notifier.c +10 -0
+		return ret;
+	}
+
+	dr->nh = nh;
+	dr->nb = n;
+	devres_add(dev, dr);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_atomic_notifier_chain_register);

IMHO devm_atomic_notifier_chain_register() should look as follows:

	ret = atomic_notifier_chain_register(nh, n);
	if (ret)
		return ret;
Quoted 7 lines
Quoted 4 lines

return devm_add_action_or_reset(dev, devm_atomic_notifier_chain_unregister, dr)

which is much easier and includes less details from the inner workings of devm. Same for the blocking variant.

Won't work. We need more than one parameter and hence the whole devres_alloc(). Please, look closer to the code.

And just answering ahead, no, devm_kmalloc() is not good bandaid as it makes code not anyhow better to read and have a downside of memory fragmentation.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH v4 01/13] notifier: add device-managed registration APIs

Hello Andy,

Quoted 35 lines · Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Uwe Kleine-König

On Sun, Jul 26, 2026 at 10:17:27AM +0000, Eliav Farber wrote:

...

Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
kernel/notifier.c +12 -0
+{
+	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);

kernel/notifier.c int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, · line 249

Quoted 10 lines
kernel/notifier.c +10 -0
+		return ret;
+	}
+
+	dr->nh = nh;
+	dr->nb = n;
+	devres_add(dev, dr);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(devm_atomic_notifier_chain_register);

IMHO devm_atomic_notifier_chain_register() should look as follows:

	ret = atomic_notifier_chain_register(nh, n);
	if (ret)
		return ret;
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

return devm_add_action_or_reset(dev, devm_atomic_notifier_chain_unregister, dr)

which is much easier and includes less details from the inner workings of devm. Same for the blocking variant.

Won't work. We need more than one parameter and hence the whole devres_alloc().

Oh indeed, justified concern.

Quoted 4 lines
Quoted 1 line

Please, look closer to the code.

And just answering ahead, no, devm_kmalloc() is not good bandaid as it makes code not anyhow better to read and have a downside of memory fragmentation.

My idea would be to introduce a variant of devm_add_action_or_reset() that copies the data (in a way to prevent the fragmentation), such that the function could look as follows:

int devm_atomic_notifier_chain_register(struct device *dev,
struct atomic_notifier_head *nh, struct notifier_block *n)

{
	struct atomic_notifier_chain_devres dr = {
		.nh = nh,
		/*
		 * Maybe rename n to nb (or vice-versa) to make the
		 * names match here?
		 */
		.nb = n,
	};
	int ret;
	
	ret = atomic_notifier_chain_register(nh, n);
	if (ret)
		return ret;
	
	return devm_copy_data_and_add_action_or_reset(dev,
						      devm_atomic_notifier_chain_unregister,
						      &dr, sizeof(dr));
}

The name is ugly and long, but IMHO the semantics are useful and the new devm_atomic_notifier_chain_register() looks IMHO nicer that the original from Eliav's patch.

But that would be a separate topic, so going with the currently suggested approach is fine for me.

If you rename n to nb, you can have my ack.

Best regards
Uwe

#22 lore raw

RE: [PATCH v4 10/13] platform/x86: uniwill-wmi: use devm_blocking_notifier_chain_register()

In reply to Uwe Kleine-König
Quoted 8 lines · Eliav Farber
Quoted 7 lines

int devm_uniwill_wmi_register_notifier(struct device *dev, struct
notifier_block *nb) {

drivers/platform/x86/uniwill/uniwill-wmi.c +0 -5
-	int ret;
-
-	ret = blocking_notifier_chain_register(&uniwill_wmi_chain_head, nb);
-	if (ret < 0)
-		return ret;
Quoted 8 lines

drivers/platform/x86/uniwill/uniwill-wmi.c line 34

Quoted 6 lines
drivers/platform/x86/uniwill/uniwill-wmi.c +3 -2
-
-	return devm_add_action_or_reset(dev, devm_uniwill_wmi_unregister_notifier, nb);
+	return devm_blocking_notifier_chain_register(dev,
+						     &uniwill_wmi_chain_head,
+						     nb);
 }

I'd remove this function and replace calls to it directly by devm_blocking_notifier_chain_register().

uniwill_wmi_chain_head is static in uniwill-wmi.c and the caller is in uniwill-acpi.c. The wrapper encapsulates access to this module-private notifier head - removing it would require exposing the variable through the header, which breaks the current abstraction.

I'd prefer to keep the wrapper as-is.

Best regards
Eliav

#23 lore raw

Re: [PATCH v4 10/13] platform/x86: uniwill-wmi: use devm_blocking_notifier_chain_register()

Hello,

Quoted 17 lines · Eliav
Quoted 8 lines · Eliav Farber
Quoted 7 lines

int devm_uniwill_wmi_register_notifier(struct device *dev, struct
notifier_block *nb) {

drivers/platform/x86/uniwill/uniwill-wmi.c +0 -5
-	int ret;
-
-	ret = blocking_notifier_chain_register(&uniwill_wmi_chain_head, nb);
-	if (ret < 0)
-		return ret;
Quoted 8 lines

drivers/platform/x86/uniwill/uniwill-wmi.c line 34

Quoted 6 lines
drivers/platform/x86/uniwill/uniwill-wmi.c +3 -2
-
-	return devm_add_action_or_reset(dev, devm_uniwill_wmi_unregister_notifier, nb);
+	return devm_blocking_notifier_chain_register(dev,
+						     &uniwill_wmi_chain_head,
+						     nb);
 }

I'd remove this function and replace calls to it directly by devm_blocking_notifier_chain_register().

Quoted 6 lines

uniwill_wmi_chain_head is static in uniwill-wmi.c and the caller is in uniwill-acpi.c. The wrapper encapsulates access to this module-private notifier head - removing it would require exposing the variable through the header, which breaks the current abstraction.

I'd prefer to keep the wrapper as-is.

Sounds like a good justification, thanks for considering my suggestion.

Uwe