public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Wilczynski, Michal" <michal.wilczynski@intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: <linux-acpi@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<nvdimm@lists.linux.dev>, <rafael.j.wysocki@intel.com>,
	<andriy.shevchenko@intel.com>, <lenb@kernel.org>,
	<dan.j.williams@intel.com>, <vishal.l.verma@intel.com>,
	<ira.weiny@intel.com>, <rui.zhang@intel.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: Re: [PATCH v1 1/9] ACPI: bus: Make notify wrappers more generic
Date: Thu, 5 Oct 2023 10:09:55 +0200	[thread overview]
Message-ID: <f8b9cfb4-aa0f-44c0-84fe-613f005a2baf@intel.com> (raw)
In-Reply-To: <CAJZ5v0jyjH48XZ6vytncodYhsS6ODYg2yaZBPfRWb_qm99FMuA@mail.gmail.com>

Hi,

Thanks for your review !

On 10/4/2023 9:09 PM, Rafael J. Wysocki wrote:
> On Mon, Sep 25, 2023 at 6:31 PM Michal Wilczynski
> <michal.wilczynski@intel.com> wrote:
>> acpi_dev_install_notify_handler() and acpi_dev_remove_notify_handler()
>> are wrappers around ACPICA installers. They are meant to save some
>> duplicated code from drivers. However as we're moving towards drivers
>> operating on platform_device they become a bit inconvenient to use as
>> inside the driver code we mostly want to use driver data of platform
>> device instead of ACPI device.
> That's fair enough, but ->
>
>> Make notify handlers installer wrappers more generic, while still
>> saving some code that would be duplicated otherwise.
>>
>> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>> Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
>> ---
>>
>> Notes:
>>     So one solution could be to just replace acpi_device with
>>     platform_device as an argument in those functions. However I don't
>>     believe this is a correct solution, as it is very often the case that
>>     drivers declare their own private structures which gets allocated during
>>     the .probe() callback, and become the heart of the driver. When drivers
>>     do that it makes much more sense to just pass the private structure
>>     to the notify handler instead of forcing user to dance with the
>>     platform_device or acpi_device.
>>
>>  drivers/acpi/ac.c         |  6 +++---
>>  drivers/acpi/acpi_video.c |  6 +++---
>>  drivers/acpi/battery.c    |  6 +++---
>>  drivers/acpi/bus.c        | 14 ++++++--------
>>  drivers/acpi/hed.c        |  6 +++---
>>  drivers/acpi/nfit/core.c  |  6 +++---
>>  drivers/acpi/thermal.c    |  6 +++---
>>  include/acpi/acpi_bus.h   |  9 ++++-----
>>  8 files changed, 28 insertions(+), 31 deletions(-)
>>
>> diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
>> index 225dc6818751..0b245f9f7ec8 100644
>> --- a/drivers/acpi/ac.c
>> +++ b/drivers/acpi/ac.c
>> @@ -256,8 +256,8 @@ static int acpi_ac_add(struct acpi_device *device)
>>         ac->battery_nb.notifier_call = acpi_ac_battery_notify;
>>         register_acpi_notifier(&ac->battery_nb);
>>
>> -       result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
>> -                                                acpi_ac_notify);
>> +       result = acpi_dev_install_notify_handler(device->handle, ACPI_ALL_NOTIFY,
>> +                                                acpi_ac_notify, device);
>>         if (result)
>>                 goto err_unregister;
>>
>> @@ -306,7 +306,7 @@ static void acpi_ac_remove(struct acpi_device *device)
>>
>>         ac = acpi_driver_data(device);
>>
>> -       acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
>> +       acpi_dev_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY,
>>                                        acpi_ac_notify);
>>         power_supply_unregister(ac->charger);
>>         unregister_acpi_notifier(&ac->battery_nb);
>> diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
>> index 948e31f7ce6e..025c17890127 100644
>> --- a/drivers/acpi/acpi_video.c
>> +++ b/drivers/acpi/acpi_video.c
>> @@ -2059,8 +2059,8 @@ static int acpi_video_bus_add(struct acpi_device *device)
>>
>>         acpi_video_bus_add_notify_handler(video);
>>
>> -       error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
>> -                                               acpi_video_bus_notify);
>> +       error = acpi_dev_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
>> +                                               acpi_video_bus_notify, device);
>>         if (error)
>>                 goto err_remove;
>>
>> @@ -2092,7 +2092,7 @@ static void acpi_video_bus_remove(struct acpi_device *device)
>>
>>         video = acpi_driver_data(device);
>>
>> -       acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
>> +       acpi_dev_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
>>                                        acpi_video_bus_notify);
>>
>>         mutex_lock(&video_list_lock);
>> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
>> index 969bf81e8d54..45dae32a8646 100644
>> --- a/drivers/acpi/battery.c
>> +++ b/drivers/acpi/battery.c
>> @@ -1213,8 +1213,8 @@ static int acpi_battery_add(struct acpi_device *device)
>>
>>         device_init_wakeup(&device->dev, 1);
>>
>> -       result = acpi_dev_install_notify_handler(device, ACPI_ALL_NOTIFY,
>> -                                                acpi_battery_notify);
>> +       result = acpi_dev_install_notify_handler(device->handle, ACPI_ALL_NOTIFY,
>> +                                                acpi_battery_notify, device);
>>         if (result)
>>                 goto fail_pm;
>>
>> @@ -1241,7 +1241,7 @@ static void acpi_battery_remove(struct acpi_device *device)
>>
>>         battery = acpi_driver_data(device);
>>
>> -       acpi_dev_remove_notify_handler(device, ACPI_ALL_NOTIFY,
>> +       acpi_dev_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY,
>>                                        acpi_battery_notify);
>>
>>         device_init_wakeup(&device->dev, 0);
>> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
>> index f41dda2d3493..479fe888d629 100644
>> --- a/drivers/acpi/bus.c
>> +++ b/drivers/acpi/bus.c
>> @@ -554,14 +554,13 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device,
>>         acpi_os_wait_events_complete();
>>  }
>>
>> -int acpi_dev_install_notify_handler(struct acpi_device *adev,
>> -                                   u32 handler_type,
>> -                                   acpi_notify_handler handler)
>> +int acpi_dev_install_notify_handler(acpi_handle handle, u32 handler_type,
>> +                                   acpi_notify_handler handler, void *context)
>>  {
>>         acpi_status status;
>>
>> -       status = acpi_install_notify_handler(adev->handle, handler_type,
>> -                                            handler, adev);
>> +       status = acpi_install_notify_handler(handle, handler_type,
>> +                                            handler, context);
> The wrapper now takes exactly the same arguments as the wrapped
> function, so what exactly is the point of having it?  The return value
> type?

I considered removing the wrapper altogether, but decided not to do so.
One trivial advantage of leaving this wrapper is the return value type as
you noticed, another is that the removal wrapper actually does something
extra and removing it would result in duplicate code among the drivers.
So I didn't really want to remove the 'install' wrapper but leave the
'remove' wrapper, as I think this might be confusing for the future reader.
In my mind if something is removed by the wrapper it should also be
installed by the wrapper.

>
>>         if (ACPI_FAILURE(status))
>>                 return -ENODEV;
>>
>> @@ -569,11 +568,10 @@ int acpi_dev_install_notify_handler(struct acpi_device *adev,
>>  }
>>  EXPORT_SYMBOL_GPL(acpi_dev_install_notify_handler);
>>
>> -void acpi_dev_remove_notify_handler(struct acpi_device *adev,
>> -                                   u32 handler_type,
>> +void acpi_dev_remove_notify_handler(acpi_handle handle, u32 handler_type,
>>                                     acpi_notify_handler handler)
>>  {
>> -       acpi_remove_notify_handler(adev->handle, handler_type, handler);
>> +       acpi_remove_notify_handler(handle, handler_type, handler);
>>         acpi_os_wait_events_complete();
> Here at least there is the extra workqueues synchronization point.
>
> That said, why exactly is it better to use acpi_handle instead of a
> struct acpi_device pointer?

I wanted to make the wrapper as close as possible to the wrapped function.
This way it would be easier to remove it in the future i.e if we ever deem
extra synchronization not worth it etc. What the ACPICA function need to
install a wrapper is a handle not a pointer to a device.
So there is no need for a middle man.

>
> Realistically, in a platform driver you'll need the latter to obtain
> the former anyway.

I don't want to introduce arbitrary limitations where they are not necessary.
It is often the case that driver allocates it's own private struct using kmalloc
family of functions, and that structure already contains everything that is
needed to remove the handler, so why force ? There are already examples
in the drivers that do that i.e in acpi_video the function
acpi_video_dev_add_notify_handler() uses raw ACPICA handler to install
a notify handler and it passes private structure there.
So there is value in leaving the choice of an actual type to the user of the
API.

To summarize:
I would say the wrappers are mostly unnecessary, but they actually save
some duplicate code in the drivers, so I decided to leave them, as I don't
want to introduce duplicate code if I can avoid that.

Thanks !
Michał



  reply	other threads:[~2023-10-05 13:44 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25 14:48 [PATCH v1 0/9] Replace acpi_driver with platform_driver Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 1/9] ACPI: bus: Make notify wrappers more generic Michal Wilczynski
2023-10-04 19:09   ` Rafael J. Wysocki
2023-10-05  8:09     ` Wilczynski, Michal [this message]
2023-10-05 10:57       ` Rafael J. Wysocki
2023-10-05 12:05         ` Wilczynski, Michal
2023-10-05 15:30           ` Rafael J. Wysocki
2023-10-05 17:03             ` Rafael J. Wysocki
2023-10-05 18:27               ` Wilczynski, Michal
2023-10-05 18:29                 ` Rafael J. Wysocki
2023-09-25 14:48 ` [PATCH v1 2/9] docs: firmware-guide: ACPI: Clarify ACPI bus concepts Michal Wilczynski
2023-10-05 17:57   ` Rafael J. Wysocki
2023-10-05 18:28     ` Wilczynski, Michal
2023-10-05 18:58       ` Wilczynski, Michal
2023-10-06 15:36         ` Rafael J. Wysocki
2023-10-06 17:29           ` Wilczynski, Michal
2023-09-25 14:48 ` [PATCH v1 3/9] ACPI: AC: Remove unnecessary checks Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 4/9] ACPI: AC: Use string_choices API instead of ternary operator Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 5/9] ACPI: AC: Replace acpi_driver with platform_driver Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 6/9] ACPI: AC: Rename ACPI device from device to adev Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 7/9] ACPI: NFIT: Replace acpi_driver with platform_driver Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 8/9] ACPI: NFIT: Remove redundant call to to_acpi_dev() Michal Wilczynski
2023-09-25 14:48 ` [PATCH v1 9/9] ACPI: NFIT: Don't use KBUILD_MODNAME for driver name Michal Wilczynski
2023-09-25 15:47   ` Andy Shevchenko
2023-09-25 16:11     ` Dan Williams

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=f8b9cfb4-aa0f-44c0-84fe-613f005a2baf@intel.com \
    --to=michal.wilczynski@intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=vishal.l.verma@intel.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