mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Armin Wolf <W_Armin@gmx.de>, markgross@kernel.org
Cc: Mario.Limonciello@amd.com, prasanth.ksr@dell.com,
	jorgealtxwork@gmail.com, james@equiv.tech,
	Dell.Client.Kernel@dell.com, platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] platform/x86: wmi: Allow retrieving the number of WMI object instances
Date: Mon, 1 May 2023 11:31:37 +0200	[thread overview]
Message-ID: <1c216a2e-2f97-b6f9-bf09-67b85e932322@redhat.com> (raw)
In-Reply-To: <3bfa4a8c-1260-3fc0-9f83-2958467ca596@gmx.de>

Hi,

On 4/30/23 23:01, Armin Wolf wrote:
> Am 30.04.23 um 22:41 schrieb Hans de Goede:
> 
>> Hi Armin,
>>
>> On 4/30/23 22:31, Armin Wolf wrote:
>>> Currently, the WMI driver core knows how many instances of a given
>>> WMI object exist, but WMI drivers cannot access this information.
>>> At the same time, some current and upcoming WMI drivers want to
>>> have access to this information. Add wmi_instance_count() and
>>> wmidev_instance_count() to allow WMI drivers to get the number of
>>> WMI object instances.
>>>
>>> Signed-off-by: Armin Wolf <W_Armin@gmx.de>
>> Thank you for your work on this.
>>
>>> ---
>>>   drivers/platform/x86/wmi.c | 41 ++++++++++++++++++++++++++++++++++++++
>>>   include/linux/acpi.h       |  2 ++
>>>   include/linux/wmi.h        |  2 ++
>>>   3 files changed, 45 insertions(+)
>>>
>>> diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
>>> index c226dd4163a1..5b95d7aa5c2f 100644
>>> --- a/drivers/platform/x86/wmi.c
>>> +++ b/drivers/platform/x86/wmi.c
>>> @@ -263,6 +263,47 @@ int set_required_buffer_size(struct wmi_device *wdev, u64 length)
>>>   }
>>>   EXPORT_SYMBOL_GPL(set_required_buffer_size);
>>>
>>> +/**
>>> + * wmi_instance_count - Get number of WMI object instances
>>> + * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
>>> + *
>>> + * Get the number of WMI object instances.
>>> + *
>>> + * Returns: Number of WMI object instances or negative error code.
>>> + */
>>> +int wmi_instance_count(const char *guid_string)
>>> +{
>>> +    struct wmi_block *wblock;
>>> +    acpi_status status;
>>> +
>>> +    status = find_guid(guid_string, &wblock);
>>> +    if (ACPI_FAILURE(status)) {
>>> +        if (status == AE_BAD_PARAMETER)
>>> +            return -EINVAL;
>>> +
>>> +        return -ENODEV;
>> Maybe just return 0 here ?
>>
>> The GUID not existing at all does not seem like
>> an error to me, but rather a case of there
>> being 0 instances.
>>
>> This will also allow patch 2/2 to completely
>> drop the get_instance_count() function and
>> replace its callers with direct calls to
>> wmi_instance_count() as the code is known
>> to always pass a valid GUID, so it won't hit
>> the -EINVAL path.
>>
>> Regards,
>>
>> Hans
>>
> Hi,
> 
> i would prefer returning -ENODEV instead of 0, so WMI drivers can
> distinguish between "not found" and "zero instances".

Ah right, that is a good point, ok lets keep this as is then.

Regards,

Hans




> Also i do not
> think that relying on the parameter of get_instance_count() always
> being a valid GUID is a good idea, just in case wmi_instance_count()
> is later modified to be able to encounter runtime errors.
> 
> Armin Wolf
> 
>>
>>> +    }
>>> +
>>> +    return wmidev_instance_count(&wblock->dev);
>>> +}
>>> +EXPORT_SYMBOL_GPL(wmi_instance_count);
>>> +
>>> +/**
>>> + * wmidev_instance_count - Get number of WMI object instances
>>> + * @wdev: A wmi bus device from a driver
>>> + *
>>> + * Get the number of WMI object instances.
>>> + *
>>> + * Returns: Number of WMI object instances.
>>> + */
>>> +u8 wmidev_instance_count(struct wmi_device *wdev)
>>> +{
>>> +    struct wmi_block *wblock = container_of(wdev, struct wmi_block, dev);
>>> +
>>> +    return wblock->gblock.instance_count;
>>> +}
>>> +EXPORT_SYMBOL_GPL(wmidev_instance_count);
>>> +
>>>   /**
>>>    * wmi_evaluate_method - Evaluate a WMI method (deprecated)
>>>    * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
>>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>>> index efff750f326d..e52bf2742eaf 100644
>>> --- a/include/linux/acpi.h
>>> +++ b/include/linux/acpi.h
>>> @@ -412,6 +412,8 @@ extern bool acpi_is_pnp_device(struct acpi_device *);
>>>
>>>   typedef void (*wmi_notify_handler) (u32 value, void *context);
>>>
>>> +int wmi_instance_count(const char *guid);
>>> +
>>>   extern acpi_status wmi_evaluate_method(const char *guid, u8 instance,
>>>                       u32 method_id,
>>>                       const struct acpi_buffer *in,
>>> diff --git a/include/linux/wmi.h b/include/linux/wmi.h
>>> index c1a3bd4e4838..763bd382cf2d 100644
>>> --- a/include/linux/wmi.h
>>> +++ b/include/linux/wmi.h
>>> @@ -35,6 +35,8 @@ extern acpi_status wmidev_evaluate_method(struct wmi_device *wdev,
>>>   extern union acpi_object *wmidev_block_query(struct wmi_device *wdev,
>>>                            u8 instance);
>>>
>>> +u8 wmidev_instance_count(struct wmi_device *wdev);
>>> +
>>>   extern int set_required_buffer_size(struct wmi_device *wdev, u64 length);
>>>
>>>   /**
>>> -- 
>>> 2.30.2
>>>
> 


  reply	other threads:[~2023-05-01  9:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-30 20:31 [PATCH 0/2] platform/x86: " Armin Wolf
2023-04-30 20:31 ` [PATCH 1/2] platform/x86: wmi: " Armin Wolf
2023-04-30 20:41   ` Hans de Goede
2023-04-30 21:01     ` Armin Wolf
2023-05-01  9:31       ` Hans de Goede [this message]
2023-04-30 20:31 ` [PATCH 2/2] platform/x86: dell-sysman: Improve instance detection Armin Wolf
2023-05-09 10:10 ` [PATCH 0/2] platform/x86: Allow retrieving the number of WMI object instances 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=1c216a2e-2f97-b6f9-bf09-67b85e932322@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=Dell.Client.Kernel@dell.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=W_Armin@gmx.de \
    --cc=james@equiv.tech \
    --cc=jorgealtxwork@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=prasanth.ksr@dell.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

all inboxes | Powered by JetHome®