platform/x86: think-lmi: add missing type attribute
PATCH v2 1/2 platform/x86: think-lmi: add missing type attribute
This driver was missing the mandatory type attribute...oops.
Add it in along with logic to determine whether the attribute is an enumeration type or a string by parsing the possible_values attribute.
Upstream bug https://bugzilla.kernel.org/show_bug.cgi?id=216460
---
Changes in v2:
- Simplify the code and move type determination into show function
- Don't use Fixes with URL in commit info
drivers/platform/x86/think-lmi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/platform/x86/think-lmi.c +17 -0
@@ -947,6 +947,20 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attributereturn 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)
@@ -1036,10 +1050,13 @@ 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 struct kobj_attribute attr_type =__ATTR_RO (type); +static struct attribute *tlmi_attrs[] = { &attr_displ_name.attr, &attr_current_val.attr, &attr_possible_values.attr, + &attr_type.attr,NULL };
Signature · 1 line
2.39.2
PATCH v2 2/2 platform/x86: think-lmi: Add possible_values for ThinkStation
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.
---
Changes in V2:
- Move no value for possible_values handling into show function
- use kstrndup for allocating string
drivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/platform/x86/think-lmi.c +22 -4
@@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute {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); +if (setting->possible_values) +return sysfs_emit (buf,"%s\n" , setting->possible_values); +return sysfs_emit (buf,"not available\n" ); } static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1440,6 +1439,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 ); + } + } }kobject_init (&setting->kobj, &tlmi_attr_setting_ktype); tlmi_priv.setting[i] = setting;
Signature · 1 line
2.39.2
Re: [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
Hi Mark,
some more remarks, sorry not seeing this earlier.
Quoted 21 lines · Mark Pearson
ThinkStation platforms don't support the API to return
possible_valuesbut instead embed it in the settings string.Try and extract this information and set the
possible_valuesattribute appropriately.Signed-off-by Mark Pearson <[email protected]>---
Changes in V2:
- Move no value forpossible_valueshandling into show function
- use kstrndup for allocating stringdrivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/platform/x86/think-lmi.c +0
-0@@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute {
drivers/platform/x86/think-lmi.c static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute · line 947
Quoted 10 lines
drivers/platform/x86/think-lmi.c +3
-4struct 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); +if (setting->possible_values) +return sysfs_emit (buf,"%s\n" , setting->possible_values); +return sysfs_emit (buf,"not available\n" ); }
As the attribute "possible_values" is not mandatory it should be possible to hide it completely with an is_visible callback.
This would indicate absence clearer than a magic value.
drivers/platform/x86/think-lmi.c static int tlmi_analyze(void) · line 1448
Quoted 12 lines
drivers/platform/x86/think-lmi.c +7
-0static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,@@ -1440,6 +1439,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. +*/
The values in possible_values are supposed to be separated by semi-colons, not commas.
I don't know how this affects the existing parts of this driver but it affects both patches of this series.
Quoted 18 lines
drivers/platform/x86/think-lmi.c +12
-0+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 ); + } + } }kobject_init (&setting->kobj, &tlmi_attr_setting_ktype); tlmi_priv.setting[i] = setting;Signature · 1 line
2.39.2
Re: [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
Hi Thomas,
Quoted 3 lines · Thomas Weißschuh
Hi Mark,
some more remarks, sorry not seeing this earlier.
No worries :) I appreciate the reviews.
Quoted 37 lines · Mark Pearson
Quoted 21 lines
ThinkStation platforms don't support the API to return
possible_valuesbut instead embed it in the settings string.Try and extract this information and set the
possible_valuesattribute appropriately.Signed-off-by Mark Pearson <[email protected]>---
Changes in V2:
- Move no value forpossible_valueshandling into show function
- use kstrndup for allocating stringdrivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/platform/x86/think-lmi.c +0
-0@@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute {drivers/platform/x86/think-lmi.c static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute · line 947
Quoted 10 lines
drivers/platform/x86/think-lmi.c +3
-4struct 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); +if (setting->possible_values) +return sysfs_emit (buf,"%s\n" , setting->possible_values); +return sysfs_emit (buf,"not available\n" ); }As the attribute "
possible_values" is not mandatory it should be possible to hide it completely with anis_visiblecallback.
Quoted 1 line
This would indicate absence clearer than a magic value.
Agreed - I like it. I'll look into implementing that. Thank you.
Quoted 10 lines
Quoted 10 lines
drivers/platform/x86/think-lmi.c +4
-0static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,@@ -1440,6 +1439,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
Quoted 8 lines
drivers/platform/x86/think-lmi.c static int tlmi_analyze(void) · line 1448
Quoted 3 lines
drivers/platform/x86/think-lmi.c +3
-0+* name string. +* Try and pull that out if it's available. +*/ The values in
possible_valuesare supposed to be separated by semi-colons, not commas.
I don't know how this affects the existing parts of this driver but it affects both patches of this series.
Good point, and I'd missed that.
The current string is returned directly from the BIOS, so I'll have to manipulate it. I would ask the BIOS team to change it but it will take forever and could impact Windows - so better to tweak it in the driver. I'll do this as a third patch I think.
Thanks
Mark
Re: [PATCH v2 2/2] platform/x86: think-lmi: Add possible_values for ThinkStation
Hi,
Quoted 69 lines · Mark Pearson
Hi Thomas,
Quoted 3 lines · Thomas Weißschuh
Hi Mark,
some more remarks, sorry not seeing this earlier.
No worries :) I appreciate the reviews.
Quoted 37 lines · Mark Pearson
Quoted 21 lines
ThinkStation platforms don't support the API to return
possible_valuesbut instead embed it in the settings string.Try and extract this information and set the
possible_valuesattribute appropriately.Signed-off-by Mark Pearson <[email protected]>---
Changes in V2:
- Move no value forpossible_valueshandling into show function
- use kstrndup for allocating stringdrivers/platform/x86/think-lmi.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/platform/x86/think-lmi.c +0
-0@@ -941,10 +941,9 @@ static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute {drivers/platform/x86/think-lmi.c static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute · line 947
Quoted 10 lines
drivers/platform/x86/think-lmi.c +3
-4struct 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); +if (setting->possible_values) +return sysfs_emit (buf,"%s\n" , setting->possible_values); +return sysfs_emit (buf,"not available\n" ); }As the attribute "
possible_values" is not mandatory it should be possible to hide it completely with anis_visiblecallback.Quoted 1 line
This would indicate absence clearer than a magic value.
Agreed - I like it. I'll look into implementing that. Thank you.
Quoted 10 lines
Quoted 10 lines
drivers/platform/x86/think-lmi.c +4
-0static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,@@ -1440,6 +1439,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 Quoted 8 lines
drivers/platform/x86/think-lmi.c static int tlmi_analyze(void) · line 1448
Quoted 3 lines
drivers/platform/x86/think-lmi.c +3
-0+* name string. +* Try and pull that out if it's available. +*/ The values in
possible_valuesare supposed to be separated by semi-colons, not commas.
I don't know how this affects the existing parts of this driver but it affects both patches of this series.
Quoted 3 lines
Good point, and I'd missed that.
The current string is returned directly from the BIOS, so I'll have to manipulate it. I would ask the BIOS team to change it but it will take forever and could impact Windows - so better to tweak it in the driver. I'll do this as a third patch I think.
Yes putting this in a separate / third patch seems best.
Regards,
Hans