linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
	Hans de Goede <hdegoede@redhat.com>
Cc: Mark Gross <markgross@kernel.org>, Len Brown <lenb@kernel.org>,
	Henrique de Moraes Holschuh <hmh@hmh.eng.br>,
	Matan Ziv-Av <matan@svgalib.org>,
	Corentin Chary <corentin.chary@gmail.com>,
	Jeremy Soller <jeremy@system76.com>,
	productdev@system76.com,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/5] ACPI: battery: Do not unload battery hooks on single error
Date: Mon, 19 Sep 2022 22:35:33 +0200	[thread overview]
Message-ID: <f0b17ba6-3d3c-cbc1-ec0d-ec59c73f06f6@gmx.de> (raw)
In-Reply-To: <f2af5d01-a2cd-ae96-24c7-d61f5f0d0bc3@gmx.de>

Am 19.09.22 um 21:12 schrieb Armin Wolf:

> Am 19.09.22 um 18:27 schrieb Rafael J. Wysocki:
>
>> On Mon, Sep 19, 2022 at 12:42 PM Hans de Goede <hdegoede@redhat.com> 
>> wrote:
>>> Hi,
>>>
>>> On 9/12/22 13:53, Armin Wolf wrote:
>>>> Currently, battery hooks are being unloaded if they return
>>>> an error when adding a single battery.
>>>> This however also causes the removal of successfully added
>>>> hooks if they return -ENODEV for a single unsupported
>>>> battery.
>>>>
>>>> Do not unload battery hooks in such cases since the hook
>>>> handles any cleanup actions.
>>>>
>>>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>>> Maybe instead of removing all error checking, allow -ENODEV
>>> and behave as before when the error is not -ENODEV ?
>>>
>>> Otherwise we should probably make the add / remove callbacks
>>> void to indicate that any errors are ignored.
>>>
>>> Rafael, do you have any opinion on this?
>> IMV this is not a completely safe change, because things may simply
>> not work in the cases in which an error is returned.
>>
>> It would be somewhat better to use a special error code to indicate
>> "no support" (eg. -ENOTSUPP) and ignore that one only.
>
> I would favor -ENODEV then, since it is already used by quiet a few 
> drivers
> to indicate a unsupported battery.
>
> Armin Wolf
>
While checking all instances where the battery hook mechanism is currently used,
i found out that all but a single battery hook return -ENODEV for all errors they
encounter, the exception being the huawei-wmi driver.

I do not know the reason for this, but i fear unloading the extension on for
example -ENOTSUP will result in similar behavior by hooks wanting to avoid being
unloaded on harmless errors.

However, i agree that when ignoring all errors, battery extensions which provide
similar attributes may currently delete each others attributes.

Any idea on how to solve this?

Armin Wolf

>>>> ---
>>>>   drivers/acpi/battery.c | 24 +++---------------------
>>>>   1 file changed, 3 insertions(+), 21 deletions(-)
>>>>
>>>> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
>>>> index 306513fec1e1..e59c261c7c59 100644
>>>> --- a/drivers/acpi/battery.c
>>>> +++ b/drivers/acpi/battery.c
>>>> @@ -724,20 +724,10 @@ void battery_hook_register(struct 
>>>> acpi_battery_hook *hook)
>>>>         * its attributes.
>>>>         */
>>>>        list_for_each_entry(battery, &acpi_battery_list, list) {
>>>> -             if (hook->add_battery(battery->bat)) {
>>>> -                     /*
>>>> -                      * If a add-battery returns non-zero,
>>>> -                      * the registration of the extension has failed,
>>>> -                      * and we will not add it to the list of loaded
>>>> -                      * hooks.
>>>> -                      */
>>>> -                     pr_err("extension failed to load: %s", 
>>>> hook->name);
>>>> -                     __battery_hook_unregister(hook, 0);
>>>> -                     goto end;
>>>> -             }
>>>> +             hook->add_battery(battery->bat);
>>>>        }
>>>>        pr_info("new extension: %s\n", hook->name);
>>>> -end:
>>>> +
>>>>        mutex_unlock(&hook_mutex);
>>>>   }
>>>>   EXPORT_SYMBOL_GPL(battery_hook_register);
>>>> @@ -762,15 +752,7 @@ static void battery_hook_add_battery(struct 
>>>> acpi_battery *battery)
>>>>         * during the battery module initialization.
>>>>         */
>>>>        list_for_each_entry_safe(hook_node, tmp, &battery_hook_list, 
>>>> list) {
>>>> -             if (hook_node->add_battery(battery->bat)) {
>>>> -                     /*
>>>> -                      * The notification of the extensions has 
>>>> failed, to
>>>> -                      * prevent further errors we will unload the 
>>>> extension.
>>>> -                      */
>>>> -                     pr_err("error in extension, unloading: %s",
>>>> -                                     hook_node->name);
>>>> -                     __battery_hook_unregister(hook_node, 0);
>>>> -             }
>>>> +             hook_node->add_battery(battery->bat);
>>>>        }
>>>>        mutex_unlock(&hook_mutex);
>>>>   }
>>>> -- 
>>>> 2.30.2
>>>>

  reply	other threads:[~2022-09-19 20:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 12:53 [PATCH 0/5] platform/x86: dell: Add new dell-wmi-ddv driver Armin Wolf
2022-09-12 12:53 ` [PATCH 1/5] ACPI: battery: Do not unload battery hooks on single error Armin Wolf
2022-09-19 10:42   ` Hans de Goede
2022-09-19 16:27     ` Rafael J. Wysocki
2022-09-19 19:12       ` Armin Wolf
2022-09-19 20:35         ` Armin Wolf [this message]
2022-09-27 14:29           ` Hans de Goede
2022-09-27 15:44             ` Armin Wolf
2022-09-12 12:53 ` [PATCH 2/5] ACPI: battery: Simplify battery_hook_unregister() Armin Wolf
2022-09-19 10:42   ` Hans de Goede
2022-09-12 12:53 ` [PATCH 3/5] ACPI: battery: Allow battery hooks to be registered multiple times Armin Wolf
2022-09-12 16:42   ` Barnabás Pőcze
2022-09-12 17:29     ` Armin Wolf
2022-09-19 11:18       ` Hans de Goede
2022-09-19 17:42       ` Barnabás Pőcze
2022-09-12 12:53 ` [PATCH 4/5] ACPI: battery: Allow for passing data to battery hooks Armin Wolf
2022-09-19 11:08   ` Hans de Goede
2022-09-12 12:53 ` [PATCH 5/5] platform/x86: dell: Add new dell-wmi-ddv driver Armin Wolf
2022-09-12 21:56   ` Randy Dunlap
2022-09-13 14:40     ` Armin Wolf
2022-09-13 16:08       ` Limonciello, Mario
2022-09-13 16:45         ` Armin Wolf
2022-09-13 18:27         ` Randy Dunlap
2022-09-13 18:30           ` Limonciello, Mario
2022-09-13 18:37             ` Randy Dunlap
2022-09-19 11:33   ` Hans de Goede

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=f0b17ba6-3d3c-cbc1-ec0d-ec59c73f06f6@gmx.de \
    --to=w_armin@gmx.de \
    --cc=corentin.chary@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=hmh@hmh.eng.br \
    --cc=jeremy@system76.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=matan@svgalib.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=productdev@system76.com \
    --cc=rafael@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).