diff mbox series

[2/2] platform/x86: think-lmi: Add possible_values for ThinkStation

Message ID 20230312024635.518769-2-mpearson-lenovo@squebb.ca (mailing list archive)
State Superseded, archived
Headers show
Series platform/x86: thinkpad_acpi: Remove AMT enablement | expand

Commit Message

Mark Pearson March 12, 2023, 2:46 a.m. UTC
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.

Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
 drivers/platform/x86/think-lmi.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Thomas Weißschuh March 12, 2023, 3:37 a.m. UTC | #1
On Sat, Mar 11, 2023 at 09:46:35PM -0500, 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.
> 
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
>  drivers/platform/x86/think-lmi.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
> index 495a5e045069..52f3472fd1e0 100644
> --- a/drivers/platform/x86/think-lmi.c
> +++ b/drivers/platform/x86/think-lmi.c
> @@ -1432,6 +1432,29 @@ 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 =
> +							kmalloc(optend - optstart, GFP_KERNEL);
> +						strncpy(setting->possible_values,
> +								optstart, optend - optstart);
> +						setting->possible_values[optend - optstart] = '\0';

Same as for patch 1.

kmalloc() can fail, etc.

kstrndup() would be much easier.

> +					}
> +				}
> +			}
>  		}
>  		/* If we don't have a possible value mark as N/A */
>  		if (!setting->possible_values) {
> -- 
> 2.39.1
>
diff mbox series

Patch

diff --git a/drivers/platform/x86/think-lmi.c b/drivers/platform/x86/think-lmi.c
index 495a5e045069..52f3472fd1e0 100644
--- a/drivers/platform/x86/think-lmi.c
+++ b/drivers/platform/x86/think-lmi.c
@@ -1432,6 +1432,29 @@  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 =
+							kmalloc(optend - optstart, GFP_KERNEL);
+						strncpy(setting->possible_values,
+								optstart, optend - optstart);
+						setting->possible_values[optend - optstart] = '\0';
+					}
+				}
+			}
 		}
 		/* If we don't have a possible value mark as N/A */
 		if (!setting->possible_values) {