Linux ACPI
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux ACPI <linux-acpi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Hans de Goede <hansg@kernel.org>, Armin Wolf <w_armin@gmx.de>,
	Dan Williams <djbw@kernel.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	nvdimm@lists.linux.dev
Subject: Re: [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler()
Date: Tue, 2 Jun 2026 21:50:34 +0300	[thread overview]
Message-ID: <ah8l-p0Ih9tzu0G1@ashevche-desk.local> (raw)
In-Reply-To: <2268031.irdbgypaU6@rafael.j.wysocki>

On Thu, May 21, 2026 at 03:59:50PM +0200, Rafael J. Wysocki wrote:

> Introduce devm_acpi_install_notify_handler() for installing an ACPI
> notify handler managed by devres that will be removed automatically on
> driver detach.
> 
> It installs the notify handler on the device object in the ACPI
> namespace that corresponds to the owner device's ACPI companion, if
> present (an error is returned if the owner device doesn't have an ACPI
> companion).
> 
> Currently, there is no way to manually remove the notify handler
> installed by it because none of its users brought on subsequently
> will need to do that.

...

> +static void devm_acpi_notify_handler_release(struct device *dev, void *res)
> +{
> +	struct acpi_notify_handler_devres *dr = res;

'dr' is usually associated with internal devres structures and might be
misleading in here, I would rename to something like handler_devres.

> +	acpi_dev_remove_notify_handler(ACPI_COMPANION(dev), dr->handler_type,

acpi_dev might be also part of the same data structure, so you won't need to
take dev again and derive adev from it.

> +				       dr->handler);
> +}

...

> +/**
> + * devm_acpi_install_notify_handler - Install an ACPI notify handler for a
> + * 				      managed device

There is a stray space just after asterisk.

> + * @dev: Device to install a notify handler for
> + * @handler_type: Type of the notify handler
> + * @handler: Handler function to install
> + * @context: Data passed back to the handler function
> + *
> + * This function performs the same function as acpi_dev_install_notify_handler()
> + * called for the ACPI companion of @dev with the same @handler_type, @handler,
> + * and @context arguments, but the ACPI notify handler installed by it will be
> + * automatically removed on driver detach.
> + *
> + * Callers should ensure that all resources used by @handler have been allocated
> + * prior to invoking this function, in which case those resources should be
> + * devres-managed so that they won't be released before the notify handler
> + * removal.  Otherwise, special synchronization between @handler and the
> + * management of those resources is required.
> + *
> + * When the request fails, an error message is printed with contextual
> + * information (device name, handler function and error code).  Don't add extra

This "handler function" points to __func__? If so, it seems misleading.

> + * error messages at the call sites.
> + *
> + * Return: 0 on success or a negative error number.
> + */
> +int devm_acpi_install_notify_handler(struct device *dev, u32 handler_type,
> +				     acpi_notify_handler handler, void *context)
> +{
> +	struct acpi_notify_handler_devres *dr;
> +	struct acpi_device *adev;
> +	int ret;
> +
> +	adev = ACPI_COMPANION(dev);
> +	if (!adev)
> +		return dev_err_probe(dev, -ENODEV, "No ACPI companion in %s()\n", __func__);

Not sure how __func__ may help here. We will have a device instance to be
printed. It's obvious then how to find the culprit call.

> +	dr = devres_alloc(devm_acpi_notify_handler_release, sizeof(*dr), GFP_KERNEL);
> +	if (!dr)
> +		return -ENOMEM;
> +
> +	ret = acpi_dev_install_notify_handler(adev, handler_type, handler, context);
> +	if (ret) {
> +		devres_free(dr);
> +		return dev_err_probe(dev, ret, "Failed to install an ACPI notify handler\n");
> +	}
> +
> +	dr->handler = handler;
> +	dr->handler_type = handler_type;
> +	devres_add(dev, dr);

> +	return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-06-02 18:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 13:57 [PATCH v1 00/17] ACPI: driver: Use devres-based resource management Rafael J. Wysocki
2026-05-21 13:59 ` [PATCH v1 01/17] ACPI: bus: Introduce devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-06-02 18:50   ` Andy Shevchenko [this message]
2026-06-02 20:57     ` Rafael J. Wysocki
2026-06-02 21:58       ` Andy Shevchenko
2026-05-21 14:01 ` [PATCH v1 02/17] ACPI: NFIT: core: Use devm_acpi_install_notify_handler() Rafael J. Wysocki
2026-05-25 15:40   ` Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 03/17] ACPI: AC: Switch over to devres-based resource management Rafael J. Wysocki
2026-05-21 14:02 ` [PATCH v1 04/17] ACPI: battery: " Rafael J. Wysocki
2026-05-21 14:03 ` [PATCH v1 05/17] ACPI: HED: Refine guarding against adding a second instance Rafael J. Wysocki
2026-05-21 14:04 ` [PATCH v1 06/17] ACPI: HED: Switch over to devres-based resource management Rafael J. Wysocki
2026-06-02 22:10   ` Andy Shevchenko
2026-06-03 10:51     ` Rafael J. Wysocki
2026-06-03 11:12       ` Andy Shevchenko
2026-05-21 14:04 ` [PATCH v1 07/17] ACPI: thermal: " Rafael J. Wysocki
2026-05-21 14:05 ` [PATCH v1 08/17] ACPI: PAD: Rearrange acpi_pad_notify() Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 09/17] ACPI: PAD: Pass struct device pointer to acpi_pad_notify() Rafael J. Wysocki
2026-05-21 14:06 ` [PATCH v1 10/17] ACPI: PAD: Fix teardown ordering in acpi_pad_remove() Rafael J. Wysocki
2026-05-21 14:07 ` [PATCH v1 11/17] ACPI: PAD: Switch over to devres-based resource management Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 12/17] ACPI: video: Reduce the number of auxiliary device dereferences Rafael J. Wysocki
2026-05-21 14:08 ` [PATCH v1 13/17] ACPI: video: Rearrange probe and remove code Rafael J. Wysocki
2026-05-21 14:09 ` [PATCH v1 14/17] ACPI: video: Use devm action for video bus object cleanup Rafael J. Wysocki
2026-05-21 14:10 ` [PATCH v1 15/17] ACPI: video: Use devm action for freeing video devices Rafael J. Wysocki
2026-05-21 14:10 ` [PATCH v1 16/17] ACPI: video: Use devm for video->entry and backlight cleanup Rafael J. Wysocki
2026-05-21 14:11 ` [PATCH v1 17/17] ACPI: video: Switch over to devres-based resource management Rafael J. Wysocki

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=ah8l-p0Ih9tzu0G1@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=hansg@kernel.org \
    --cc=ira.weiny@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=rafael@kernel.org \
    --cc=vishal.l.verma@intel.com \
    --cc=w_armin@gmx.de \
    /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