Linux PWM subsystem development
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <ukleinek@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: Eliav Farber <farbere@amazon.com>,
	rafael@kernel.org,  tony.luck@intel.com, bp@alien8.de,
	guohanjun@huawei.com, mchehab@kernel.org,
	 xueshuai@linux.alibaba.com, lenb@kernel.org,
	laurent.pinchart@ideasonboard.com,  linusw@kernel.org,
	brgl@kernel.org, orsonzhai@gmail.com,
	 baolin.wang@linux.alibaba.com, zhang.lyra@gmail.com,
	jic23@kernel.org, dlechner@baylibre.com,  nuno.sa@analog.com,
	andy@kernel.org, dmitry.torokhov@gmail.com, hansg@kernel.org,
	 ilpo.jarvinen@linux.intel.com, W_Armin@gmx.de,
	fabio.m.de.francesco@linux.intel.com,  kaihengf@nvidia.com,
	ankita@nvidia.com, leitao@debian.org, pedro.pbg@usp.br,
	 paulmck@kernel.org, frederic@kernel.org, kees@kernel.org,
	linux-acpi@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-gpio@vger.kernel.org, linux-pwm@vger.kernel.org,
	 linux-iio@vger.kernel.org, linux-input@vger.kernel.org,
	platform-driver-x86@vger.kernel.org
Subject: Re: [PATCH v4 01/13] notifier: add device-managed registration APIs
Date: Tue, 11 Aug 2026 06:46:33 +0200	[thread overview]
Message-ID: <anqlfa6UADHn4qbo@monoceros> (raw)
In-Reply-To: <anmWCWT_p8sIMwyf@ashevche-desk.local>

[-- Attachment #1: Type: text/plain, Size: 2774 bytes --]

Hello Andy,

On Mon, Aug 10, 2026 at 12:12:41PM +0300, Andy Shevchenko wrote:
> On Mon, Aug 10, 2026 at 12:11:40PM +0300, Andy Shevchenko wrote:
> > On Mon, Aug 10, 2026 at 06:37:25AM +0200, Uwe Kleine-König wrote:
> > > On Sun, Jul 26, 2026 at 10:17:27AM +0000, Eliav Farber wrote:
> 
> ...
> 
> > > > +{
> > > > +	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);
> > > 
> > > 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.
> > 
> > Won't work. We need more than one parameter and hence the whole devres_alloc().

Oh indeed, justified concern.

> > 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-08-11  4:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-26 10:17 [PATCH v4 00/13] notifier: add device-managed registration APIs and convert drivers Eliav Farber
2026-07-26 10:17 ` [PATCH v4 01/13] notifier: add device-managed registration APIs Eliav Farber
2026-08-10  4:37   ` Uwe Kleine-König
2026-08-10  9:11     ` Andy Shevchenko
2026-08-10  9:12       ` Andy Shevchenko
2026-08-11  4:46         ` Uwe Kleine-König [this message]
2026-07-26 10:17 ` [PATCH v4 02/13] pwm: iqs620a: use devm_blocking_notifier_chain_register() Eliav Farber
2026-08-10  4:38   ` Uwe Kleine-König
2026-07-26 10:17 ` [PATCH v4 03/13] iio: light: iqs621-als: " Eliav Farber
2026-07-26 10:17 ` [PATCH v4 04/13] iio: position: iqs624: " Eliav Farber
2026-07-26 10:17 ` [PATCH v4 05/13] gpio: adp5585: " Eliav Farber
2026-07-26 10:17 ` [PATCH v4 06/13] platform/x86: bitland-mifs-wmi: " Eliav Farber
2026-07-26 10:17 ` [PATCH v4 07/13] Input: adp5585: " Eliav Farber
2026-07-26 10:17 ` [PATCH v4 08/13] ACPI: APEI: GHES: remove unused ghes_{,un}register_vendor_record_notifier() Eliav Farber
2026-07-27  1:57   ` Jonathan Cameron
2026-07-26 10:17 ` [PATCH v4 09/13] ACPI: APEI: GHES: use devm_blocking_notifier_chain_register() Eliav Farber
2026-07-27  1:59   ` Jonathan Cameron
2026-07-26 10:17 ` [PATCH v4 10/13] platform/x86: uniwill-wmi: " Eliav Farber
2026-07-27 18:48   ` Armin Wolf
2026-08-10  4:23   ` Uwe Kleine-König
2026-07-26 10:17 ` [PATCH v4 11/13] gpio: eic-sprd: use devm_atomic_notifier_chain_register() Eliav Farber
2026-07-27  3:12   ` Baolin Wang
2026-07-26 10:17 ` [PATCH v4 12/13] gpio: gpiolib-kunit: use devm_blocking_notifier_chain_register() Eliav Farber
2026-07-27 13:05   ` Bartosz Golaszewski
2026-07-26 10:17 ` [PATCH v4 13/13] reboot: " Eliav Farber
2026-07-26 14:10 ` [PATCH v4 00/13] notifier: add device-managed registration APIs and convert drivers Borislav Petkov
2026-07-27  7:47   ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anqlfa6UADHn4qbo@monoceros \
    --to=ukleinek@kernel.org \
    --cc=W_Armin@gmx.de \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=ankita@nvidia.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bp@alien8.de \
    --cc=brgl@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=fabio.m.de.francesco@linux.intel.com \
    --cc=farbere@amazon.com \
    --cc=frederic@kernel.org \
    --cc=guohanjun@huawei.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=kaihengf@nvidia.com \
    --cc=kees@kernel.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=leitao@debian.org \
    --cc=lenb@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=orsonzhai@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=pedro.pbg@usp.br \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=xueshuai@linux.alibaba.com \
    --cc=zhang.lyra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox