From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Thomas Weißschuh" <thomas@t-8ch.de>
Cc: "Hans de Goede" <hdegoede@redhat.com>,
"markgross@kernel.org" <markgross@kernel.org>,
"Mark Pearson" <markpearson@lenovo.com>,
"platform-driver-x86@vger.kernel.org"
<platform-driver-x86@vger.kernel.org>
Subject: Re: [PATCH v3 2/3] platform/x86: think-lmi: Add possible_values for ThinkStation
Date: Sat, 18 Mar 2023 13:53:33 -0400 [thread overview]
Message-ID: <da0c88a5-d03f-4dc2-939d-f1e60bc7d3cc@app.fastmail.com> (raw)
In-Reply-To: <c6175d59-2000-4145-95a6-b022631bf3a3@t-8ch.de>
Thanks Thomas
On Sat, Mar 18, 2023, at 12:35 PM, Thomas Weißschuh wrote:
> Hi Mark,
>
> please also CC linux-kernel@vger.kernel.org and previous reviewers.
>
> On Fri, Mar 17, 2023 at 11:46:34AM -0400, Mark Pearson wrote:
>> ThinkStation platforms don't support the API to return possible_values
>> but instead embed it in the settings string.
>>
>> Try and extract this information and set the possible_values attribute
>> appropriately.
>>
>> If there aren't any values possible then don't display possible_values.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> Changes in V3:
>> - Use is_visible attribute to determine if possible_values should be
>> available
>> - Code got refactored a bit to make compilation cleaner
>> Changes in V2:
>> - Move no value for possible_values handling into show function
>> - use kstrndup for allocating string
>>
>> drivers/platform/x86/think-lmi.c | 82 ++++++++++++++++++++++----------
>> 1 file changed, 56 insertions(+), 26 deletions(-)
>>
>> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
>> index 5fa5451c4802..d89a1c9bdbf1 100644
>> --- a/drivers/platform/x86/think-lmi.c
>> +++ b/drivers/platform/x86/think-lmi.c
>> @@ -917,6 +917,8 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
>> return sysfs_emit(buf, "%s\n", setting->display_name);
>> }
>>
>> +static struct kobj_attribute attr_displ_name = __ATTR_RO(display_name);
>> +
>> static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>> {
>> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> @@ -937,30 +939,6 @@ static ssize_t current_value_show(struct kobject *kobj, struct kobj_attribute *a
>> return ret;
>> }
>>
>> -static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>> -{
>> - struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> -
>> - if (!tlmi_priv.can_get_bios_selections)
>> - return -EOPNOTSUPP;
>> -
>> - return sysfs_emit(buf, "%s\n", setting->possible_values);
>> -}
>> -
>> -static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
>> - char *buf)
>> -{
>> - struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> -
>> - if (setting->possible_values) {
>> - /* Figure out what setting type is as BIOS does not return this */
>> - if (strchr(setting->possible_values, ','))
>> - return sysfs_emit(buf, "enumeration\n");
>> - }
>> - /* Anything else is going to be a string */
>> - return sysfs_emit(buf, "string\n");
>> -}
>> -
>> static ssize_t current_value_store(struct kobject *kobj,
>> struct kobj_attribute *attr,
>> const char *buf, size_t count)
>> @@ -1044,14 +1022,46 @@ static ssize_t current_value_store(struct kobject *kobj,
>> return ret ?: count;
>> }
>>
>> -static struct kobj_attribute attr_displ_name = __ATTR_RO(display_name);
>> +static struct kobj_attribute attr_current_val = __ATTR_RW_MODE(current_value, 0600);
>> +
>> +static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>> +{
>> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> +
>> + return sysfs_emit(buf, "%s\n", setting->possible_values);
>> +}
>>
>> static struct kobj_attribute attr_possible_values = __ATTR_RO(possible_values);
>>
>> -static struct kobj_attribute attr_current_val = __ATTR_RW_MODE(current_value, 0600);
>> +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
>> + char *buf)
>> +{
>> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> +
>> + if (setting->possible_values) {
>> + /* Figure out what setting type is as BIOS does not return this */
>> + if (strchr(setting->possible_values, ','))
>> + return sysfs_emit(buf, "enumeration\n");
>> + }
>> + /* Anything else is going to be a string */
>> + return sysfs_emit(buf, "string\n");
>> +}
>
> This patch seems to introduce a lot of churn, is it intentional?
Yes(ish). It got cleaned up as the functions were in a weird order when I introduced the is_visible. The actual changes are very small - but it did make it look messier than it really is.
Is this a big concern? I know it makes the review a bit more painful and my apologies for that.
>>
>> static struct kobj_attribute attr_type = __ATTR_RO(type);
>>
>> +static umode_t attr_is_visible(struct kobject *kobj,
>> + struct attribute *attr, int n)
>> +{
>> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> +
>> + /* We don't want to display possible_values attributes if not available */
>> + if (attr == (struct attribute *)&attr_possible_values)
>
> This cast is unsafe, if the struct kobj_attribute order is randomised it
> will break.
>
> You can use
>
> if (attr == &attr_possible_values.attr)
>
Ack. Will change.
>> + if (!setting->possible_values)
>> + return 0;
>> +
>> + return attr->mode;
>> +}
>> +
>> static struct attribute *tlmi_attrs[] = {
>> &attr_displ_name.attr,
>> &attr_current_val.attr,
>> @@ -1061,6 +1071,7 @@ static struct attribute *tlmi_attrs[] = {
>> };
>>
>> static const struct attribute_group tlmi_attr_group = {
>> + .is_visible = attr_is_visible,
>> .attrs = tlmi_attrs,
>> };
>>
>> @@ -1440,6 +1451,25 @@ static int tlmi_analyze(void)
>> if (ret || !setting->possible_values)
>> pr_info("Error retrieving possible values for %d : %s\n",
>> i, setting->display_name);
>> + } else {
>> + /*
>> + * Older Thinkstations don't support the bios_selections API.
>> + * Instead they store this as a [Optional:Option1,Option2] section of the
>> + * name string.
>> + * Try and pull that out if it's available.
>> + */
>> + char *item, *optstart, *optend;
>> +
>> + if (!tlmi_setting(setting->index, &item, LENOVO_BIOS_SETTING_GUID)) {
>> + optstart = strstr(item, "[Optional:");
>> + if (optstart) {
>> + optstart += strlen("[Optional:");
>> + optend = strstr(optstart, "]");
>> + if (optend)
>> + setting->possible_values =
>> + kstrndup(optstart, optend - optstart, GFP_KERNEL);
>> + }
>> + }
>
> The patch now does two things:
> 1) Hide the sysfs attributes if the value is not available
> 2) Extract the value from the description
>
> Maybe it could be split in two?
Sure. I did contemplate that and then ultimately decided it was all from the same intent so left it. But I can split.
>
> Another observation:
> Would it make sense to remove the part
> "[Optional:Option1,Option2]" from the name attribute?
>
I considered this previously and I was concerned about if this could have impacts that I couldn't foresee. The BIOS teams do strange things with this string so I was playing safe and leaving it alone (especially as it differs across the different portfolios)
I know it would be nice to have one standard for everything but sadly that's not the case, and not a battle I can win.
>> }
>> kobject_init(&setting->kobj, &tlmi_attr_setting_ktype);
>> tlmi_priv.setting[i] = setting;
>> --
>> 2.39.2
>>
next prev parent reply other threads:[~2023-03-18 17:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-17 15:46 [PATCH v3 1/3] platform/x86: think-lmi: add missing type attribute Mark Pearson
2023-03-17 15:46 ` [PATCH v3 2/3] platform/x86: think-lmi: Add possible_values for ThinkStation Mark Pearson
2023-03-18 16:35 ` Thomas Weißschuh
2023-03-18 17:53 ` Mark Pearson [this message]
2023-03-18 23:52 ` Thomas Weißschuh
2023-03-19 0:08 ` Mark Pearson
2023-03-19 9:34 ` Hans de Goede
2023-03-18 17:59 ` Mark Pearson
2023-03-19 0:01 ` Thomas Weißschuh
2023-03-19 0:04 ` Mark Pearson
2023-03-17 15:46 ` [PATCH v3 3/3] platform/x86: think-lmi: use correct possible_values delimters Mark Pearson
2023-03-18 14:37 ` Barnabás Pőcze
2023-03-18 17:55 ` Mark Pearson
2023-03-18 16:39 ` Thomas Weißschuh
2023-03-18 18:06 ` Mark Pearson
2023-03-19 0:11 ` Thomas Weißschuh
2023-03-19 0:18 ` Mark Pearson
2023-03-20 0:52 ` [PATCH v3 1/3] platform/x86: think-lmi: add missing type attribute Limonciello, Mario
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=da0c88a5-d03f-4dc2-939d-f1e60bc7d3cc@app.fastmail.com \
--to=mpearson-lenovo@squebb.ca \
--cc=hdegoede@redhat.com \
--cc=markgross@kernel.org \
--cc=markpearson@lenovo.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=thomas@t-8ch.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;
as well as URLs for NNTP newsgroup(s).