* [PATCH 00/13] New Lenovo common WMI driver - tlmi
@ 2026-12-04 2:20 Mark Pearson
2026-12-04 2:20 ` [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers Mark Pearson
` (13 more replies)
0 siblings, 14 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
This series introduces support for a new Lenovo 'common WMI'
implementation.
The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
WMI methods for interfacing with the BIOS settings. This implementation
will be available for 2027 platforms and is intended to be common across
the business units.
The new driver is called tlmi and can run alongside the existing
think-lmi driver. Initially the BIOS's will support both interfaces.
The first 5 patches in the series update the existing think-lmi driver
with changes that means it can share structures with the new tlmi
driver. They also introduce fixes for issues I found when implementing
tlmi.
The remaining patches introduce the new tlmi functionality. I've tried
to break them up into reviewable chunks.
The tlmi driver for now offers the same functionality as think-lmi -
with support for modifying BIOS settings and authentication options.
It also introduces 'platform' settings and 'function' settings.
During implementation I needed some functionality to be common between
modules. Using the wmi-helpers module seemed a good place for this, but
please let me know if it's not suitable.
Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
Thinkstation P5 G2.
Much of this implementation builds on the recommendations from Armin,
Derek and Ilpo from the original RFC. Many thanks for the guidance.
Mark Pearson (13):
platform/x86: lenovo: think-lmi: Convert name arrays to pointers
platform/x86: lenovo: think-lmi: Clean up attributes if not added to
list
platform/x86: lenovo: think-lmi: cache current value at init
platform/x86: lenovo: think-lmi: store attributes as linked list
platform/x86: lenovo: tlmi: New tlmi driver for common WMI
implementation
platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
platform/x86: lenovo: tlmi: Retrieve auth information
platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
platform/x86: lenovo: tlmi: Add authentication sysfs entries
platform/x86: lenovo: tlmi: Add platform attribute support
platform/x86: lenovo: tlmi: Add function attributes support
platform/x86: lenovo: tlmi: Add method identifier
docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
.../testing/sysfs-class-firmware-attributes | 39 +-
drivers/platform/x86/lenovo/Kconfig | 1 +
drivers/platform/x86/lenovo/Makefile | 3 +
drivers/platform/x86/lenovo/think-lmi.c | 193 ++--
drivers/platform/x86/lenovo/think-lmi.h | 72 +-
drivers/platform/x86/lenovo/tlmi-attr.c | 214 ++++
drivers/platform/x86/lenovo/tlmi-auth.c | 958 ++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-authdata.c | 135 +++
drivers/platform/x86/lenovo/tlmi-config.c | 764 ++++++++++++++
drivers/platform/x86/lenovo/tlmi-function.c | 196 ++++
drivers/platform/x86/lenovo/tlmi-platform.c | 212 ++++
drivers/platform/x86/lenovo/wmi-helpers.c | 65 +-
drivers/platform/x86/lenovo/wmi-helpers.h | 5 +
13 files changed, 2788 insertions(+), 69 deletions(-)
create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-auth.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-function.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-platform.c
--
2.43.0
^ permalink raw reply [flat|nested] 44+ messages in thread
* [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list Mark Pearson
` (12 subsequent siblings)
13 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Change the name and display_name properties of the attribute setting
to be allocated instead of static.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 24 ++++++++++++++++++++++--
drivers/platform/x86/lenovo/think-lmi.h | 4 ++--
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index 2c45c98ec0ec..c060a0a360ca 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1255,6 +1255,8 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+ kfree(setting->name);
+ kfree(setting->display_name);
kfree(setting->possible_values);
kfree(setting);
}
@@ -1525,6 +1527,8 @@ static int tlmi_sysfs_init(void)
/* check for duplicate or reserved values */
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
tlmi_priv.setting[i]->display_name) < 0) {
+ kfree(tlmi_priv.setting[i]->name);
+ kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
kfree(tlmi_priv.setting[i]);
tlmi_priv.setting[i] = NULL;
@@ -1686,10 +1690,24 @@ static int tlmi_analyze(struct wmi_device *wdev)
setting->wdev = wdev;
setting->index = i;
- strscpy(setting->name, item);
+ setting->name = kstrdup(item, GFP_KERNEL);
+ if (!setting->name) {
+ ret = -ENOMEM;
+ kfree(item);
+ kfree(setting);
+ goto fail_clear_attr;
+ }
+
/* It is not allowed to have '/' for file name. Convert it into '\'. */
strreplace(item, '/', '\\');
- strscpy(setting->display_name, item);
+ setting->display_name = kstrdup(item, GFP_KERNEL);
+ if (!setting->display_name) {
+ ret = -ENOMEM;
+ kfree(item);
+ kfree(setting->name);
+ kfree(setting);
+ goto fail_clear_attr;
+ }
/* If BIOS selections supported, load those */
if (tlmi_priv.can_get_bios_selections) {
@@ -1815,6 +1833,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
fail_clear_attr:
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
if (tlmi_priv.setting[i]) {
+ kfree(tlmi_priv.setting[i]->name);
+ kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
kfree(tlmi_priv.setting[i]);
}
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 017644323d46..8ced29253f40 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -101,8 +101,8 @@ struct tlmi_attr_setting {
struct kobject kobj;
struct wmi_device *wdev;
int index;
- char name[TLMI_SETTINGS_MAXLEN];
- char display_name[TLMI_SETTINGS_MAXLEN];
+ char *name;
+ char *display_name;
char *possible_values;
};
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
2026-12-04 2:20 ` [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:20 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
` (11 subsequent siblings)
13 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
If we fail to add an attribute to the attribute_kset list then it will not
get freed during the subsequent kobject_put.
Make sure to free resources before going ahead with the rest of the
cleanup.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 87 ++++++++++++++++++-------
1 file changed, 65 insertions(+), 22 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index c060a0a360ca..63ea212b4bda 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1444,6 +1444,16 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr
static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
/* ---- Initialisation --------------------------------------------------------- */
+/* Utility function to free record when not in the attribute_kset list */
+static void tlmi_free_attr_record(int i)
+{
+ kfree(tlmi_priv.setting[i]->name);
+ kfree(tlmi_priv.setting[i]->display_name);
+ kfree(tlmi_priv.setting[i]->possible_values);
+ kfree(tlmi_priv.setting[i]);
+ tlmi_priv.setting[i] = NULL;
+}
+
static void tlmi_release_attr(void)
{
struct kobject *pos, *n;
@@ -1461,8 +1471,10 @@ static void tlmi_release_attr(void)
kset_unregister(tlmi_priv.attribute_kset);
/* Free up any saved signatures */
- kfree(tlmi_priv.pwd_admin->signature);
- kfree(tlmi_priv.pwd_admin->save_signature);
+ if (tlmi_priv.pwd_admin) {
+ kfree(tlmi_priv.pwd_admin->signature);
+ kfree(tlmi_priv.pwd_admin->save_signature);
+ }
if (tlmi_priv.pwd_system) {
kfree(tlmi_priv.pwd_system->signature);
kfree(tlmi_priv.pwd_system->save_signature);
@@ -1495,8 +1507,9 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
static int tlmi_sysfs_init(void)
{
- int i, ret;
+ int i, ret = 0, auth_ret = 0;
+ guard(mutex)(&tlmi_mutex);
tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
NULL, "%s", "thinklmi");
if (IS_ERR(tlmi_priv.class_dev)) {
@@ -1524,14 +1537,15 @@ static int tlmi_sysfs_init(void)
if (!tlmi_priv.setting[i])
continue;
+ if (ret) { /* We had a critical failure. Just clean up */
+ tlmi_free_attr_record(i);
+ continue;
+ }
+
/* check for duplicate or reserved values */
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
tlmi_priv.setting[i]->display_name) < 0) {
- kfree(tlmi_priv.setting[i]->name);
- kfree(tlmi_priv.setting[i]->display_name);
- kfree(tlmi_priv.setting[i]->possible_values);
- kfree(tlmi_priv.setting[i]);
- tlmi_priv.setting[i] = NULL;
+ tlmi_free_attr_record(i);
continue;
}
@@ -1539,9 +1553,14 @@ static int tlmi_sysfs_init(void)
tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
NULL, "%s", tlmi_priv.setting[i]->display_name);
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.setting[i]->kobj);
+ continue; /* use loop to clear remaining items */
+ }
}
+ /* Check if we had an error during the attribute creations */
+ if (ret)
+ goto fail_create_attr;
ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
if (ret)
@@ -1561,39 +1580,63 @@ static int tlmi_sysfs_init(void)
tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "Admin");
- if (ret)
- goto fail_create_attr;
-
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_admin->kobj);
+ tlmi_priv.pwd_admin = NULL;
+ auth_ret = ret;
+ }
tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "Power-on");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_power->kobj);
+ tlmi_priv.pwd_power = NULL;
+ auth_ret = ret;
+ }
if (tlmi_priv.opcode_support) {
tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "System");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_system->kobj);
+ tlmi_priv.pwd_system = NULL;
+ auth_ret = ret;
+ }
tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "HDD");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_hdd->kobj);
+ tlmi_priv.pwd_hdd = NULL;
+ auth_ret = ret;
+ }
tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
NULL, "%s", "NVMe");
- if (ret)
- goto fail_create_attr;
+ if (ret) {
+ kobject_put(&tlmi_priv.pwd_nvme->kobj);
+ tlmi_priv.pwd_nvme = NULL;
+ auth_ret = ret;
+ }
+ }
+ /* If one of the auth entries fail, we'd best go and clean up */
+ if (auth_ret) {
+ ret = auth_ret;
+ goto fail_create_attr;
}
-
return ret;
fail_create_attr:
+ /* Release any kobject items */
tlmi_release_attr();
+ kfree(tlmi_priv.pwd_admin);
+ kfree(tlmi_priv.pwd_power);
+ kfree(tlmi_priv.pwd_system);
+ kfree(tlmi_priv.pwd_hdd);
+ kfree(tlmi_priv.pwd_nvme);
fail_device_created:
device_unregister(tlmi_priv.class_dev);
fail_class_created:
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
2026-12-04 2:20 ` [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers Mark Pearson
2026-12-04 2:20 ` [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:28 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
` (10 subsequent siblings)
13 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
When we read in current BIOS setting at init, cache it then to avoid
having to process it later, as it doesn't change.
This does introduce a couple of changes in behaviour:
- If the attribute value is changed we modify the cached value to show
what was set. Previously this would have read back the value - which
would have been wrong, so this should be an improvement.
- Previously a malformed attribute (invalid name or value) would have
been registered, whereas now it is skipped. It is better not to show
invalid entries
During code review it picked up that if attributes are cleared the
setting pointer could be leaked with a driver re-probe.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 67 ++++++++++++++++---------
drivers/platform/x86/lenovo/think-lmi.h | 1 +
2 files changed, 43 insertions(+), 25 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index 63ea212b4bda..6580b1401f01 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1047,25 +1047,11 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
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);
- char *item, *value;
- int ret;
-
- ret = tlmi_setting(setting->wdev, setting->index, &item);
- if (ret)
- return ret;
- /* validate and split from `item,value` -> `value` */
- value = strpbrk(item, ",");
- if (!value || value == item || !strlen(value + 1))
- ret = -EINVAL;
- else {
- /* On Workstations remove the Options part after the value */
- strreplace(value, ';', '\0');
- ret = sysfs_emit(buf, "%s\n", value + 1);
- }
- kfree(item);
-
- return ret;
+ guard(mutex)(&tlmi_mutex);
+ if (!setting->current_value)
+ return sysfs_emit(buf, "unknown\n");
+ return sysfs_emit(buf, "%s\n", setting->current_value);
}
static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
@@ -1204,8 +1190,16 @@ static ssize_t current_value_store(struct kobject *kobj,
ret = tlmi_save_bios_settings("");
}
}
- if (!ret && !tlmi_priv.pending_changes) {
- tlmi_priv.pending_changes = true;
+ if (!ret) {
+ char *s;
+
+ if (!tlmi_priv.pending_changes)
+ tlmi_priv.pending_changes = true;
+ /* Update setting so read back shows correctly */
+ s = kstrdup(new_setting, GFP_KERNEL);
+ kfree(setting->current_value);
+ /* if kstrdup fails, show will handle null value */
+ setting->current_value = s;
/* let userland know it may need to check reboot pending again */
kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
}
@@ -1258,6 +1252,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
kfree(setting->name);
kfree(setting->display_name);
kfree(setting->possible_values);
+ kfree(setting->current_value);
kfree(setting);
}
@@ -1450,6 +1445,7 @@ static void tlmi_free_attr_record(int i)
kfree(tlmi_priv.setting[i]->name);
kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
+ kfree(tlmi_priv.setting[i]->current_value);
kfree(tlmi_priv.setting[i]);
tlmi_priv.setting[i] = NULL;
}
@@ -1469,6 +1465,8 @@ static void tlmi_release_attr(void)
kobject_put(pos);
kset_unregister(tlmi_priv.attribute_kset);
+ /* Clear up settings array */
+ memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
/* Free up any saved signatures */
if (tlmi_priv.pwd_admin) {
@@ -1707,9 +1705,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
*/
for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
struct tlmi_attr_setting *setting;
- char *item = NULL;
+ char *item = NULL, *value;
- tlmi_priv.setting[i] = NULL;
ret = tlmi_setting(wdev, i, &item);
if (ret)
break;
@@ -1720,9 +1717,6 @@ static int tlmi_analyze(struct wmi_device *wdev)
continue;
}
- /* Remove the value part */
- strreplace(item, ',', '\0');
-
/* Create a setting entry */
setting = kzalloc_obj(*setting);
if (!setting) {
@@ -1733,10 +1727,31 @@ static int tlmi_analyze(struct wmi_device *wdev)
setting->wdev = wdev;
setting->index = i;
+ /* validate and split from `item,value` -> `value` */
+ value = strpbrk(item, ",");
+ if (!value || value == item || !strlen(value + 1)) {
+ pr_info("Incorrectly formed attribute %s\n", item);
+ kfree(item);
+ kfree(setting);
+ continue;
+ }
+
+ /* On Workstations remove the Options part after the value */
+ strreplace(value, ';', '\0');
+ setting->current_value = kstrdup(value + 1, GFP_KERNEL);
+ if (!setting->current_value) {
+ ret = -ENOMEM;
+ kfree(item);
+ kfree(setting);
+ goto fail_clear_attr;
+ }
+
+ strreplace(item, ',', '\0'); /* Remove the value part */
setting->name = kstrdup(item, GFP_KERNEL);
if (!setting->name) {
ret = -ENOMEM;
kfree(item);
+ kfree(setting->current_value);
kfree(setting);
goto fail_clear_attr;
}
@@ -1748,6 +1763,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
ret = -ENOMEM;
kfree(item);
kfree(setting->name);
+ kfree(setting->current_value);
kfree(setting);
goto fail_clear_attr;
}
@@ -1879,6 +1895,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
kfree(tlmi_priv.setting[i]->name);
kfree(tlmi_priv.setting[i]->display_name);
kfree(tlmi_priv.setting[i]->possible_values);
+ kfree(tlmi_priv.setting[i]->current_value);
kfree(tlmi_priv.setting[i]);
}
}
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 8ced29253f40..54d5c3b8233e 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -104,6 +104,7 @@ struct tlmi_attr_setting {
char *name;
char *display_name;
char *possible_values;
+ char *current_value;
};
struct think_lmi {
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (2 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:30 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
` (9 subsequent siblings)
13 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Use a linked list for storing attributes instead of a fixed array.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.c | 55 +++++++++++--------------
drivers/platform/x86/lenovo/think-lmi.h | 3 +-
2 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
index 6580b1401f01..7a24985882ea 100644
--- a/drivers/platform/x86/lenovo/think-lmi.c
+++ b/drivers/platform/x86/lenovo/think-lmi.c
@@ -1249,6 +1249,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
{
struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+ list_del(&setting->node);
kfree(setting->name);
kfree(setting->display_name);
kfree(setting->possible_values);
@@ -1440,14 +1441,14 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
/* ---- Initialisation --------------------------------------------------------- */
/* Utility function to free record when not in the attribute_kset list */
-static void tlmi_free_attr_record(int i)
+static void tlmi_free_attr_record(struct tlmi_attr_setting *attr)
{
- kfree(tlmi_priv.setting[i]->name);
- kfree(tlmi_priv.setting[i]->display_name);
- kfree(tlmi_priv.setting[i]->possible_values);
- kfree(tlmi_priv.setting[i]->current_value);
- kfree(tlmi_priv.setting[i]);
- tlmi_priv.setting[i] = NULL;
+ list_del(&attr->node);
+ kfree(attr->name);
+ kfree(attr->display_name);
+ kfree(attr->possible_values);
+ kfree(attr->current_value);
+ kfree(attr);
}
static void tlmi_release_attr(void)
@@ -1465,8 +1466,6 @@ static void tlmi_release_attr(void)
kobject_put(pos);
kset_unregister(tlmi_priv.attribute_kset);
- /* Clear up settings array */
- memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
/* Free up any saved signatures */
if (tlmi_priv.pwd_admin) {
@@ -1505,7 +1504,8 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
static int tlmi_sysfs_init(void)
{
- int i, ret = 0, auth_ret = 0;
+ struct tlmi_attr_setting *attr, *na;
+ int ret = 0, auth_ret = 0;
guard(mutex)(&tlmi_mutex);
tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
@@ -1530,29 +1530,25 @@ static int tlmi_sysfs_init(void)
goto fail_device_created;
}
- for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
- /* Check if index is a valid setting - skip if it isn't */
- if (!tlmi_priv.setting[i])
- continue;
-
+ list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node) {
if (ret) { /* We had a critical failure. Just clean up */
- tlmi_free_attr_record(i);
+ tlmi_free_attr_record(attr);
continue;
}
/* check for duplicate or reserved values */
if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
- tlmi_priv.setting[i]->display_name) < 0) {
- tlmi_free_attr_record(i);
+ attr->display_name) < 0) {
+ tlmi_free_attr_record(attr);
continue;
}
/* Build attribute */
- tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
- ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
- NULL, "%s", tlmi_priv.setting[i]->display_name);
+ attr->kobj.kset = tlmi_priv.attribute_kset;
+ ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
+ NULL, "%s", attr->display_name);
if (ret) {
- kobject_put(&tlmi_priv.setting[i]->kobj);
+ kobject_put(&attr->kobj);
continue; /* use loop to clear remaining items */
}
}
@@ -1664,6 +1660,7 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
static int tlmi_analyze(struct wmi_device *wdev)
{
+ struct tlmi_attr_setting *attr, *na;
int i, ret;
if (wmi_has_guid(LENOVO_SET_BIOS_SETTINGS_GUID) &&
@@ -1699,6 +1696,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
pr_info("ThinkCenter modified support being used\n");
}
+ INIT_LIST_HEAD(&tlmi_priv.settings);
/*
* Try to find the number of valid settings of this machine
* and use it to create sysfs attributes.
@@ -1804,7 +1802,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
if (setting->possible_values)
strreplace(setting->possible_values, ',', ';');
- tlmi_priv.setting[i] = setting;
+ list_add_tail(&setting->node, &tlmi_priv.settings);
kfree(item);
}
@@ -1890,15 +1888,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
return 0;
fail_clear_attr:
- for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
- if (tlmi_priv.setting[i]) {
- kfree(tlmi_priv.setting[i]->name);
- kfree(tlmi_priv.setting[i]->display_name);
- kfree(tlmi_priv.setting[i]->possible_values);
- kfree(tlmi_priv.setting[i]->current_value);
- kfree(tlmi_priv.setting[i]);
- }
- }
+ list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node)
+ tlmi_free_attr_record(attr);
kfree(tlmi_priv.pwd_admin);
kfree(tlmi_priv.pwd_power);
kfree(tlmi_priv.pwd_system);
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 54d5c3b8233e..d0d8428ee440 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -100,6 +100,7 @@ struct tlmi_pwd_setting {
struct tlmi_attr_setting {
struct kobject kobj;
struct wmi_device *wdev;
+ struct list_head node;
int index;
char *name;
char *display_name;
@@ -123,7 +124,7 @@ struct think_lmi {
bool reboot_required;
bool thinkcenter_mode;
- struct tlmi_attr_setting *setting[TLMI_SETTINGS_COUNT];
+ struct list_head settings;
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (3 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:41 ` Rong Zhang
` (2 more replies)
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
` (8 subsequent siblings)
13 siblings, 3 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Thinkpad, ThinkCenter and ThinkStation are implementing a new WMI API that
is common across all platforms.
This adds the initial infrastructure for reading in the BIOS settings.
The tlmi-config module provides the main interface, using the config GUID,
for changing settings.
The tlmi-attr module reads in, and verifies, the BIOS attribute settings
that are available.
Future patches will add the sysfs infrastructure needed.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 1 +
drivers/platform/x86/lenovo/think-lmi.h | 10 +
drivers/platform/x86/lenovo/tlmi-attr.c | 212 ++++++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-config.c | 119 ++++++++++++
4 files changed, 342 insertions(+)
create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index 12816d8d5e24..d22b56553297 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -5,6 +5,7 @@
#
obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index d0d8428ee440..82f3644b9089 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -12,6 +12,8 @@
#define TLMI_LANG_MAXLEN 4
#define TLMI_INDEX_MAX 32
+#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
+
/* Possible error values */
struct tlmi_err_codes {
const char *err_str;
@@ -106,6 +108,9 @@ struct tlmi_attr_setting {
char *display_name;
char *possible_values;
char *current_value;
+ char *factory_default;
+ unsigned char access_level;
+ bool read_only;
};
struct think_lmi {
@@ -128,6 +133,7 @@ struct think_lmi {
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
+ struct wmi_device *config_wdev;
struct tlmi_pwdcfg pwdcfg;
struct tlmi_pwd_setting *pwd_admin;
@@ -139,4 +145,8 @@ struct think_lmi {
const struct tlmi_cert_guids *cert_guid;
};
+/* Used by tlmi to sync the different sub-drivers */
+struct component_match;
+void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
+
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
new file mode 100644
index 000000000000..04c2ecf5053b
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-attr.c
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo TLMI attributes WMI interface driver.
+ *
+ * Read in the WMI configureable BIOS settings and their properties.
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ */
+
+#include <linux/acpi.h>
+#include <linux/cleanup.h>
+#include <linux/component.h>
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+#include <linux/kobject.h>
+#include <linux/module.h>
+#include <linux/string_helpers.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
+{
+ if (setting) {
+ list_del(&setting->node);
+ kfree(setting->name);
+ kfree(setting->display_name);
+ kfree(setting->possible_values);
+ kfree(setting->current_value);
+ kfree(setting->factory_default);
+ kfree(setting);
+ }
+}
+
+#define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
+
+static int tlmi_attr_sanitize(const union acpi_object *obj, bool *valid)
+{
+ int i;
+
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < ATTRDATA_ENTRIES)
+ return -EIO;
+
+ /* First six entries should all be valid strings */
+ for (i = 0; i < 6; i++) {
+ if (obj->package.elements[i].type != ACPI_TYPE_STRING)
+ return -EIO;
+ if (!obj->package.elements[i].string.pointer[0]) {
+ /* If first entry empty, this is just an empty slot */
+ return i == 0 ? 0 : -EIO;
+ }
+ }
+ /* Remaining two are integers */
+ if (obj->package.elements[6].type != ACPI_TYPE_INTEGER)
+ return -EIO;
+ if (obj->package.elements[7].type != ACPI_TYPE_INTEGER)
+ return -EIO;
+
+ *valid = true;
+ return 0;
+}
+
+static int tlmi_attr_create_setting(int item, struct think_lmi *td, struct wmi_device *wdev)
+{
+ struct tlmi_attr_setting *setting;
+ union acpi_object *obj __free(kfree) = NULL;
+ bool valid = false;
+ int ret;
+
+ obj = wmidev_block_query(wdev, item);
+ if (!obj)
+ return 0; /* No valid entry here */
+
+ /* Confirm we have a valid item */
+ ret = tlmi_attr_sanitize(obj, &valid);
+ if (!valid) {
+ if (ret)
+ pr_info("tlmi-attr: Incorrectly formatted entry %d\n", item);
+ return 0; /* Skip this entry */
+ }
+
+ char *name __free(kfree) = kstrdup(obj->package.elements[0].string.pointer, GFP_KERNEL);
+ if (!name)
+ return -ENOMEM;
+
+ char *current_value __free(kfree) = kstrdup(obj->package.elements[1].string.pointer,
+ GFP_KERNEL);
+ if (!current_value)
+ return -ENOMEM;
+
+ char *possible_values __free(kfree) = kstrdup(obj->package.elements[2].string.pointer,
+ GFP_KERNEL);
+ if (!possible_values)
+ return -ENOMEM;
+
+ char *factory_default __free(kfree) = kstrdup(obj->package.elements[3].string.pointer,
+ GFP_KERNEL);
+ if (!factory_default)
+ return -ENOMEM;
+
+ char *display_name __free(kfree) = kstrdup(obj->package.elements[5].string.pointer,
+ GFP_KERNEL);
+ if (!display_name)
+ return -ENOMEM;
+
+ setting = kzalloc_obj(*setting);
+ if (!setting)
+ return -ENOMEM;
+
+ setting->index = item;
+ setting->access_level = obj->package.elements[6].integer.value;
+ setting->read_only = obj->package.elements[7].integer.value ? true : false;
+ setting->name = no_free_ptr(name);
+ setting->current_value = no_free_ptr(current_value);
+ setting->possible_values = no_free_ptr(possible_values);
+ setting->factory_default = no_free_ptr(factory_default);
+ setting->display_name = no_free_ptr(display_name);
+ setting->wdev = td->config_wdev; /* Used to set attributes */
+
+ list_add(&setting->node, &td->settings);
+ return 0;
+}
+
+static int tlmi_attr_component_bind(struct device *attr_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = dev_get_drvdata(attr_dev);
+ struct tlmi_attr_setting *attr, *na;
+ struct think_lmi *td = d;
+ int i, ret = 0;
+
+ INIT_LIST_HEAD(&td->settings);
+ /*
+ * Try to find the number of valid settings of this machine
+ * and use it to create sysfs attributes.
+ */
+ for (i = 0; i < TLMI_SETTINGS_COUNT - 1; ++i) {
+ ret = tlmi_attr_create_setting(i, td, wdev);
+ if (ret)
+ break;
+ }
+ if (ret) { /* Clean up as unbind will not be called */
+ list_for_each_entry_safe(attr, na, &td->settings, node)
+ tlmi_attr_release_setting(attr);
+ }
+ return ret;
+}
+
+static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *config_dev,
+ void *d)
+{
+ struct tlmi_attr_setting *attr, *na;
+ struct think_lmi *td = d;
+
+ list_for_each_entry_safe(attr, na, &td->settings, node)
+ tlmi_attr_release_setting(attr);
+}
+
+static const struct component_ops tlmi_attr_component_ops = {
+ .bind = tlmi_attr_component_bind,
+ .unbind = tlmi_attr_component_unbind,
+};
+
+static int tlmi_attr_probe(struct wmi_device *wdev, const void *context)
+{
+ dev_set_drvdata(&wdev->dev, wdev);
+ return component_add(&wdev->dev, &tlmi_attr_component_ops);
+}
+
+static void tlmi_attr_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_attr_component_ops);
+}
+
+static const struct wmi_device_id tlmi_attr_id_table[] = {
+ { TLMI_ATTRIBUTE_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_attr_driver = {
+ .driver = {
+ .name = "tlmi-attr",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_attr_id_table,
+ .probe = tlmi_attr_probe,
+ .remove = tlmi_attr_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_attr_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_attr_driver.driver);
+}
+
+void tlmi_attr_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_attr_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_attr_match_add, "TLMI-ATTR");
+
+module_wmi_driver(tlmi_attr_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_attr_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("TLMI Attributes WMI Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
new file mode 100644
index 000000000000..9f57b0ba8dc5
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo TLMI configuration WMI Data Block driver.
+ *
+ * Main controller for the tlmi-* suite of drivers.
+ * Provides ability to set and save BIOS settings.
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ */
+
+#include <linux/component.h>
+#include <linux/device.h>
+#include <linux/dev_printk.h>
+#include <linux/err.h>
+#include <linux/firmware_attributes.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/mutex_types.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+#define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
+
+/* Method IDS for configuration GUID */
+#define SET_ID 1
+#define SAVE_ID 2
+
+static int tlmi_config_bind(struct device *dev)
+{
+ struct think_lmi *td = dev_get_drvdata(dev);
+ int ret;
+
+ /* Triggers the bind callbacks for registered sub-components */
+ ret = component_bind_all(dev, td);
+ return ret;
+}
+
+static void tlmi_config_unbind(struct device *dev)
+{
+ struct think_lmi *td = dev_get_drvdata(dev);
+
+ component_unbind_all(dev, td);
+}
+
+static const struct component_master_ops aggregate_ops = {
+ .bind = tlmi_config_bind,
+ .unbind = tlmi_config_unbind,
+};
+
+static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
+{
+ struct component_match *match = NULL;
+ guid_t tlmi_attr_guid;
+ struct think_lmi *td;
+ int ret;
+
+ guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
+
+ /* At minimum need to support BIOS settings */
+ if (!wmidev_exists(&tlmi_attr_guid))
+ return -EOPNOTSUPP;
+
+ td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
+ if (!td)
+ return -ENOMEM;
+
+ td->config_wdev = wdev;
+ dev_set_drvdata(&wdev->dev, td);
+
+ td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
+ NULL, "%s", "tlmi");
+ if (IS_ERR(td->class_dev))
+ return PTR_ERR(td->class_dev);
+ dev_set_drvdata(td->class_dev, td);
+
+ /* Register the other components */
+ tlmi_attr_match_add(&wdev->dev, &match);
+
+ ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
+ if (ret)
+ device_unregister(td->class_dev);
+
+ return ret;
+}
+
+static void tlmi_config_remove(struct wmi_device *wdev)
+{
+ struct think_lmi *td = dev_get_drvdata(&wdev->dev);
+
+ component_master_del(&wdev->dev, &aggregate_ops);
+ device_unregister(td->class_dev);
+}
+
+static const struct wmi_device_id tlmi_config_id_table[] = {
+ { TLMI_CONFIG_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_config_driver = {
+ .driver = {
+ .name = "tlmi-config",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_config_id_table,
+ .probe = tlmi_config_probe,
+ .remove = tlmi_config_remove,
+ .no_singleton = true,
+};
+
+module_wmi_driver(tlmi_config_driver);
+
+MODULE_IMPORT_NS("TLMI-ATTR");
+MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("TLMI Config WMI Driver");
+MODULE_LICENSE("GPL");
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (4 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:44 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
` (7 subsequent siblings)
13 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Implement the sysfs entries for the attribute settings, along with the
ability to modify and query them.
Implement the save_settings and pending_reboot sysfs entries.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/think-lmi.h | 1 +
drivers/platform/x86/lenovo/tlmi-attr.c | 4 +-
drivers/platform/x86/lenovo/tlmi-config.c | 362 ++++++++++++++++++++++
3 files changed, 366 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 82f3644b9089..07a235b3a886 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -148,5 +148,6 @@ struct think_lmi {
/* Used by tlmi to sync the different sub-drivers */
struct component_match;
void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
index 04c2ecf5053b..8818010a45cd 100644
--- a/drivers/platform/x86/lenovo/tlmi-attr.c
+++ b/drivers/platform/x86/lenovo/tlmi-attr.c
@@ -21,7 +21,7 @@
#include <linux/wmi.h>
#include "think-lmi.h"
-static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
+void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
{
if (setting) {
list_del(&setting->node);
@@ -33,6 +33,7 @@ static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
kfree(setting);
}
}
+EXPORT_SYMBOL_NS_GPL(tlmi_attr_release_setting, "TLMI-ATTR");
#define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
@@ -157,6 +158,7 @@ static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *c
struct tlmi_attr_setting *attr, *na;
struct think_lmi *td = d;
+ /* This should not be needed - but make sure settings list is clear */
list_for_each_entry_safe(attr, na, &td->settings, node)
tlmi_attr_release_setting(attr);
}
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 9f57b0ba8dc5..ef5efae2e395 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -18,6 +18,7 @@
#include <linux/mutex.h>
#include <linux/mutex_types.h>
#include <linux/stddef.h>
+#include <linux/string_helpers.h>
#include <linux/types.h>
#include <linux/wmi.h>
#include "think-lmi.h"
@@ -28,6 +29,359 @@
#define SET_ID 1
#define SAVE_ID 2
+static DEFINE_MUTEX(tlmi_config_lock);
+
+/* ---- Helper functions---- */
+
+static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
+{
+ struct wmi_string *wmistr = (struct wmi_string *)buffer;
+ u16 len;
+ int ret;
+
+ if (!str || !buffer)
+ return -EINVAL;
+
+ ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
+ if (ret < 0)
+ return ret;
+
+ len = le16_to_cpu(wmistr->length);
+ wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
+ return len; /* minus extra null and + the length field */
+}
+
+/* Send request to BIOS and scan return buffer for error codes */
+static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
+ struct wmi_buffer *wmibuf)
+{
+ struct wmi_buffer wmibuf_return = {0, NULL};
+ char errstr[32];
+ int ret;
+
+ ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
+ sizeof(struct wmi_string));
+ if (!ret && wmibuf_return.data) {
+ /* extract error string */
+ if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
+ ret = -EINVAL;
+ else
+ ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
+ sizeof(errstr));
+ kfree(wmibuf_return.data);
+ if (ret < 0)
+ return ret;
+
+ if (!strcmp("Success", errstr))
+ return 0;
+ else if (!strcmp("Not Supported", errstr))
+ return -EOPNOTSUPP;
+ else if (!strcmp("Invalid Parameter", errstr))
+ return -EINVAL;
+ else if (!strcmp("Access Denied", errstr))
+ return -EACCES;
+ else if (!strcmp("System Busy", errstr))
+ return -EBUSY;
+ else if (!strcmp("System Locked", errstr))
+ return -EACCES;
+ dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
+ return -EIO;
+ }
+ return ret;
+}
+
+static ssize_t common_type_show(char *possible_values, char *buf)
+{
+ if (possible_values) {
+ /* Figure out what setting type is as BIOS does not return this */
+ if (strchr(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 common_current_value_store(char *name, const char *buf, int wmi_id,
+ struct think_lmi *td)
+{
+ char *new_setting __free(kfree) = NULL;
+ char *wmidata __free(kfree) = NULL;
+ size_t namelen, valuelen;
+ struct wmi_buffer wmibuf;
+ char *start;
+ int ix = 0;
+
+ /* If a save has been done then a reboot is needed */
+ if (td->reboot_required)
+ return -EPERM;
+
+ /* Strip out CR if one is present */
+ new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_setting)
+ return -ENOMEM;
+
+ /* Calculate and alloc buffer for command string */
+ namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
+ valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
+ wmibuf.length = namelen + valuelen;
+ wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
+ wmibuf.data = wmidata;
+ if (!wmibuf.data)
+ return -ENOMEM;
+
+ /* build argument buffer from inputs */
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, namelen, name);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
+ if (ix < 0)
+ return ix;
+
+ return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
+}
+
+/* ---- Attribute sysfs ---- */
+static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_attr_setting, kobj);
+}
+
+static ssize_t display_name_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->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);
+
+ guard(mutex)(&tlmi_config_lock);
+
+ if (!setting->current_value)
+ return sysfs_emit(buf, "unknown\n");
+ return sysfs_emit(buf, "%s\n", setting->current_value);
+}
+
+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 ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ return common_type_show(setting->possible_values, buf);
+}
+
+static ssize_t current_value_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int ret;
+
+ guard(mutex)(&tlmi_config_lock);
+
+ ret = common_current_value_store(setting->name, buf, SET_ID, td);
+ if (!ret) {
+ char *s;
+
+ td->save_required = true;
+ /* Update setting so read back shows correctly */
+ s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ kfree(setting->current_value);
+ /* if kstrdup fails, we'll handle it in the show */
+ setting->current_value = s;
+ return count;
+ }
+ return ret;
+}
+
+static struct kobj_attribute attr_display_name = __ATTR_RO(display_name);
+
+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_display_name.attr,
+ &attr_current_val.attr,
+ &attr_possible_values.attr,
+ &attr_type.attr,
+ NULL
+};
+
+static const struct attribute_group tlmi_attr_group = {
+ .attrs = tlmi_attrs,
+};
+__ATTRIBUTE_GROUPS(tlmi_attr);
+
+static void tlmi_attr_setting_release(struct kobject *kobj)
+{
+ struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
+
+ tlmi_attr_release_setting(setting);
+}
+
+static const struct kobj_type tlmi_attr_setting_ktype = {
+ .release = &tlmi_attr_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = tlmi_attr_groups,
+};
+
+/* ---- sysfs entries --------------------------------------------------------- */
+static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+
+ return sysfs_emit(buf, "%d\n", td->pending_changes);
+}
+
+static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
+
+static ssize_t save_settings_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+
+ return sysfs_emit(buf, "%d\n", td->save_required);
+}
+
+static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+ char *wmidata __free(kfree) = NULL;
+ struct wmi_buffer wmibuf;
+ int ret = 0;
+
+ /* save command triggered by writing 'save' */
+ if (!sysfs_streq(buf, "save"))
+ return -EINVAL;
+
+ /* Use lock in case multiple WMI operations needed */
+ guard(mutex)(&tlmi_config_lock);
+
+ /* Check there is actually something to save */
+ if (!td->save_required)
+ return -ENOENT;
+
+ wmibuf.length = struct_size_t(struct wmi_string, chars, 1 + 1);
+ wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
+ wmibuf.data = wmidata;
+ if (!wmibuf.data)
+ return -ENOMEM;
+
+ ret = tlmi_populate_string_buffer(wmibuf.data, 1, "\0");
+ if (ret < 0)
+ return ret;
+
+ ret = tlmi_request(td->config_wdev, 0, SAVE_ID, &wmibuf);
+ if (ret < 0)
+ return ret;
+
+ td->save_required = false;
+ td->reboot_required = true;
+
+ if (!td->pending_changes) {
+ td->pending_changes = true;
+ /* let userland know it may need to check reboot pending again */
+ kobject_uevent(&td->class_dev->kobj, KOBJ_CHANGE);
+ }
+ return count;
+}
+
+static struct kobj_attribute save_settings = __ATTR_RW(save_settings);
+
+static void tlmi_config_sysfs_release(struct think_lmi *td)
+{
+ struct kobject *pos, *n;
+
+ if (!td->attribute_kset)
+ return;
+
+ sysfs_remove_file(&td->attribute_kset->kobj, &pending_reboot.attr);
+ sysfs_remove_file(&td->attribute_kset->kobj, &save_settings.attr);
+
+ list_for_each_entry_safe(pos, n, &td->attribute_kset->list, entry)
+ kobject_put(pos);
+
+ kset_unregister(td->attribute_kset);
+ td->attribute_kset = NULL;
+}
+
+static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
+{
+ struct kobject *duplicate;
+
+ if (!strcmp(name, ""))
+ return -EINVAL;
+ if (!strcmp(name, "Reserved"))
+ return -EINVAL;
+
+ duplicate = kset_find_obj(attribute_kset, name);
+ if (duplicate) {
+ /* kset_find_obj() returns a reference */
+ kobject_put(duplicate);
+ return -EBUSY;
+ }
+
+ return 0;
+}
+
+static int tlmi_config_sysfs_init(struct think_lmi *td)
+{
+ struct tlmi_attr_setting *attr, *na;
+ int ret;
+
+ /* Create sysfs entries */
+ td->attribute_kset = kset_create_and_add("attributes", NULL,
+ &td->class_dev->kobj);
+ if (!td->attribute_kset)
+ return -ENOMEM;
+
+ list_for_each_entry_safe(attr, na, &td->settings, node) {
+ /* check for duplicate or reserved values */
+ if (tlmi_validate_setting_name(td->attribute_kset,
+ attr->name) < 0)
+ continue;
+
+ /* Build attribute */
+ attr->kobj.kset = td->attribute_kset;
+ ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
+ NULL, "%s", attr->name);
+ if (ret) {
+ kobject_put(&attr->kobj);
+ goto out;
+ }
+ }
+
+ ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
+ if (ret)
+ goto out;
+
+ ret = sysfs_create_file(&td->attribute_kset->kobj, &save_settings.attr);
+
+out:
+ if (ret) /* Clean up if any failures */
+ tlmi_config_sysfs_release(td);
+ return ret;
+}
+
static int tlmi_config_bind(struct device *dev)
{
struct think_lmi *td = dev_get_drvdata(dev);
@@ -35,6 +389,13 @@ static int tlmi_config_bind(struct device *dev)
/* Triggers the bind callbacks for registered sub-components */
ret = component_bind_all(dev, td);
+ if (ret)
+ return ret;
+ /* Create sysfs entries */
+ ret = tlmi_config_sysfs_init(td);
+ if (ret)
+ component_unbind_all(dev, td);
+
return ret;
}
@@ -42,6 +403,7 @@ static void tlmi_config_unbind(struct device *dev)
{
struct think_lmi *td = dev_get_drvdata(dev);
+ tlmi_config_sysfs_release(td);
component_unbind_all(dev, td);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (5 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:48 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
` (6 subsequent siblings)
13 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add authdata module for reading in the authorisation account
details from the BIOS.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 2 +-
drivers/platform/x86/lenovo/think-lmi.h | 13 ++
drivers/platform/x86/lenovo/tlmi-authdata.c | 135 ++++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-config.c | 10 +-
4 files changed, 156 insertions(+), 4 deletions(-)
create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index d22b56553297..f1600b562273 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -5,7 +5,7 @@
#
obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
-obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 07a235b3a886..75b21dcc2f42 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -13,6 +13,7 @@
#define TLMI_INDEX_MAX 32
#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
+#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
/* Possible error values */
struct tlmi_err_codes {
@@ -75,9 +76,20 @@ struct tlmi_pwdcfg_ext {
uint32_t nvme_master_password;
};
+/* fields specific to tlmi-authdata driver */
+struct tlmi_pwdcfg_authdata {
+ bool strong_password;
+ bool deploy_mode;
+ bool sys_mgr_pwd_ctrl;
+ bool power_on_pwd_ctrl;
+ bool storage_pwd_ctrl;
+ bool sys_mgr_setup_ctrl;
+};
+
struct tlmi_pwdcfg {
struct tlmi_pwdcfg_core core;
struct tlmi_pwdcfg_ext ext;
+ struct tlmi_pwdcfg_authdata authdata;
};
/* password setting details */
@@ -149,5 +161,6 @@ struct think_lmi {
struct component_match;
void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
+void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-authdata.c b/drivers/platform/x86/lenovo/tlmi-authdata.c
new file mode 100644
index 000000000000..668d07029139
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-authdata.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo ThinkLMI authentication data WMI interface driver.
+ *
+ * Read in the WMI authentication settings and their properties.
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ */
+
+#include <linux/cleanup.h>
+#include <linux/component.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+#define AUTHDATA_ENTRIES 15 /*number of entries returned from BIOS */
+
+static int tlmi_authdata_sanitize(const union acpi_object *obj)
+{
+ int i;
+
+ /*Scan through query result and check it's sane*/
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < AUTHDATA_ENTRIES)
+ return -EIO;
+
+ for (i = 0; i < AUTHDATA_ENTRIES; i++) {
+ /* Every entry is an integer which makes this easy */
+ if (obj->package.elements[i].type != ACPI_TYPE_INTEGER)
+ return -EIO;
+ }
+ return 0;
+}
+
+/* Get password settings from BIOS */
+static int tlmi_authdata_get(struct wmi_device *wdev, struct think_lmi *td)
+{
+ const union acpi_object *obj __free(kfree) = NULL;
+ int ret;
+
+ obj = wmidev_block_query(wdev, 0);
+ if (!obj)
+ return -EIO;
+
+ ret = tlmi_authdata_sanitize(obj);
+ if (ret)
+ return ret;
+
+ td->pwdcfg.core.password_state = obj->package.elements[0].integer.value;
+ td->pwdcfg.core.min_length = obj->package.elements[1].integer.value;
+ td->pwdcfg.core.max_length = obj->package.elements[2].integer.value;
+ td->pwdcfg.authdata.strong_password = obj->package.elements[3].integer.value;
+ td->pwdcfg.core.supported_encodings = obj->package.elements[4].integer.value;
+ td->pwdcfg.core.supported_keyboard = obj->package.elements[5].integer.value;
+ td->pwdcfg.ext.hdd_user_password = obj->package.elements[6].integer.value;
+ td->pwdcfg.ext.hdd_master_password = obj->package.elements[7].integer.value;
+ td->pwdcfg.ext.nvme_user_password = obj->package.elements[8].integer.value;
+ td->pwdcfg.ext.nvme_master_password = obj->package.elements[9].integer.value;
+ td->pwdcfg.authdata.deploy_mode = obj->package.elements[10].integer.value;
+ td->pwdcfg.authdata.sys_mgr_pwd_ctrl = obj->package.elements[11].integer.value;
+ td->pwdcfg.authdata.power_on_pwd_ctrl = obj->package.elements[12].integer.value;
+ td->pwdcfg.authdata.storage_pwd_ctrl = obj->package.elements[13].integer.value;
+ td->pwdcfg.authdata.sys_mgr_setup_ctrl = obj->package.elements[14].integer.value;
+
+ if (WARN_ON(td->pwdcfg.core.max_length >= TLMI_PWD_BUFSIZE))
+ td->pwdcfg.core.max_length = TLMI_PWD_BUFSIZE - 1;
+ if (WARN_ON(td->pwdcfg.core.min_length > td->pwdcfg.core.max_length))
+ td->pwdcfg.core.min_length = td->pwdcfg.core.max_length;
+
+ return 0;
+}
+
+static int tlmi_authdata_component_bind(struct device *authdata_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = dev_get_drvdata(authdata_dev);
+ struct think_lmi *td = d;
+
+ return tlmi_authdata_get(wdev, td);
+}
+
+static const struct component_ops tlmi_authdata_component_ops = {
+ .bind = tlmi_authdata_component_bind,
+};
+
+static int tlmi_authdata_probe(struct wmi_device *wdev, const void *context)
+{
+ dev_set_drvdata(&wdev->dev, wdev);
+
+ return component_add(&wdev->dev, &tlmi_authdata_component_ops);
+}
+
+static void tlmi_authdata_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_authdata_component_ops);
+}
+
+static const struct wmi_device_id tlmi_authdata_id_table[] = {
+ { TLMI_AUTHENTICATION_DATA_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_authdata_driver = {
+ .driver = {
+ .name = "tlmi-authdata",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_authdata_id_table,
+ .probe = tlmi_authdata_probe,
+ .remove = tlmi_authdata_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_authdata_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_authdata_driver.driver);
+}
+
+void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_authdata_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_authdata_match_add, "TLMI-AUTHDATA");
+
+module_wmi_driver(tlmi_authdata_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_authdata_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Authentication Data WMI Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index ef5efae2e395..ddbf0307f810 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -415,14 +415,16 @@ static const struct component_master_ops aggregate_ops = {
static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
{
struct component_match *match = NULL;
- guid_t tlmi_attr_guid;
+ guid_t tlmi_attr_guid, tlmi_authdata_guid;
struct think_lmi *td;
int ret;
guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
+ guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
- /* At minimum need to support BIOS settings */
- if (!wmidev_exists(&tlmi_attr_guid))
+ /* At minimum need to support BIOS and authentication settings */
+ if (!wmidev_exists(&tlmi_attr_guid) ||
+ !wmidev_exists(&tlmi_authdata_guid))
return -EOPNOTSUPP;
td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
@@ -440,6 +442,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
/* Register the other components */
tlmi_attr_match_add(&wdev->dev, &match);
+ tlmi_authdata_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -475,6 +478,7 @@ static struct wmi_driver tlmi_config_driver = {
module_wmi_driver(tlmi_config_driver);
MODULE_IMPORT_NS("TLMI-ATTR");
+MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (6 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:49 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
` (5 subsequent siblings)
13 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
The tlmi_populate_string_buffer and tlmi_request are going to be
needed in the upcoming tlmi-auth module, as well as the current
tlmi-config module.
As we can't have circular dependencies they need to move out of
tlmi-config.
The wmi-helpers module already provides helper functions for the
Lenovo Legion platforms, and seems a logical place for these to
move too.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Kconfig | 1 +
drivers/platform/x86/lenovo/tlmi-config.c | 59 +-------------------
drivers/platform/x86/lenovo/wmi-helpers.c | 65 ++++++++++++++++++++++-
drivers/platform/x86/lenovo/wmi-helpers.h | 5 ++
4 files changed, 72 insertions(+), 58 deletions(-)
diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
index 16569406c946..c59461cf5f4a 100644
--- a/drivers/platform/x86/lenovo/Kconfig
+++ b/drivers/platform/x86/lenovo/Kconfig
@@ -218,6 +218,7 @@ config THINKPAD_LMI
depends on ACPI_WMI
depends on DMI
select FW_ATTR_CLASS
+ select LENOVO_WMI_HELPERS
help
This driver allows changing BIOS settings on Lenovo machines whose
BIOS support the WMI interface.
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index ddbf0307f810..bb9c5f720c24 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/wmi.h>
#include "think-lmi.h"
+#include "wmi-helpers.h"
#define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
@@ -33,63 +34,6 @@ static DEFINE_MUTEX(tlmi_config_lock);
/* ---- Helper functions---- */
-static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
-{
- struct wmi_string *wmistr = (struct wmi_string *)buffer;
- u16 len;
- int ret;
-
- if (!str || !buffer)
- return -EINVAL;
-
- ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
- if (ret < 0)
- return ret;
-
- len = le16_to_cpu(wmistr->length);
- wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
- return len; /* minus extra null and + the length field */
-}
-
-/* Send request to BIOS and scan return buffer for error codes */
-static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
- struct wmi_buffer *wmibuf)
-{
- struct wmi_buffer wmibuf_return = {0, NULL};
- char errstr[32];
- int ret;
-
- ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
- sizeof(struct wmi_string));
- if (!ret && wmibuf_return.data) {
- /* extract error string */
- if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
- ret = -EINVAL;
- else
- ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
- sizeof(errstr));
- kfree(wmibuf_return.data);
- if (ret < 0)
- return ret;
-
- if (!strcmp("Success", errstr))
- return 0;
- else if (!strcmp("Not Supported", errstr))
- return -EOPNOTSUPP;
- else if (!strcmp("Invalid Parameter", errstr))
- return -EINVAL;
- else if (!strcmp("Access Denied", errstr))
- return -EACCES;
- else if (!strcmp("System Busy", errstr))
- return -EBUSY;
- else if (!strcmp("System Locked", errstr))
- return -EACCES;
- dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
- return -EIO;
- }
- return ret;
-}
-
static ssize_t common_type_show(char *possible_values, char *buf)
{
if (possible_values) {
@@ -477,6 +421,7 @@ static struct wmi_driver tlmi_config_driver = {
module_wmi_driver(tlmi_config_driver);
+MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
index 687caa226263..e735771bb8d7 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.c
+++ b/drivers/platform/x86/lenovo/wmi-helpers.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Lenovo Legion WMI helpers driver.
+ * Lenovo Legion and TLMI WMI helpers driver.
*
* The Lenovo Legion WMI interface is broken up into multiple GUID interfaces
* that require cross-references between GUID's for some functionality. The
@@ -13,6 +13,10 @@
* drivers uses a common procedure to get data from the WMI interface,
* enumerated here.
*
+ * TLMI interface uses multiple GUID interfaces for BIOS settings and
+ * authentication settings. A common procedure is used to get data from the
+ * WMI interface and check for return error strings.
+ *
* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
*/
@@ -33,6 +37,65 @@
/* Thermal mode notifier chain. */
static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
+ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
+{
+ struct wmi_string *wmistr = (struct wmi_string *)buffer;
+ u16 len;
+ int ret;
+
+ if (!str || !buffer)
+ return -EINVAL;
+
+ ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
+ if (ret < 0)
+ return ret;
+
+ len = le16_to_cpu(wmistr->length);
+ wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
+ return len; /* minus extra null and + the length field */
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_populate_string_buffer, "LENOVO_WMI_HELPERS");
+
+/* Send request to BIOS and scan return buffer for error codes */
+int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
+ struct wmi_buffer *wmibuf)
+{
+ struct wmi_buffer wmibuf_return = {0, NULL};
+ char errstr[32];
+ int ret;
+
+ ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
+ sizeof(struct wmi_string));
+ if (!ret && wmibuf_return.data) {
+ /* extract error string */
+ if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
+ ret = -EINVAL;
+ else
+ ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
+ sizeof(errstr));
+ kfree(wmibuf_return.data);
+ if (ret < 0)
+ return ret;
+
+ if (!strcmp("Success", errstr))
+ return 0;
+ else if (!strcmp("Not Supported", errstr))
+ return -EOPNOTSUPP;
+ else if (!strcmp("Invalid Parameter", errstr))
+ return -EINVAL;
+ else if (!strcmp("Access Denied", errstr))
+ return -EACCES;
+ else if (!strcmp("System Busy", errstr))
+ return -EBUSY;
+ else if (!strcmp("System Locked", errstr))
+ return -EACCES;
+ dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
+ return -EIO;
+ }
+ return ret;
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_request, "LENOVO_WMI_HELPERS");
+
/**
* lwmi_dev_evaluate_int() - Helper function for calling WMI methods that
* return an integer.
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
index 039fe61003ce..f9c05aa25d69 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.h
+++ b/drivers/platform/x86/lenovo/wmi-helpers.h
@@ -10,6 +10,7 @@
struct device;
struct notifier_block;
struct wmi_device;
+struct wmi_buffer;
struct wmi_method_args_32 {
u32 arg0;
@@ -31,6 +32,10 @@ enum thermal_mode {
LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
};
+ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str);
+int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
+ struct wmi_buffer *wmibuf);
+
int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
unsigned char *buf, size_t size, u32 *retval);
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (7 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:52 ` Rong Zhang
2026-12-05 9:55 ` kernel test robot
2026-12-04 2:20 ` [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Mark Pearson
` (4 subsequent siblings)
13 siblings, 2 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add interface to authentication settings using it's associated GUID.
tlmi-auth uses the data read in by tlmi-authdata.
Enables ability to configure admin, system, power-on, hdd and nvme
passwords.
Enables certificate support.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 2 +-
drivers/platform/x86/lenovo/think-lmi.h | 6 +
drivers/platform/x86/lenovo/tlmi-auth.c | 958 ++++++++++++++++++++++
drivers/platform/x86/lenovo/tlmi-config.c | 50 +-
4 files changed, 1009 insertions(+), 7 deletions(-)
create mode 100644 drivers/platform/x86/lenovo/tlmi-auth.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index f1600b562273..6434e77f4ed3 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -5,7 +5,7 @@
#
obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
-obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o tlmi-auth.o
obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 75b21dcc2f42..6ab9a7e6fabf 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -13,6 +13,7 @@
#define TLMI_INDEX_MAX 32
#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
+#define TLMI_AUTHENTICATION_GUID "5cb5f556-30ce-40d3-a135-7ca0648a5a52"
#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
/* Possible error values */
@@ -95,6 +96,7 @@ struct tlmi_pwdcfg {
/* password setting details */
struct tlmi_pwd_setting {
struct kobject kobj;
+ struct wmi_device *wdev;
bool pwd_enabled;
char password[TLMI_PWD_BUFSIZE];
const char *pwd_type;
@@ -146,6 +148,7 @@ struct think_lmi {
struct kset *attribute_kset;
struct kset *authentication_kset;
struct wmi_device *config_wdev;
+ struct wmi_device *auth_wdev;
struct tlmi_pwdcfg pwdcfg;
struct tlmi_pwd_setting *pwd_admin;
@@ -153,6 +156,7 @@ struct think_lmi {
struct tlmi_pwd_setting *pwd_system;
struct tlmi_pwd_setting *pwd_hdd;
struct tlmi_pwd_setting *pwd_nvme;
+ struct mutex tlmi_auth_lock; /* shared between auth and config */
const struct tlmi_cert_guids *cert_guid;
};
@@ -162,5 +166,7 @@ struct component_match;
void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_auth_match_add(struct device *master, struct component_match **matchptr);
+int tlmi_auth_authenticate_user(struct think_lmi *td);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-auth.c b/drivers/platform/x86/lenovo/tlmi-auth.c
new file mode 100644
index 000000000000..d18cf6390663
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-auth.c
@@ -0,0 +1,958 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo ThinkLMI Authentication WMI interface driver.
+ *
+ * Manage the WMI authentication settings and their properties.
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ */
+
+#include <linux/component.h>
+#include <linux/device.h>
+#include <linux/dmi.h>
+#include <linux/kdev_t.h>
+#include <linux/kobject.h>
+#include <linux/limits.h>
+#include <linux/module.h>
+#include <linux/string_helpers.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+#include "wmi-helpers.h"
+
+#define MAX_HDD_INDEX 4
+#define MAX_NVME_INDEX 8
+
+enum pwd_type_v2 {
+ SVP = 0,
+ SMP = 1,
+ POP = 2,
+ HDD = 3, /* 3 to 6 */
+ NVME = HDD + MAX_HDD_INDEX, /* 7 to 14 */
+ MASTERHDD = NVME + MAX_NVME_INDEX, /* 15 to 18 */
+ MASTERNVME = MASTERHDD + MAX_HDD_INDEX, /* 19 to 26 */
+};
+
+/* Method IDS for Access GUID */
+#define SET_PASSWORD 1
+#define AUTHENTICATE 2
+#define SET_CERT 3
+#define UPDATE_CERT 4
+#define CLEAR_CERT 5
+#define CERT_TO_PWD 6
+#define CERT_THUMBPRINT 7
+
+#define TLMI_POP_PWD BIT(0) /* Power-on */
+#define TLMI_SVP_PWD BIT(1) /* Supervisor */
+#define TLMI_SMP_PWD BIT(2) /* System Management */
+#define TLMI_SVC_PWD BIT(7) /* Supervisor Certificate */
+#define TLMI_SMC_PWD BIT(8) /* System Certificate */
+
+static const char * const level_options[] = {
+ [TLMI_LEVEL_USER] = "user",
+ [TLMI_LEVEL_MASTER] = "master",
+};
+
+int tlmi_auth_authenticate_user(struct think_lmi *td)
+{
+ struct wmi_buffer wmibuf;
+ char *password;
+ int ret;
+
+ lockdep_assert_held(&td->tlmi_auth_lock);
+
+ /* If certificate used, we use signatures not passwords*/
+ if (td->pwd_admin->cert_installed ||
+ td->pwd_system->cert_installed)
+ return 0;
+
+ /* If admin password configured, use that. If not try system */
+ if (strlen(td->pwd_admin->password) > 0)
+ password = td->pwd_admin->password;
+ else if (strlen(td->pwd_system->password) > 0)
+ password = td->pwd_system->password;
+ else
+ /* No password configured, so no need to run authentication */
+ return 0;
+
+ wmibuf.length = struct_size_t(struct wmi_string, chars, strlen(password) + 1);
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ ret = tlmi_populate_string_buffer(wmibuf.data, wmibuf.length, password);
+ if (ret < 0)
+ return ret;
+
+ return tlmi_request(td->auth_wdev, 0, AUTHENTICATE, &wmibuf);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_auth_authenticate_user, "TLMI-AUTH");
+
+/* ---- Authentication sysfs ---- */
+static inline struct tlmi_pwd_setting *to_tlmi_pwd_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_pwd_setting, kobj);
+}
+
+static ssize_t is_enabled_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->pwd_enabled || setting->cert_installed);
+}
+
+static struct kobj_attribute auth_is_pass_set = __ATTR_RO(is_enabled);
+
+static ssize_t current_password_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ size_t pwdlen;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Strip newline; setting password won't work if one is present. */
+ pwdlen = strchrnul(buf, '\n') - buf;
+ /* pwdlen == 0 is allowed to clear the password */
+ if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
+ return -EINVAL;
+
+ strscpy(setting->password, buf, pwdlen + 1);
+ return count;
+}
+
+static struct kobj_attribute auth_current_password = __ATTR_WO(current_password);
+
+static ssize_t new_password_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ enum pwd_type_v2 pwd_type;
+ size_t pwdlen, cur_pwdlen;
+ struct wmi_buffer wmibuf;
+ char *start;
+ int ix = 0;
+ int ret;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Authorisation needs to be done first */
+ ret = tlmi_auth_authenticate_user(td);
+ /* Ignore most errors. We might be in deployment mode */
+ if (ret == -ENOMEM)
+ return ret;
+
+ /* Strip out CR if one is present, setting password won't work if it is present */
+ char *new_pwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_pwd)
+ return -ENOMEM;
+
+ pwdlen = strlen(new_pwd);
+ /* pwdlen == 0 is allowed to clear the password */
+ if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
+ return -EINVAL;
+
+ cur_pwdlen = struct_size_t(struct wmi_string, chars, strlen(setting->password) + 1);
+ pwdlen = struct_size_t(struct wmi_string, chars, strlen(new_pwd) + 1);
+ wmibuf.length = 2 + cur_pwdlen + pwdlen;
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ if (setting == td->pwd_admin) {
+ pwd_type = SVP;
+ } else if (setting == td->pwd_power) {
+ pwd_type = POP;
+ } else if (setting == td->pwd_system) {
+ pwd_type = SMP;
+ } else if (setting == td->pwd_hdd) {
+ if (setting->level == TLMI_LEVEL_MASTER)
+ pwd_type = MASTERHDD;
+ else
+ pwd_type = HDD;
+ pwd_type += setting->index - 1;
+ } else if (setting == td->pwd_nvme) {
+ if (setting->level == TLMI_LEVEL_MASTER)
+ pwd_type = MASTERNVME;
+ else
+ pwd_type = NVME;
+ pwd_type += setting->index - 1;
+ } else {
+ return -EOPNOTSUPP;
+ }
+
+ start = wmibuf.data;
+ start[0] = pwd_type;
+ start += 2;
+
+ ix = tlmi_populate_string_buffer(start, cur_pwdlen, setting->password);
+ if (ix < 0)
+ return ix;
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, pwdlen, new_pwd);
+ if (ix < 0)
+ return ix;
+
+ ret = tlmi_request(td->auth_wdev, 0, SET_PASSWORD, &wmibuf);
+ return ret ?: count;
+}
+
+static struct kobj_attribute auth_new_password = __ATTR_WO(new_password);
+
+static ssize_t min_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->minlen);
+}
+
+static struct kobj_attribute auth_min_pass_length = __ATTR_RO(min_password_length);
+
+static ssize_t max_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->maxlen);
+}
+
+static struct kobj_attribute auth_max_pass_length = __ATTR_RO(max_password_length);
+
+static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ if (setting->cert_installed)
+ return sysfs_emit(buf, "certificate\n");
+ return sysfs_emit(buf, "password\n");
+}
+
+static struct kobj_attribute auth_mechanism = __ATTR_RO(mechanism);
+
+static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->role);
+}
+
+static struct kobj_attribute auth_role = __ATTR_RO(role);
+
+static ssize_t index_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->index);
+}
+
+static ssize_t index_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int err, val, max;
+
+ err = kstrtoint(buf, 10, &val);
+ if (err < 0)
+ return err;
+
+ if (setting == td->pwd_hdd)
+ max = MAX_HDD_INDEX;
+ else if (setting == td->pwd_nvme)
+ max = MAX_NVME_INDEX;
+ else
+ return -EOPNOTSUPP;
+
+ if (val <= 0 || val > max)
+ return -EINVAL;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+ setting->index = val;
+ return count;
+}
+
+static struct kobj_attribute auth_index = __ATTR_RW(index);
+
+static ssize_t level_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", level_options[setting->level]);
+}
+
+static ssize_t level_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int i;
+
+ /* Scan for a matching profile */
+ i = sysfs_match_string(level_options, buf);
+ if (i < 0)
+ return -EINVAL;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+ setting->level = i;
+ return count;
+}
+
+static struct kobj_attribute auth_level = __ATTR_RW(level);
+
+static char *thumbtypes[] = {"SHA1", "SHA256", "SHA384", "SHA512", "MD5"};
+#define MAX_SHA_LEN 513
+
+static ssize_t cert_thumbprint(char *buf, char *type, unsigned char alg, int *count,
+ struct think_lmi *td)
+{
+ struct wmi_buffer wmibuf, wmibuf_thumb;
+ int ix, ret;
+ char *start;
+
+ if (!type)
+ return -EINVAL;
+
+ wmibuf.length = struct_size_t(struct wmi_string, chars, strlen(type) + 2);
+ char *wmidata __free(kfree) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ char *thumbstr __free(kfree) = kzalloc(MAX_SHA_LEN, GFP_KERNEL);
+ if (!thumbstr)
+ return -ENOMEM;
+
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, wmibuf.length, type);
+ if (ix < 0)
+ return ix;
+ start += ix;
+ *start = alg;
+
+ ret = wmidev_invoke_method(td->auth_wdev, 0, CERT_THUMBPRINT, &wmibuf, &wmibuf_thumb,
+ sizeof(struct wmi_string));
+ if (ret < 0)
+ return ret;
+
+ if (wmibuf_thumb.data) {
+ /* Check for valid string */
+ if (wmibuf_thumb.length < 2 || wmibuf_thumb.length > MAX_SHA_LEN * 2)
+ ret = -EINVAL;
+ else
+ /* Extract thumbprint */
+ ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_thumb.data,
+ thumbstr, MAX_SHA_LEN);
+ kfree(wmibuf_thumb.data);
+ if (ret > 0)
+ *count += sysfs_emit_at(buf, *count, "%s : %s\n",
+ thumbtypes[alg], thumbstr);
+ }
+
+ return ret;
+}
+
+static ssize_t certificate_thumbprint_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ unsigned int i;
+ int ret, count = 0;
+
+ if (!setting->cert_installed)
+ return -EOPNOTSUPP;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ for (i = 0; i < ARRAY_SIZE(thumbtypes); i++) {
+ ret = cert_thumbprint(buf, setting == td->pwd_admin ? "SVC" : "SMC",
+ i, &count, td);
+ if (ret < 0)
+ return ret;
+ }
+
+ return count;
+}
+
+static struct kobj_attribute auth_cert_thumb = __ATTR_RO(certificate_thumbprint);
+
+static ssize_t cert_to_password_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ size_t typelen, pwdlen, siglen;
+ char *start, *cert_type;
+ struct wmi_buffer wmibuf;
+ int ret = -EINVAL;
+ int ix;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (!setting->cert_installed)
+ return -EINVAL;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ if (!setting->signature || !setting->signature[0])
+ return -EACCES;
+
+ /* Strip out CR if one is present */
+ char *passwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!passwd)
+ return -ENOMEM;
+
+ cert_type = (setting == td->pwd_admin) ? "SVC" : "SMC";
+ typelen = struct_size_t(struct wmi_string, chars, strlen(cert_type) + 1);
+ pwdlen = struct_size_t(struct wmi_string, chars, strlen(passwd) + 1);
+ siglen = struct_size_t(struct wmi_string, chars, strlen(setting->signature) + 1);
+ wmibuf.length = typelen + pwdlen + siglen;
+
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, typelen, cert_type);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, pwdlen, passwd);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ ix = tlmi_populate_string_buffer(start, siglen, setting->signature);
+ if (ix < 0)
+ return ix;
+
+ ret = tlmi_request(td->auth_wdev, 0, CERT_TO_PWD, &wmibuf);
+
+ return ret ?: count;
+}
+
+static struct kobj_attribute auth_cert_to_password = __ATTR_WO(cert_to_password);
+
+static ssize_t certificate_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ struct tlmi_pwd_setting *pwd_admin = td->pwd_admin;
+ size_t typelen, certlen, pwdlen, siglen, seriallen;
+ struct wmi_buffer wmibuf;
+ char *start;
+ char *signature, *cert_type;
+ int install_mode = SET_CERT;
+ const char *serial;
+ int ix = 0;
+ int ret;
+
+ char *new_cert __free(kfree_sensitive) = NULL;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ cert_type = (setting == pwd_admin) ? "SVC" : "SMC";
+ typelen = struct_size_t(struct wmi_string, chars, strlen(cert_type) + 1);
+
+ if ((buf[0] == '\0') || (buf[0] == '\n')) {
+ /*
+ * Clear installed certificate
+ * Format: 'Type, serial#, signature'
+ */
+
+ /* Check that signature is set */
+ if (!setting->signature || !setting->signature[0])
+ return -EACCES;
+
+ install_mode = CLEAR_CERT;
+ serial = dmi_get_system_info(DMI_PRODUCT_SERIAL);
+ if (!serial)
+ return -ENODEV;
+ seriallen = struct_size_t(struct wmi_string, chars, strlen(serial) + 1);
+ signature = setting->signature;
+ siglen = struct_size_t(struct wmi_string, chars, strlen(signature) + 1);
+ wmibuf.length = typelen + seriallen + siglen;
+ } else {
+ /* New install, or update */
+ /* Strip out CR from certificate if one is present */
+ new_cert = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_cert)
+ return -ENOMEM;
+ certlen = struct_size_t(struct wmi_string, chars, strlen(new_cert) + 1);
+
+ if (setting->cert_installed) {
+ /*
+ * Update installed certificate
+ * Format: 'Type, Certificate, signature'
+ */
+ install_mode = UPDATE_CERT;
+ /* If admin account enabled - need to use its signature */
+ if (pwd_admin && pwd_admin->pwd_enabled)
+ signature = pwd_admin->signature;
+ else
+ signature = setting->signature;
+ if (!signature)
+ return -EINVAL;
+
+ siglen = struct_size_t(struct wmi_string, chars, strlen(signature) + 1);
+ wmibuf.length = typelen + certlen + siglen;
+ } else {
+ /*
+ * Install a new certificate
+ * Format: 'Type, Certificate, Password'
+ */
+ install_mode = SET_CERT;
+ /* To set admin cert, a password must be enabled */
+ if (setting == pwd_admin &&
+ (!setting->pwd_enabled || !setting->password[0]))
+ return -EACCES;
+
+ pwdlen = struct_size_t(struct wmi_string, chars,
+ strlen(setting->password) + 1);
+ wmibuf.length = typelen + certlen + pwdlen;
+ }
+ }
+
+ /* Set up WMI buffer */
+ char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
+ if (!wmidata)
+ return -ENOMEM;
+ wmibuf.data = wmidata;
+
+ start = wmibuf.data;
+ ix = tlmi_populate_string_buffer(start, typelen, cert_type);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ if (install_mode == CLEAR_CERT)
+ ix = tlmi_populate_string_buffer(start, seriallen, serial);
+ else
+ ix = tlmi_populate_string_buffer(start, certlen, new_cert);
+ if (ix < 0)
+ return ix;
+
+ start += ix;
+ if (install_mode == SET_CERT)
+ ix = tlmi_populate_string_buffer(start, pwdlen, setting->password);
+ else
+ ix = tlmi_populate_string_buffer(start, siglen, signature);
+ if (ix < 0)
+ return ix;
+
+ ret = tlmi_request(td->auth_wdev, 0, install_mode, &wmibuf);
+
+ return ret ?: count;
+}
+
+static struct kobj_attribute auth_certificate = __ATTR_WO(certificate);
+
+static ssize_t signature_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ char *new_signature;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Strip out CR if one is present */
+ new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_signature)
+ return -ENOMEM;
+
+ /* Free any previous signature */
+ kfree_sensitive(setting->signature);
+ setting->signature = new_signature;
+
+ return count;
+}
+
+static struct kobj_attribute auth_signature = __ATTR_WO(signature);
+
+static ssize_t save_signature_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ char *new_signature;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Strip out CR if one is present */
+ new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ if (!new_signature)
+ return -ENOMEM;
+
+ /* Free any previous signature */
+ kfree_sensitive(setting->save_signature);
+ setting->save_signature = new_signature;
+
+ return count;
+}
+
+static struct kobj_attribute auth_save_signature = __ATTR_WO(save_signature);
+
+static umode_t auth_attr_is_visible(struct kobject *kobj,
+ struct attribute *attr, int n)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+
+ /* We only want to display level and index settings on HDD/NVMe */
+ if (attr == &auth_index.attr || attr == &auth_level.attr) {
+ if (setting == td->pwd_hdd || setting == td->pwd_nvme)
+ return attr->mode;
+ return 0;
+ }
+
+ return attr->mode;
+}
+
+static struct attribute *auth_attrs[] = {
+ &auth_is_pass_set.attr,
+ &auth_min_pass_length.attr,
+ &auth_max_pass_length.attr,
+ &auth_current_password.attr,
+ &auth_new_password.attr,
+ &auth_role.attr,
+ &auth_mechanism.attr,
+ &auth_index.attr,
+ &auth_level.attr,
+ &auth_certificate.attr,
+ &auth_signature.attr,
+ &auth_save_signature.attr,
+ &auth_cert_thumb.attr,
+ &auth_cert_to_password.attr,
+ NULL
+};
+
+static const struct attribute_group auth_attr_group = {
+ .is_visible = auth_attr_is_visible,
+ .attrs = auth_attrs,
+};
+__ATTRIBUTE_GROUPS(auth_attr);
+
+static void tlmi_pwd_setting_release(struct kobject *kobj)
+{
+ struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
+
+ kfree_sensitive(setting->save_signature);
+ kfree_sensitive(setting->signature);
+ kfree_sensitive(setting);
+}
+
+static const struct kobj_type tlmi_pwd_setting_ktype = {
+ .release = &tlmi_pwd_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = auth_attr_groups,
+};
+
+static void tlmi_auth_sysfs_release(struct think_lmi *td)
+{
+ struct kobject *pos, *n;
+
+ if (!td || !td->authentication_kset)
+ return;
+
+ /* Authentication structures */
+ list_for_each_entry_safe(pos, n, &td->authentication_kset->list, entry)
+ kobject_put(pos);
+
+ kset_unregister(td->authentication_kset);
+
+ /* Prevent dangling pointers */
+ td->authentication_kset = NULL;
+ td->pwd_admin = NULL;
+ td->pwd_system = NULL;
+ td->pwd_power = NULL;
+ td->pwd_hdd = NULL;
+ td->pwd_nvme = NULL;
+}
+
+static int tlmi_auth_sysfs_init(struct think_lmi *td)
+{
+ int ret;
+
+ if (!td)
+ return -EINVAL;
+
+ /* Create authentication entries */
+ td->authentication_kset = kset_create_and_add("authentication", NULL,
+ &td->class_dev->kobj);
+ if (!td->authentication_kset) {
+ ret = -ENOMEM;
+ goto out_admin_fail;
+ }
+
+ td->pwd_admin->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_admin->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "Admin");
+ if (ret)
+ goto out_admin_fail;
+
+ td->pwd_power->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_power->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "Power-on");
+ if (ret)
+ goto out_power_fail;
+
+ td->pwd_system->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_system->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "System");
+ if (ret)
+ goto out_system_fail;
+
+ td->pwd_hdd->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "HDD");
+ if (ret)
+ goto out_hdd_fail;
+
+ td->pwd_nvme->kobj.kset = td->authentication_kset;
+ ret = kobject_init_and_add(&td->pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
+ NULL, "%s", "NVMe");
+ if (ret)
+ goto out_nvme_fail;
+
+ return 0;
+
+out_admin_fail:
+ kobject_put(&td->pwd_admin->kobj);
+ td->pwd_admin = NULL;
+out_power_fail:
+ kobject_put(&td->pwd_power->kobj);
+ td->pwd_power = NULL;
+out_system_fail:
+ kobject_put(&td->pwd_system->kobj);
+ td->pwd_system = NULL;
+out_hdd_fail:
+ kobject_put(&td->pwd_hdd->kobj);
+ td->pwd_hdd = NULL;
+out_nvme_fail:
+ kobject_put(&td->pwd_nvme->kobj);
+ td->pwd_nvme = NULL;
+ return ret;
+}
+
+static int tlmi_create_auth(struct think_lmi *td,
+ const char *pwd_role,
+ struct tlmi_pwd_setting **setting)
+{
+ struct tlmi_pwd_setting *new_pwd;
+
+ new_pwd = kzalloc_obj(*new_pwd);
+ if (!new_pwd)
+ return -ENOMEM;
+
+ new_pwd->role = pwd_role;
+ new_pwd->minlen = td->pwdcfg.core.min_length;
+ new_pwd->maxlen = td->pwdcfg.core.max_length;
+ new_pwd->index = 1;
+ new_pwd->level = TLMI_LEVEL_MASTER;
+ new_pwd->wdev = td->auth_wdev;
+
+ *setting = new_pwd;
+ return 0;
+}
+
+static int tlmi_auth_setup(struct think_lmi *td)
+{
+ struct tlmi_pwd_setting *admin __free(kfree) = NULL;
+ struct tlmi_pwd_setting *power __free(kfree) = NULL;
+ struct tlmi_pwd_setting *system __free(kfree) = NULL;
+ struct tlmi_pwd_setting *hdd __free(kfree) = NULL;
+ struct tlmi_pwd_setting *nvme __free(kfree) = NULL;
+ unsigned int index;
+ int ret;
+
+ if (!td)
+ return -EINVAL;
+
+ ret = tlmi_create_auth(td, "bios-admin", &admin);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "power-on", &power);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "system", &system);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "hdd", &hdd);
+ if (ret)
+ return ret;
+
+ ret = tlmi_create_auth(td, "nvme", &nvme);
+ if (ret)
+ return ret;
+
+ td->pwd_admin = no_free_ptr(admin);
+ td->pwd_power = no_free_ptr(power);
+ td->pwd_system = no_free_ptr(system);
+ td->pwd_hdd = no_free_ptr(hdd);
+ td->pwd_nvme = no_free_ptr(nvme);
+
+ if (td->pwdcfg.core.password_state & TLMI_SVP_PWD)
+ td->pwd_admin->pwd_enabled = true;
+
+ if (td->pwdcfg.core.password_state & TLMI_POP_PWD)
+ td->pwd_power->pwd_enabled = true;
+
+ if (td->pwdcfg.core.password_state & TLMI_SMP_PWD)
+ td->pwd_system->pwd_enabled = true;
+
+ if (td->pwdcfg.core.password_state & TLMI_SVC_PWD)
+ td->pwd_admin->cert_installed = true;
+ if (td->pwdcfg.core.password_state & TLMI_SMC_PWD)
+ td->pwd_system->cert_installed = true;
+
+ if (td->pwdcfg.ext.hdd_user_password ||
+ td->pwdcfg.ext.hdd_master_password) {
+ td->pwd_hdd->pwd_enabled = true;
+ if (td->pwdcfg.ext.hdd_master_password)
+ index = ffs(td->pwdcfg.ext.hdd_master_password);
+ else
+ index = ffs(td->pwdcfg.ext.hdd_user_password);
+ /* Sanitize result */
+ if (index > MAX_HDD_INDEX || !index) {
+ pr_info("tlmi-auth: Invalid HDD password index %u. Setting to %d\n",
+ index, MAX_HDD_INDEX);
+ index = MAX_HDD_INDEX;
+ }
+ td->pwd_hdd->index = index;
+ }
+
+ if (td->pwdcfg.ext.nvme_user_password ||
+ td->pwdcfg.ext.nvme_master_password) {
+ td->pwd_nvme->pwd_enabled = true;
+ if (td->pwdcfg.ext.nvme_master_password)
+ index = ffs(td->pwdcfg.ext.nvme_master_password);
+ else
+ index = ffs(td->pwdcfg.ext.nvme_user_password);
+ /* Sanitize result */
+ if (index > MAX_NVME_INDEX || !index) {
+ pr_info("tlmi-auth: Invalid NVME password index %d. Setting to %d\n",
+ index, MAX_NVME_INDEX);
+ index = MAX_NVME_INDEX;
+ }
+ td->pwd_nvme->index = index;
+ }
+
+ mutex_init(&td->tlmi_auth_lock);
+
+ return ret;
+}
+
+static int tlmi_auth_component_bind(struct device *auth_dev, struct device *config_dev,
+ void *d)
+{
+ struct think_lmi *td = d;
+ int ret;
+
+ td->auth_wdev = to_wmi_device(auth_dev);
+ dev_set_drvdata(&td->auth_wdev->dev, td);
+
+ ret = tlmi_auth_setup(td);
+ if (ret)
+ return ret;
+
+ ret = tlmi_auth_sysfs_init(td);
+ if (ret)
+ tlmi_auth_sysfs_release(td);
+ return ret;
+}
+
+static void tlmi_auth_component_unbind(struct device *auth_dev, struct device *cfg_dev, void *d)
+{
+ struct think_lmi *td = d;
+
+ tlmi_auth_sysfs_release(td);
+}
+
+static const struct component_ops tlmi_auth_component_ops = {
+ .bind = tlmi_auth_component_bind,
+ .unbind = tlmi_auth_component_unbind,
+};
+
+static int tlmi_auth_probe(struct wmi_device *wdev, const void *context)
+{
+ return component_add(&wdev->dev, &tlmi_auth_component_ops);
+}
+
+static void tlmi_auth_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_auth_component_ops);
+}
+
+static const struct wmi_device_id tlmi_auth_id_table[] = {
+ { TLMI_AUTHENTICATION_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_auth_driver = {
+ .driver = {
+ .name = "tlmi-auth",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_auth_id_table,
+ .probe = tlmi_auth_probe,
+ .remove = tlmi_auth_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_auth_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_auth_driver.driver);
+}
+
+void tlmi_auth_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_auth_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_auth_match_add, "TLMI-AUTH");
+
+module_wmi_driver(tlmi_auth_driver);
+
+MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
+MODULE_DEVICE_TABLE(wmi, tlmi_auth_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Authentication WMI Driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index bb9c5f720c24..702e6754fcb4 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -50,7 +50,7 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
{
char *new_setting __free(kfree) = NULL;
char *wmidata __free(kfree) = NULL;
- size_t namelen, valuelen;
+ size_t namelen, valuelen, siglen;
struct wmi_buffer wmibuf;
char *start;
int ix = 0;
@@ -64,10 +64,17 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
if (!new_setting)
return -ENOMEM;
+ guard(mutex)(&td->tlmi_auth_lock);
+
/* Calculate and alloc buffer for command string */
namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
- wmibuf.length = namelen + valuelen;
+ if (td->pwd_admin && td->pwd_admin->signature)
+ siglen = struct_size_t(struct wmi_string, chars,
+ strlen(td->pwd_admin->signature) + 1);
+ else
+ siglen = struct_size_t(struct wmi_string, chars, 1 + 1);
+ wmibuf.length = namelen + valuelen + siglen;
wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
wmibuf.data = wmidata;
if (!wmibuf.data)
@@ -83,6 +90,14 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
if (ix < 0)
return ix;
+ start += ix;
+ if (td->pwd_admin && td->pwd_admin->signature)
+ ix = tlmi_populate_string_buffer(start, siglen,
+ td->pwd_admin->signature);
+ else
+ ix = tlmi_populate_string_buffer(start, siglen, "\0");
+ if (ix < 0)
+ return ix;
return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
}
@@ -209,8 +224,10 @@ static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *
const char *buf, size_t count)
{
struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
+ struct tlmi_pwd_setting *pwd_admin = td->pwd_admin;
char *wmidata __free(kfree) = NULL;
struct wmi_buffer wmibuf;
+ size_t siglen;
int ret = 0;
/* save command triggered by writing 'save' */
@@ -224,13 +241,30 @@ static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *
if (!td->save_required)
return -ENOENT;
- wmibuf.length = struct_size_t(struct wmi_string, chars, 1 + 1);
+ guard(mutex)(&td->tlmi_auth_lock);
+
+ /* Authorisation (if needed) is done just before save */
+ ret = tlmi_auth_authenticate_user(td);
+ /* Ignore most errors. We might be in deployment mode */
+ if (ret == -ENOMEM)
+ return ret;
+
+ if (td->pwd_admin && td->pwd_admin->save_signature)
+ siglen = struct_size_t(struct wmi_string, chars,
+ strlen(td->pwd_admin->save_signature) + 1);
+ else
+ siglen = struct_size_t(struct wmi_string, chars, 1 + 1);
+ wmibuf.length = siglen;
wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
wmibuf.data = wmidata;
if (!wmibuf.data)
return -ENOMEM;
- ret = tlmi_populate_string_buffer(wmibuf.data, 1, "\0");
+ if (pwd_admin && pwd_admin->save_signature)
+ ret = tlmi_populate_string_buffer(wmibuf.data, wmibuf.length,
+ pwd_admin->save_signature);
+ else
+ ret = tlmi_populate_string_buffer(wmibuf.data, siglen, "\0");
if (ret < 0)
return ret;
@@ -359,16 +393,18 @@ static const struct component_master_ops aggregate_ops = {
static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
{
struct component_match *match = NULL;
- guid_t tlmi_attr_guid, tlmi_authdata_guid;
+ guid_t tlmi_attr_guid, tlmi_authdata_guid, tlmi_auth_guid;
struct think_lmi *td;
int ret;
guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
+ guid_parse(TLMI_AUTHENTICATION_GUID, &tlmi_auth_guid);
/* At minimum need to support BIOS and authentication settings */
if (!wmidev_exists(&tlmi_attr_guid) ||
- !wmidev_exists(&tlmi_authdata_guid))
+ !wmidev_exists(&tlmi_authdata_guid) ||
+ !wmidev_exists(&tlmi_auth_guid))
return -EOPNOTSUPP;
td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
@@ -387,6 +423,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
/* Register the other components */
tlmi_attr_match_add(&wdev->dev, &match);
tlmi_authdata_match_add(&wdev->dev, &match);
+ tlmi_auth_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -424,6 +461,7 @@ module_wmi_driver(tlmi_config_driver);
MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
+MODULE_IMPORT_NS("TLMI-AUTH");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (8 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support Mark Pearson
` (3 subsequent siblings)
13 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
This commit adds a tlmi-platform WMI driver that reads platform settings
from the platform GUID, and extends tlmi-config to expose them in sysfs
and to write them using a new SET_PLATFORM_ID method.
Platform settings behave the same as regular BIOS settings (tlmi-attr)
but are for less commonly used settings and may not have a matching
entry in the BIOS menu.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 1 +
drivers/platform/x86/lenovo/think-lmi.h | 18 ++
drivers/platform/x86/lenovo/tlmi-config.c | 141 +++++++++++++
drivers/platform/x86/lenovo/tlmi-platform.c | 212 ++++++++++++++++++++
4 files changed, 372 insertions(+)
create mode 100644 drivers/platform/x86/lenovo/tlmi-platform.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index 6434e77f4ed3..f5618078224b 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -6,6 +6,7 @@
obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o tlmi-auth.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-platform.o
obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 6ab9a7e6fabf..620dbdb5b768 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -15,6 +15,7 @@
#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
#define TLMI_AUTHENTICATION_GUID "5cb5f556-30ce-40d3-a135-7ca0648a5a52"
#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
+#define TLMI_PLATFORM_GUID "FC1678AB-DD14-432A-BBFA-621DF8D5AE51"
/* Possible error values */
struct tlmi_err_codes {
@@ -127,6 +128,19 @@ struct tlmi_attr_setting {
bool read_only;
};
+/* Platform setting details */
+struct tlmi_platform_setting {
+ struct kobject kobj;
+ struct wmi_device *wdev;
+ int index;
+ char *name;
+ char *display_name;
+ char *possible_values;
+ char *current_value;
+ bool on_reboot;
+ struct list_head node;
+};
+
struct think_lmi {
struct wmi_device *wmi_device;
@@ -142,8 +156,10 @@ struct think_lmi {
bool save_required;
bool reboot_required;
bool thinkcenter_mode;
+ bool platform_settings_support;
struct list_head settings;
+ struct list_head platform_settings;
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
@@ -167,6 +183,8 @@ void tlmi_attr_match_add(struct device *master, struct component_match **matchpt
void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
void tlmi_auth_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_platform_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_platform_release_setting(struct tlmi_platform_setting *setting);
int tlmi_auth_authenticate_user(struct think_lmi *td);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 702e6754fcb4..7670107942d8 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -29,6 +29,7 @@
/* Method IDS for configuration GUID */
#define SET_ID 1
#define SAVE_ID 2
+#define SET_PLATFORM_ID 7
static DEFINE_MUTEX(tlmi_config_lock);
@@ -102,6 +103,122 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
}
+/* ---- Platform settings sysfs ---- */
+static inline struct tlmi_platform_setting *to_tlmi_platform_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_platform_setting, kobj);
+}
+
+static ssize_t platform_display_name_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->display_name);
+}
+
+static ssize_t platform_current_value_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ guard(mutex)(&tlmi_config_lock);
+
+ if (!setting->current_value)
+ return sysfs_emit(buf, "unknown\n");
+ return sysfs_emit(buf, "%s\n", setting->current_value);
+}
+
+static ssize_t platform_possible_values_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->possible_values);
+}
+
+static ssize_t platform_type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return common_type_show(setting->possible_values, buf);
+}
+
+static ssize_t platform_onreboot_show(struct kobject *kobj, struct kobj_attribute *p,
+ char *buf)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ return sysfs_emit(buf, "%d\n", setting->on_reboot);
+}
+
+static ssize_t platform_current_value_store(struct kobject *kobj,
+ struct kobj_attribute *p,
+ const char *buf, size_t count)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int ret;
+
+ guard(mutex)(&tlmi_config_lock);
+
+ ret = common_current_value_store(setting->name, buf, SET_PLATFORM_ID, td);
+ if (!ret) {
+ char *s;
+
+ td->save_required = true;
+ /* Update setting so read back shows correctly */
+ s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ kfree(setting->current_value);
+ /* if kstrdup fails, we'll handle it in the show */
+ setting->current_value = s;
+ return count;
+ }
+ return ret;
+}
+
+static struct kobj_attribute platform_display_name = __ATTR(display_name, 0444,
+ platform_display_name_show, NULL);
+
+static struct kobj_attribute platform_possible_values = __ATTR(possible_values, 0444,
+ platform_possible_values_show,
+ NULL);
+
+static struct kobj_attribute platform_current_val = __ATTR(current_value, 0600,
+ platform_current_value_show,
+ platform_current_value_store);
+static struct kobj_attribute platform_type = __ATTR(type, 0444, platform_type_show, NULL);
+static struct kobj_attribute platform_onreboot = __ATTR(onreboot, 0444, platform_onreboot_show,
+ NULL);
+
+static struct attribute *tlmi_platform[] = {
+ &platform_display_name.attr,
+ &platform_current_val.attr,
+ &platform_possible_values.attr,
+ &platform_type.attr,
+ &platform_onreboot.attr,
+ NULL
+};
+
+static const struct attribute_group tlmi_platform_group = {
+ .attrs = tlmi_platform,
+};
+__ATTRIBUTE_GROUPS(tlmi_platform);
+
+static void tlmi_platform_setting_release(struct kobject *kobj)
+{
+ struct tlmi_platform_setting *setting = to_tlmi_platform_setting(kobj);
+
+ tlmi_platform_release_setting(setting);
+}
+
+static const struct kobj_type tlmi_platform_setting_ktype = {
+ .release = &tlmi_platform_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = tlmi_platform_groups,
+};
+
/* ---- Attribute sysfs ---- */
static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
{
@@ -324,6 +441,7 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
static int tlmi_config_sysfs_init(struct think_lmi *td)
{
struct tlmi_attr_setting *attr, *na;
+ struct tlmi_platform_setting *p, *np;
int ret;
/* Create sysfs entries */
@@ -348,6 +466,24 @@ static int tlmi_config_sysfs_init(struct think_lmi *td)
}
}
+ if (td->platform_settings_support) {
+ list_for_each_entry_safe(p, np, &td->platform_settings, node) {
+ /* check for duplicate or reserved values */
+ if (tlmi_validate_setting_name(td->attribute_kset,
+ p->name) < 0)
+ continue;
+
+ /* Build platform setting */
+ p->kobj.kset = td->attribute_kset;
+ ret = kobject_init_and_add(&p->kobj, &tlmi_platform_setting_ktype,
+ NULL, "%s", p->name);
+ if (ret) {
+ kobject_put(&p->kobj);
+ goto out;
+ }
+ }
+ }
+
ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
if (ret)
goto out;
@@ -394,12 +530,14 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
{
struct component_match *match = NULL;
guid_t tlmi_attr_guid, tlmi_authdata_guid, tlmi_auth_guid;
+ guid_t tlmi_platform_guid;
struct think_lmi *td;
int ret;
guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
guid_parse(TLMI_AUTHENTICATION_GUID, &tlmi_auth_guid);
+ guid_parse(TLMI_PLATFORM_GUID, &tlmi_platform_guid);
/* At minimum need to support BIOS and authentication settings */
if (!wmidev_exists(&tlmi_attr_guid) ||
@@ -424,6 +562,8 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
tlmi_attr_match_add(&wdev->dev, &match);
tlmi_authdata_match_add(&wdev->dev, &match);
tlmi_auth_match_add(&wdev->dev, &match);
+ if (wmidev_exists(&tlmi_platform_guid))
+ tlmi_platform_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -462,6 +602,7 @@ MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_IMPORT_NS("TLMI-AUTH");
+MODULE_IMPORT_NS("TLMI-PLATFORM");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
diff --git a/drivers/platform/x86/lenovo/tlmi-platform.c b/drivers/platform/x86/lenovo/tlmi-platform.c
new file mode 100644
index 000000000000..3f211a7e1c35
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-platform.c
@@ -0,0 +1,212 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo TLMI platform settings WMI interface driver.
+ *
+ * Read in the WMI platform settings and their properties.
+ * Platform settings behave identically to regular BIOS settings
+ * but are less commonly used and may not have a matching entry
+ * in the BIOS menu.
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ *
+ */
+
+#include <linux/acpi.h>
+#include <linux/cleanup.h>
+#include <linux/component.h>
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+#include <linux/kobject.h>
+#include <linux/limits.h>
+#include <linux/module.h>
+#include <linux/string_helpers.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+#define TLMI_PLATFORM_SETTINGS_COUNT 32
+#define PLATFORM_ENTRIES 5
+
+void tlmi_platform_release_setting(struct tlmi_platform_setting *setting)
+{
+ if (setting) {
+ list_del(&setting->node);
+ kfree(setting->name);
+ kfree(setting->display_name);
+ kfree(setting->possible_values);
+ kfree(setting->current_value);
+ kfree(setting);
+ }
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_platform_release_setting, "TLMI-PLATFORM");
+
+static int tlmi_platform_sanitize(const union acpi_object *obj, bool *valid)
+{
+ int i;
+
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < PLATFORM_ENTRIES)
+ return -EIO;
+
+ /* First four entries should all be strings */
+ for (i = 0; i < 4; i++) {
+ if (obj->package.elements[i].type != ACPI_TYPE_STRING)
+ return -EIO;
+ /* Check for empty string */
+ if (!obj->package.elements[i].string.pointer[0]) {
+ /* first entry means empty slot. Later is invalid data */
+ return i == 0 ? 0 : -EIO;
+ }
+ }
+ /* Remaining entry is an integer */
+ if (obj->package.elements[4].type != ACPI_TYPE_INTEGER)
+ return -EIO;
+
+ *valid = true;
+ return 0;
+}
+
+static int tlmi_platform_create_setting(int item, struct think_lmi *td,
+ struct wmi_device *wdev)
+{
+ struct tlmi_platform_setting *setting;
+ union acpi_object *obj __free(kfree) = NULL;
+ bool valid = false;
+ int ret;
+
+ obj = wmidev_block_query(wdev, item);
+ if (!obj)
+ return 0; /* ignore invalid entries */
+
+ /* Confirm we have a valid item */
+ ret = tlmi_platform_sanitize(obj, &valid);
+ if (!valid) {
+ if (ret)
+ pr_info("tlmi_platform: Incorrectly formatted platform entry %d\n", item);
+ return 0; /* ignore malformed entries */
+ }
+
+ char *name __free(kfree) = kstrdup(obj->package.elements[0].string.pointer, GFP_KERNEL);
+ if (!name)
+ return -ENOMEM;
+
+ char *current_value __free(kfree) = kstrdup(obj->package.elements[1].string.pointer,
+ GFP_KERNEL);
+ if (!current_value)
+ return -ENOMEM;
+
+ char *possible_values __free(kfree) = kstrdup(obj->package.elements[2].string.pointer,
+ GFP_KERNEL);
+ if (!possible_values)
+ return -ENOMEM;
+
+ char *display_name __free(kfree) = kstrdup(obj->package.elements[3].string.pointer,
+ GFP_KERNEL);
+ if (!display_name)
+ return -ENOMEM;
+
+ setting = kzalloc_obj(*setting);
+ if (!setting)
+ return -ENOMEM;
+
+ setting->index = item;
+ setting->name = no_free_ptr(name);
+ setting->current_value = no_free_ptr(current_value);
+ setting->possible_values = no_free_ptr(possible_values);
+ setting->display_name = no_free_ptr(display_name);
+ setting->on_reboot = obj->package.elements[4].integer.value ? true : false;
+ setting->wdev = td->config_wdev;
+
+ list_add(&setting->node, &td->platform_settings);
+
+ return 0;
+}
+
+static int tlmi_platform_component_bind(struct device *platform_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = to_wmi_device(platform_dev);
+ struct tlmi_platform_setting *p, *np;
+ struct think_lmi *td = d;
+ int i, ret = 0;
+
+ td->platform_settings_support = true;
+ INIT_LIST_HEAD(&td->platform_settings);
+
+ /* Probe for platform settings */
+ for (i = 0; i < TLMI_PLATFORM_SETTINGS_COUNT; ++i) {
+ ret = tlmi_platform_create_setting(i, td, wdev);
+ if (ret)
+ break;
+ }
+ if (ret) { /* Clean up after any failures */
+ list_for_each_entry_safe(p, np, &td->platform_settings, node)
+ tlmi_platform_release_setting(p);
+ }
+ return ret;
+}
+
+static void tlmi_platform_component_unbind(struct device *platform_dev, struct device *config_dev,
+ void *d)
+{
+ struct tlmi_platform_setting *p, *np;
+ struct think_lmi *td = d;
+
+ /* This should not be needed - but make sure settings list is clear */
+ list_for_each_entry_safe(p, np, &td->platform_settings, node)
+ tlmi_platform_release_setting(p);
+}
+
+static const struct component_ops tlmi_platform_component_ops = {
+ .bind = tlmi_platform_component_bind,
+ .unbind = tlmi_platform_component_unbind,
+};
+
+static int tlmi_platform_probe(struct wmi_device *wdev, const void *context)
+{
+ return component_add(&wdev->dev, &tlmi_platform_component_ops);
+}
+
+static void tlmi_platform_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_platform_component_ops);
+}
+
+static const struct wmi_device_id tlmi_platform_id_table[] = {
+ { TLMI_PLATFORM_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_platform_driver = {
+ .driver = {
+ .name = "tlmi-platform",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_platform_id_table,
+ .probe = tlmi_platform_probe,
+ .remove = tlmi_platform_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_platform_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_platform_driver.driver);
+}
+
+void tlmi_platform_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_platform_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_platform_match_add, "TLMI-PLATFORM");
+
+module_wmi_driver(tlmi_platform_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_platform_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Platform settings WMI Driver");
+MODULE_LICENSE("GPL");
+
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (9 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier Mark Pearson
` (2 subsequent siblings)
13 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add support for function attributes.
These are settings that take effect immediately. They do not require a save
and reboot.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/Makefile | 1 +
drivers/platform/x86/lenovo/think-lmi.h | 16 ++
drivers/platform/x86/lenovo/tlmi-config.c | 129 +++++++++++++
drivers/platform/x86/lenovo/tlmi-function.c | 196 ++++++++++++++++++++
4 files changed, 342 insertions(+)
create mode 100644 drivers/platform/x86/lenovo/tlmi-function.c
diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
index f5618078224b..dd6f873519c2 100644
--- a/drivers/platform/x86/lenovo/Makefile
+++ b/drivers/platform/x86/lenovo/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o tlmi-auth.o
obj-$(CONFIG_THINKPAD_LMI) += tlmi-platform.o
+obj-$(CONFIG_THINKPAD_LMI) += tlmi-function.o
obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
index 620dbdb5b768..49816678033c 100644
--- a/drivers/platform/x86/lenovo/think-lmi.h
+++ b/drivers/platform/x86/lenovo/think-lmi.h
@@ -16,6 +16,7 @@
#define TLMI_AUTHENTICATION_GUID "5cb5f556-30ce-40d3-a135-7ca0648a5a52"
#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
#define TLMI_PLATFORM_GUID "FC1678AB-DD14-432A-BBFA-621DF8D5AE51"
+#define TLMI_FUNCTION_GUID "B8FD1C30-EEC5-4037-87D2-CF513A92BB23"
/* Possible error values */
struct tlmi_err_codes {
@@ -141,6 +142,17 @@ struct tlmi_platform_setting {
struct list_head node;
};
+/* Function setting details */
+struct tlmi_function_setting {
+ struct kobject kobj;
+ struct wmi_device *wdev;
+ int index;
+ char *name;
+ char *possible_values;
+ char *current_value;
+ struct list_head node;
+};
+
struct think_lmi {
struct wmi_device *wmi_device;
@@ -157,9 +169,11 @@ struct think_lmi {
bool reboot_required;
bool thinkcenter_mode;
bool platform_settings_support;
+ bool function_settings_support;
struct list_head settings;
struct list_head platform_settings;
+ struct list_head function_settings;
struct device *class_dev;
struct kset *attribute_kset;
struct kset *authentication_kset;
@@ -185,6 +199,8 @@ void tlmi_authdata_match_add(struct device *master, struct component_match **mat
void tlmi_auth_match_add(struct device *master, struct component_match **matchptr);
void tlmi_platform_match_add(struct device *master, struct component_match **matchptr);
void tlmi_platform_release_setting(struct tlmi_platform_setting *setting);
+void tlmi_function_match_add(struct device *master, struct component_match **matchptr);
+void tlmi_function_release_setting(struct tlmi_function_setting *setting);
int tlmi_auth_authenticate_user(struct think_lmi *td);
#endif /* !_THINK_LMI_H_ */
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 7670107942d8..76cf86ee4907 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -30,6 +30,7 @@
#define SET_ID 1
#define SAVE_ID 2
#define SET_PLATFORM_ID 7
+#define SET_FUNCTION_ID 8
static DEFINE_MUTEX(tlmi_config_lock);
@@ -103,6 +104,110 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
}
+/* ---- Function settings sysfs ---- */
+static inline struct tlmi_function_setting *to_tlmi_function_setting(struct kobject *kobj)
+{
+ return container_of(kobj, struct tlmi_function_setting, kobj);
+}
+
+static ssize_t function_display_name_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->name);
+}
+
+static ssize_t function_current_value_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ guard(mutex)(&tlmi_config_lock);
+
+ if (!setting->current_value)
+ return sysfs_emit(buf, "unknown\n");
+ return sysfs_emit(buf, "%s\n", setting->current_value);
+}
+
+static ssize_t function_possible_values_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ return sysfs_emit(buf, "%s\n", setting->possible_values);
+}
+
+static ssize_t function_type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ return common_type_show(setting->possible_values, buf);
+}
+
+static ssize_t function_current_value_store(struct kobject *kobj,
+ struct kobj_attribute *f,
+ const char *buf, size_t count)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+ struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
+ int ret;
+
+ guard(mutex)(&tlmi_config_lock);
+
+ ret = common_current_value_store(setting->name, buf, SET_FUNCTION_ID, td);
+ if (!ret) {
+ char *s;
+
+ /* Update setting so read back shows correctly */
+ s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
+ kfree(setting->current_value);
+ /* if kstrdup fails, we'll handle it in the show */
+ setting->current_value = s;
+ return count;
+ }
+ return ret;
+}
+
+static struct kobj_attribute function_display_name = __ATTR(display_name, 0444,
+ function_display_name_show, NULL);
+
+static struct kobj_attribute function_possible_values = __ATTR(possible_values, 0444,
+ function_possible_values_show,
+ NULL);
+
+static struct kobj_attribute function_current_val = __ATTR(current_value, 0600,
+ function_current_value_show,
+ function_current_value_store);
+static struct kobj_attribute function_type = __ATTR(type, 0444, function_type_show, NULL);
+
+static struct attribute *tlmi_function[] = {
+ &function_display_name.attr,
+ &function_current_val.attr,
+ &function_possible_values.attr,
+ &function_type.attr,
+ NULL
+};
+
+static const struct attribute_group tlmi_function_group = {
+ .attrs = tlmi_function,
+};
+__ATTRIBUTE_GROUPS(tlmi_function);
+
+static void tlmi_function_setting_release(struct kobject *kobj)
+{
+ struct tlmi_function_setting *setting = to_tlmi_function_setting(kobj);
+
+ tlmi_function_release_setting(setting);
+}
+
+static const struct kobj_type tlmi_function_setting_ktype = {
+ .release = &tlmi_function_setting_release,
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_groups = tlmi_function_groups,
+};
+
/* ---- Platform settings sysfs ---- */
static inline struct tlmi_platform_setting *to_tlmi_platform_setting(struct kobject *kobj)
{
@@ -442,6 +547,7 @@ static int tlmi_config_sysfs_init(struct think_lmi *td)
{
struct tlmi_attr_setting *attr, *na;
struct tlmi_platform_setting *p, *np;
+ struct tlmi_function_setting *f, *nf;
int ret;
/* Create sysfs entries */
@@ -484,6 +590,24 @@ static int tlmi_config_sysfs_init(struct think_lmi *td)
}
}
+ if (td->function_settings_support) {
+ list_for_each_entry_safe(f, nf, &td->function_settings, node) {
+ /* check for duplicate or reserved values */
+ if (tlmi_validate_setting_name(td->attribute_kset,
+ f->name) < 0)
+ continue;
+
+ /* Build function setting */
+ f->kobj.kset = td->attribute_kset;
+ ret = kobject_init_and_add(&f->kobj, &tlmi_function_setting_ktype,
+ NULL, "%s", f->name);
+ if (ret) {
+ kobject_put(&f->kobj);
+ goto out;
+ }
+ }
+ }
+
ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
if (ret)
goto out;
@@ -531,6 +655,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
struct component_match *match = NULL;
guid_t tlmi_attr_guid, tlmi_authdata_guid, tlmi_auth_guid;
guid_t tlmi_platform_guid;
+ guid_t tlmi_function_guid;
struct think_lmi *td;
int ret;
@@ -538,6 +663,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
guid_parse(TLMI_AUTHENTICATION_GUID, &tlmi_auth_guid);
guid_parse(TLMI_PLATFORM_GUID, &tlmi_platform_guid);
+ guid_parse(TLMI_FUNCTION_GUID, &tlmi_function_guid);
/* At minimum need to support BIOS and authentication settings */
if (!wmidev_exists(&tlmi_attr_guid) ||
@@ -564,6 +690,8 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
tlmi_auth_match_add(&wdev->dev, &match);
if (wmidev_exists(&tlmi_platform_guid))
tlmi_platform_match_add(&wdev->dev, &match);
+ if (wmidev_exists(&tlmi_function_guid))
+ tlmi_function_match_add(&wdev->dev, &match);
ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
if (ret)
@@ -603,6 +731,7 @@ MODULE_IMPORT_NS("TLMI-ATTR");
MODULE_IMPORT_NS("TLMI-AUTHDATA");
MODULE_IMPORT_NS("TLMI-AUTH");
MODULE_IMPORT_NS("TLMI-PLATFORM");
+MODULE_IMPORT_NS("TLMI-FUNCTION");
MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
MODULE_DESCRIPTION("TLMI Config WMI Driver");
diff --git a/drivers/platform/x86/lenovo/tlmi-function.c b/drivers/platform/x86/lenovo/tlmi-function.c
new file mode 100644
index 000000000000..e99d7ee62e88
--- /dev/null
+++ b/drivers/platform/x86/lenovo/tlmi-function.c
@@ -0,0 +1,196 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Lenovo TLMI function settings WMI interface driver.
+ *
+ * Read in the WMI function settings and their properties.
+ * Function settings are attributes that take effect immediately
+ *
+ * This driver supports the "Common WMI" approach implemented on
+ * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
+ */
+
+#include <linux/acpi.h>
+#include <linux/cleanup.h>
+#include <linux/component.h>
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+#include <linux/kobject.h>
+#include <linux/limits.h>
+#include <linux/module.h>
+#include <linux/string_helpers.h>
+#include <linux/types.h>
+#include <linux/wmi.h>
+#include "think-lmi.h"
+
+#define TLMI_FUNCTION_SETTINGS_COUNT 32
+#define FUNCTION_ENTRIES 3
+
+void tlmi_function_release_setting(struct tlmi_function_setting *setting)
+{
+ if (setting) {
+ list_del(&setting->node);
+ kfree(setting->name);
+ kfree(setting->possible_values);
+ kfree(setting->current_value);
+ kfree(setting);
+ }
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_function_release_setting, "TLMI-FUNCTION");
+
+static int tlmi_function_sanitize(const union acpi_object *obj, bool *valid)
+{
+ int i;
+
+ if (obj->type != ACPI_TYPE_PACKAGE)
+ return -EINVAL;
+
+ if (obj->package.count < FUNCTION_ENTRIES)
+ return -EIO;
+
+ /* All entries are strings */
+ for (i = 0; i < FUNCTION_ENTRIES; i++) {
+ if (obj->package.elements[i].type != ACPI_TYPE_STRING)
+ return -EIO;
+ if (!obj->package.elements[i].string.pointer[0]) {
+ /* first entry means empty slot. Later is invalid data */
+ return i == 0 ? 0 : -EIO;
+ }
+ }
+
+ *valid = true;
+ return 0;
+}
+
+static int tlmi_function_create_setting(int item, struct think_lmi *td,
+ struct wmi_device *wdev)
+{
+ struct tlmi_function_setting *setting;
+ union acpi_object *obj __free(kfree) = NULL;
+ bool valid = false;
+ int ret;
+
+ obj = wmidev_block_query(wdev, item);
+ if (!obj)
+ return 0; /* ignore invalid entries */
+
+ /* Confirm we have a valid item */
+ ret = tlmi_function_sanitize(obj, &valid);
+ if (!valid) {
+ if (ret)
+ pr_info("tlmi-function: Incorrectly formatted function entry %d\n", item);
+ return 0; /* ignore malformed entries */
+ }
+
+ char *name __free(kfree) = kstrdup(obj->package.elements[0].string.pointer, GFP_KERNEL);
+ if (!name)
+ return -ENOMEM;
+
+ char *current_value __free(kfree) = kstrdup(obj->package.elements[1].string.pointer,
+ GFP_KERNEL);
+ if (!current_value)
+ return -ENOMEM;
+
+ char *possible_values __free(kfree) = kstrdup(obj->package.elements[2].string.pointer,
+ GFP_KERNEL);
+ if (!possible_values)
+ return -ENOMEM;
+
+ setting = kzalloc_obj(*setting);
+ if (!setting)
+ return -ENOMEM;
+
+ setting->index = item;
+ setting->name = no_free_ptr(name);
+ setting->current_value = no_free_ptr(current_value);
+ setting->possible_values = no_free_ptr(possible_values);
+ setting->wdev = td->config_wdev;
+
+ list_add(&setting->node, &td->function_settings);
+ return 0;
+}
+
+static int tlmi_function_component_bind(struct device *function_dev, struct device *config_dev,
+ void *d)
+{
+ struct wmi_device *wdev = to_wmi_device(function_dev);
+ struct tlmi_function_setting *f, *nf;
+ struct think_lmi *td = d;
+ int i, ret = 0;
+
+ td->function_settings_support = true;
+ INIT_LIST_HEAD(&td->function_settings);
+
+ /* Probe for function settings */
+ for (i = 0; i < TLMI_FUNCTION_SETTINGS_COUNT; ++i) {
+ ret = tlmi_function_create_setting(i, td, wdev);
+ if (ret)
+ break;
+ }
+ if (ret) { /* Clean up after any failures */
+ list_for_each_entry_safe(f, nf, &td->function_settings, node)
+ tlmi_function_release_setting(f);
+ }
+ return ret;
+}
+
+static void tlmi_function_component_unbind(struct device *function_dev, struct device *config_dev,
+ void *d)
+{
+ struct tlmi_function_setting *f, *nf;
+ struct think_lmi *td = d;
+
+ /* This should not be needed - but make sure settings list is clear */
+ list_for_each_entry_safe(f, nf, &td->function_settings, node)
+ tlmi_function_release_setting(f);
+}
+
+static const struct component_ops tlmi_function_component_ops = {
+ .bind = tlmi_function_component_bind,
+ .unbind = tlmi_function_component_unbind,
+};
+
+static int tlmi_function_probe(struct wmi_device *wdev, const void *context)
+{
+ return component_add(&wdev->dev, &tlmi_function_component_ops);
+}
+
+static void tlmi_function_remove(struct wmi_device *wdev)
+{
+ component_del(&wdev->dev, &tlmi_function_component_ops);
+}
+
+static const struct wmi_device_id tlmi_function_id_table[] = {
+ { TLMI_FUNCTION_GUID, NULL },
+ {}
+};
+
+static struct wmi_driver tlmi_function_driver = {
+ .driver = {
+ .name = "tlmi-function",
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = tlmi_function_id_table,
+ .probe = tlmi_function_probe,
+ .remove = tlmi_function_remove,
+ .no_singleton = true,
+};
+
+static int tlmi_function_match(struct device *dev, void *type)
+{
+ return (dev->driver == &tlmi_function_driver.driver);
+}
+
+void tlmi_function_match_add(struct device *master, struct component_match **matchptr)
+{
+ component_match_add(master, matchptr, tlmi_function_match, NULL);
+}
+EXPORT_SYMBOL_NS_GPL(tlmi_function_match_add, "TLMI-FUNCTION");
+
+module_wmi_driver(tlmi_function_driver);
+
+MODULE_DEVICE_TABLE(wmi, tlmi_function_id_table);
+MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
+MODULE_DESCRIPTION("ThinkLMI Function settings WMI Driver");
+MODULE_LICENSE("GPL");
+
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (10 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections Mark Pearson
2026-12-04 13:19 ` [PATCH 00/13] New Lenovo common WMI driver - tlmi Rong Zhang
13 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Add the ability to see whether attributes are regular, platform or
function attributes.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/tlmi-config.c | 26 +++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
index 76cf86ee4907..eb7e8b54271c 100644
--- a/drivers/platform/x86/lenovo/tlmi-config.c
+++ b/drivers/platform/x86/lenovo/tlmi-config.c
@@ -146,6 +146,12 @@ static ssize_t function_type_show(struct kobject *kobj, struct kobj_attribute *a
return common_type_show(setting->possible_values, buf);
}
+static ssize_t function_method_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ return sysfs_emit(buf, "function\n");
+}
+
static ssize_t function_current_value_store(struct kobject *kobj,
struct kobj_attribute *f,
const char *buf, size_t count)
@@ -181,12 +187,15 @@ static struct kobj_attribute function_current_val = __ATTR(current_value, 0600,
function_current_value_show,
function_current_value_store);
static struct kobj_attribute function_type = __ATTR(type, 0444, function_type_show, NULL);
+static struct kobj_attribute function_method = __ATTR(method, 0444,
+ function_method_show, NULL);
static struct attribute *tlmi_function[] = {
&function_display_name.attr,
&function_current_val.attr,
&function_possible_values.attr,
&function_type.attr,
+ &function_method.attr,
NULL
};
@@ -258,6 +267,12 @@ static ssize_t platform_onreboot_show(struct kobject *kobj, struct kobj_attribut
return sysfs_emit(buf, "%d\n", setting->on_reboot);
}
+static ssize_t platform_method_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ return sysfs_emit(buf, "platform\n");
+}
+
static ssize_t platform_current_value_store(struct kobject *kobj,
struct kobj_attribute *p,
const char *buf, size_t count)
@@ -296,6 +311,8 @@ static struct kobj_attribute platform_current_val = __ATTR(current_value, 0600,
static struct kobj_attribute platform_type = __ATTR(type, 0444, platform_type_show, NULL);
static struct kobj_attribute platform_onreboot = __ATTR(onreboot, 0444, platform_onreboot_show,
NULL);
+static struct kobj_attribute platform_method = __ATTR(method, 0444,
+ platform_method_show, NULL);
static struct attribute *tlmi_platform[] = {
&platform_display_name.attr,
@@ -303,6 +320,7 @@ static struct attribute *tlmi_platform[] = {
&platform_possible_values.attr,
&platform_type.attr,
&platform_onreboot.attr,
+ &platform_method.attr,
NULL
};
@@ -364,6 +382,12 @@ static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
return common_type_show(setting->possible_values, buf);
}
+static ssize_t method_show(struct kobject *kobj, struct kobj_attribute *f,
+ char *buf)
+{
+ return sysfs_emit(buf, "setting\n");
+}
+
static ssize_t current_value_store(struct kobject *kobj,
struct kobj_attribute *attr,
const char *buf, size_t count)
@@ -396,12 +420,14 @@ 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 kobj_attribute attr_method = __ATTR_RO(method);
static struct attribute *tlmi_attrs[] = {
&attr_display_name.attr,
&attr_current_val.attr,
&attr_possible_values.attr,
&attr_type.attr,
+ &attr_method.attr,
NULL
};
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (11 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier Mark Pearson
@ 2026-12-04 2:20 ` Mark Pearson
2026-12-04 13:19 ` [PATCH 00/13] New Lenovo common WMI driver - tlmi Rong Zhang
13 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 2:20 UTC (permalink / raw)
To: mpearson-lenovo
Cc: derekjohn.clark, i, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
With the introduction of the tlmi driver:
- There is a new setting for determining regular, platform or function
settings
- Some of the settings used for the older think-lmi driver are no longer
relevant
Add the differences to the documentations.
Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
.../testing/sysfs-class-firmware-attributes | 39 +++++++++++++++++--
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-class-firmware-attributes b/Documentation/ABI/testing/sysfs-class-firmware-attributes
index 40e35fe97a7d..387698234587 100644
--- a/Documentation/ABI/testing/sysfs-class-firmware-attributes
+++ b/Documentation/ABI/testing/sysfs-class-firmware-attributes
@@ -146,6 +146,21 @@ Description:
the list in a different order to current_value alters
the priority order for the particular attribute.
+ Lenovo specific class extensions
+ --------------------------------
+
+ On Lenovo systems, using the tlmi driver, the following additional attributes are
+ available:
+
+ method:
+ A file that can be read to determine if the attribute is a standard
+ BIOS setting, a platform setting or a functional setting.
+ Platform settings are less standard and are not available in the BIOS
+ menu, but behave the same as regular settings (save/reboot required to activate)
+ Function settings are effective immediately.
+
+ Known methods: setting, platform, function
+
What: /sys/class/firmware-attributes/*/authentication/
Date: February 2021
KernelVersion: 5.11
@@ -245,12 +260,14 @@ Description:
lenovo_encoding:
The encoding method that is used. This can be either "ascii"
- or "scancode". Default is set to "ascii"
+ or "scancode". Default is set to "ascii".
+ This method is not used in the newer tlmi driver
lenovo_kbdlang:
The keyboard language method that is used. This is generally a
two char code (e.g. "us", "fr", "gr") and may vary per platform.
- Default is set to "us"
+ Default is set to "us".
+ This method is not used in the newer tlmi driver
level:
Available for HDD and NVMe authentication to set 'user' or 'master'
@@ -259,7 +276,8 @@ Description:
unlock the drive at boot. If both master and user passwords are set
then either can be used. If a master password is set a user password
is required.
- This attribute defaults to 'user' level
+ This attribute defaults to 'user' level for think-lmi.
+ This attribute defaults to 'master' level for the newer tlmi driver.
index:
Used with HDD and NVME authentication to set the drive index
@@ -389,6 +407,7 @@ Date: August 2023
KernelVersion: 6.6
Contact: Mark Pearson <mpearson-lenovo@squebb.ca>
Description:
+ For the older think-lmi driver:
On Lenovo platforms there is a limitation in the number of times an attribute can be
saved. This is an architectural limitation and it limits the number of attributes
that can be modified to 48.
@@ -417,6 +436,18 @@ Description:
# echo save > /sys/class/firmware-attributes/thinklmi/attributes/save_settings
+ For the newer tlmi driver:
+ A save is needed after any changes are made to either 'setting' or 'platform' attributes.
+ This requires writing 'save', the same way as the 'bulk' mode in the think-lmi driver.
+ A save is not needed with 'function' attributes.
+ See 'method' above for more details on the different types of attribute.
+
+ Read the attribute to confirm if a save is needed. 1 means required, 0 means not required.
+ E.g::
+
+ # cat /sys/class/firmware-attributes/tlmi/attributes/save_settings
+ 1
+
What: /sys/class/firmware-attributes/*/attributes/debug_cmd
Date: July 2021
KernelVersion: 5.14
@@ -427,7 +458,7 @@ Description:
use it to enable extra debug attributes or BIOS features for testing purposes.
Note that any changes to this attribute requires a reboot for changes to take effect.
-
+ This attribute is only present on the think-lmi driver.
HP specific class extensions - Secure Platform Manager (SPM)
--------------------------------
--
2.43.0
^ permalink raw reply related [flat|nested] 44+ messages in thread
* Re: [PATCH 00/13] New Lenovo common WMI driver - tlmi
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
` (12 preceding siblings ...)
2026-12-04 2:20 ` [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections Mark Pearson
@ 2026-12-04 13:19 ` Rong Zhang
2026-12-04 14:42 ` Mark Pearson
13 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:19 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
Thanks for working on this.
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> This series introduces support for a new Lenovo 'common WMI'
> implementation.
>
> The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
> WMI methods for interfacing with the BIOS settings. This implementation
> will be available for 2027 platforms and is intended to be common across
> the business units.
>
> The new driver is called tlmi and can run alongside the existing
> think-lmi driver. Initially the BIOS's will support both interfaces.
>
> The first 5 patches in the series update the existing think-lmi driver
> with changes that means it can share structures with the new tlmi
> driver. They also introduce fixes for issues I found when implementing
> tlmi.
> The remaining patches introduce the new tlmi functionality. I've tried
> to break them up into reviewable chunks.
>
> The tlmi driver for now offers the same functionality as think-lmi -
> with support for modifying BIOS settings and authentication options.
> It also introduces 'platform' settings and 'function' settings.
>
> During implementation I needed some functionality to be common between
> modules. Using the wmi-helpers module seemed a good place for this, but
> please let me know if it's not suitable.
>
> Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
> Thinkstation P5 G2.
>
> Much of this implementation builds on the recommendations from Armin,
> Derek and Ilpo from the original RFC. Many thanks for the guidance.
>
> Mark Pearson (13):
> platform/x86: lenovo: think-lmi: Convert name arrays to pointers
> platform/x86: lenovo: think-lmi: Clean up attributes if not added to
> list
> platform/x86: lenovo: think-lmi: cache current value at init
> platform/x86: lenovo: think-lmi: store attributes as linked list
> platform/x86: lenovo: tlmi: New tlmi driver for common WMI
> implementation
> platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
> platform/x86: lenovo: tlmi: Retrieve auth information
> platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
> platform/x86: lenovo: tlmi: Add authentication sysfs entries
> platform/x86: lenovo: tlmi: Add platform attribute support
> platform/x86: lenovo: tlmi: Add function attributes support
> platform/x86: lenovo: tlmi: Add method identifier
> docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
Sashiko found quite a lot of issues in the series, so I am not going to
seriously review this series yet, in case you'd need to change the design
a lot in the next revision.
That being said, I will glance at each patch and see if I have some
additional suggestions on the design.
Thanks,
Rong
>
> .../testing/sysfs-class-firmware-attributes | 39 +-
> drivers/platform/x86/lenovo/Kconfig | 1 +
> drivers/platform/x86/lenovo/Makefile | 3 +
> drivers/platform/x86/lenovo/think-lmi.c | 193 ++--
> drivers/platform/x86/lenovo/think-lmi.h | 72 +-
> drivers/platform/x86/lenovo/tlmi-attr.c | 214 ++++
> drivers/platform/x86/lenovo/tlmi-auth.c | 958 ++++++++++++++++++
> drivers/platform/x86/lenovo/tlmi-authdata.c | 135 +++
> drivers/platform/x86/lenovo/tlmi-config.c | 764 ++++++++++++++
> drivers/platform/x86/lenovo/tlmi-function.c | 196 ++++
> drivers/platform/x86/lenovo/tlmi-platform.c | 212 ++++
> drivers/platform/x86/lenovo/wmi-helpers.c | 65 +-
> drivers/platform/x86/lenovo/wmi-helpers.h | 5 +
> 13 files changed, 2788 insertions(+), 69 deletions(-)
> create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-auth.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-function.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-platform.c
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list
2026-12-04 2:20 ` [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list Mark Pearson
@ 2026-12-04 13:20 ` Rong Zhang
2026-12-04 15:09 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:20 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> If we fail to add an attribute to the attribute_kset list then it will not
> get freed during the subsequent kobject_put.
> Make sure to free resources before going ahead with the rest of the
> cleanup.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/think-lmi.c | 87 ++++++++++++++++++-------
> 1 file changed, 65 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
> index c060a0a360ca..63ea212b4bda 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.c
> +++ b/drivers/platform/x86/lenovo/think-lmi.c
> @@ -1444,6 +1444,16 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr
> static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
>
> /* ---- Initialisation --------------------------------------------------------- */
> +/* Utility function to free record when not in the attribute_kset list */
> +static void tlmi_free_attr_record(int i)
> +{
> + kfree(tlmi_priv.setting[i]->name);
> + kfree(tlmi_priv.setting[i]->display_name);
> + kfree(tlmi_priv.setting[i]->possible_values);
> + kfree(tlmi_priv.setting[i]);
> + tlmi_priv.setting[i] = NULL;
> +}
> +
> static void tlmi_release_attr(void)
> {
> struct kobject *pos, *n;
> @@ -1461,8 +1471,10 @@ static void tlmi_release_attr(void)
> kset_unregister(tlmi_priv.attribute_kset);
>
> /* Free up any saved signatures */
> - kfree(tlmi_priv.pwd_admin->signature);
> - kfree(tlmi_priv.pwd_admin->save_signature);
> + if (tlmi_priv.pwd_admin) {
> + kfree(tlmi_priv.pwd_admin->signature);
> + kfree(tlmi_priv.pwd_admin->save_signature);
> + }
> if (tlmi_priv.pwd_system) {
> kfree(tlmi_priv.pwd_system->signature);
> kfree(tlmi_priv.pwd_system->save_signature);
> @@ -1495,8 +1507,9 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
>
> static int tlmi_sysfs_init(void)
> {
> - int i, ret;
> + int i, ret = 0, auth_ret = 0;
>
> + guard(mutex)(&tlmi_mutex);
It'd better to add a comment explaining what's serialized during
initialization (gating attribute access?).
> tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
> NULL, "%s", "thinklmi");
> if (IS_ERR(tlmi_priv.class_dev)) {
> @@ -1524,14 +1537,15 @@ static int tlmi_sysfs_init(void)
> if (!tlmi_priv.setting[i])
> continue;
>
> + if (ret) { /* We had a critical failure. Just clean up */
> + tlmi_free_attr_record(i);
> + continue;
> + }
> +
> /* check for duplicate or reserved values */
> if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
> tlmi_priv.setting[i]->display_name) < 0) {
> - kfree(tlmi_priv.setting[i]->name);
> - kfree(tlmi_priv.setting[i]->display_name);
> - kfree(tlmi_priv.setting[i]->possible_values);
> - kfree(tlmi_priv.setting[i]);
> - tlmi_priv.setting[i] = NULL;
> + tlmi_free_attr_record(i);
> continue;
> }
>
> @@ -1539,9 +1553,14 @@ static int tlmi_sysfs_init(void)
> tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
> ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
> NULL, "%s", tlmi_priv.setting[i]->display_name);
> - if (ret)
> - goto fail_create_attr;
> + if (ret) {
> + kobject_put(&tlmi_priv.setting[i]->kobj);
> + continue; /* use loop to clear remaining items */
> + }
> }
> + /* Check if we had an error during the attribute creations */
> + if (ret)
> + goto fail_create_attr;
>
> ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
> if (ret)
> @@ -1561,39 +1580,63 @@ static int tlmi_sysfs_init(void)
> tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
> ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
> NULL, "%s", "Admin");
> - if (ret)
> - goto fail_create_attr;
> -
> + if (ret) {
> + kobject_put(&tlmi_priv.pwd_admin->kobj);
> + tlmi_priv.pwd_admin = NULL;
> + auth_ret = ret;
> + }
Let's factor out a helper function like:
kobj.kset = ...
ret = kobject_init_and_add();
if (ret) {
...
}
> tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
> ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
> NULL, "%s", "Power-on");
> - if (ret)
> - goto fail_create_attr;
> + if (ret) {
> + kobject_put(&tlmi_priv.pwd_power->kobj);
> + tlmi_priv.pwd_power = NULL;
> + auth_ret = ret;
> + }
>
> if (tlmi_priv.opcode_support) {
> tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
> ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
> NULL, "%s", "System");
> - if (ret)
> - goto fail_create_attr;
> + if (ret) {
> + kobject_put(&tlmi_priv.pwd_system->kobj);
> + tlmi_priv.pwd_system = NULL;
> + auth_ret = ret;
> + }
>
> tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
> ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
> NULL, "%s", "HDD");
> - if (ret)
> - goto fail_create_attr;
> + if (ret) {
> + kobject_put(&tlmi_priv.pwd_hdd->kobj);
> + tlmi_priv.pwd_hdd = NULL;
> + auth_ret = ret;
> + }
>
> tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
> ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
> NULL, "%s", "NVMe");
> - if (ret)
> - goto fail_create_attr;
> + if (ret) {
> + kobject_put(&tlmi_priv.pwd_nvme->kobj);
> + tlmi_priv.pwd_nvme = NULL;
> + auth_ret = ret;
> + }
> + }
> + /* If one of the auth entries fail, we'd best go and clean up */
> + if (auth_ret) {
> + ret = auth_ret;
> + goto fail_create_attr;
Why would you need to defer the bail-out path?
> }
> -
> return ret;
>
> fail_create_attr:
> + /* Release any kobject items */
> tlmi_release_attr();
tlmi_release_attr() calls kobject_put() without nullifying
tlmi_priv.pwd_*, so ...
> + kfree(tlmi_priv.pwd_admin);
> + kfree(tlmi_priv.pwd_power);
> + kfree(tlmi_priv.pwd_system);
> + kfree(tlmi_priv.pwd_hdd);
> + kfree(tlmi_priv.pwd_nvme);
a bunch of double free.
Thanks,
Rong
> fail_device_created:
> device_unregister(tlmi_priv.class_dev);
> fail_class_created:
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init
2026-12-04 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
@ 2026-12-04 13:28 ` Rong Zhang
2026-12-04 15:14 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:28 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> When we read in current BIOS setting at init, cache it then to avoid
> having to process it later, as it doesn't change.
>
> This does introduce a couple of changes in behaviour:
>
> - If the attribute value is changed we modify the cached value to show
> what was set. Previously this would have read back the value - which
> would have been wrong, so this should be an improvement.
>
> - Previously a malformed attribute (invalid name or value) would have
> been registered, whereas now it is skipped. It is better not to show
> invalid entries
>
> During code review it picked up that if attributes are cleared the
> setting pointer could be leaked with a driver re-probe.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/think-lmi.c | 67 ++++++++++++++++---------
> drivers/platform/x86/lenovo/think-lmi.h | 1 +
> 2 files changed, 43 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
> index 63ea212b4bda..6580b1401f01 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.c
> +++ b/drivers/platform/x86/lenovo/think-lmi.c
> @@ -1047,25 +1047,11 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
> 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);
> - char *item, *value;
> - int ret;
> -
> - ret = tlmi_setting(setting->wdev, setting->index, &item);
> - if (ret)
> - return ret;
>
> - /* validate and split from `item,value` -> `value` */
> - value = strpbrk(item, ",");
> - if (!value || value == item || !strlen(value + 1))
> - ret = -EINVAL;
> - else {
> - /* On Workstations remove the Options part after the value */
> - strreplace(value, ';', '\0');
> - ret = sysfs_emit(buf, "%s\n", value + 1);
> - }
> - kfree(item);
> -
> - return ret;
> + guard(mutex)(&tlmi_mutex);
> + if (!setting->current_value)
> + return sysfs_emit(buf, "unknown\n");
> + return sysfs_emit(buf, "%s\n", setting->current_value);
> }
>
> static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
> @@ -1204,8 +1190,16 @@ static ssize_t current_value_store(struct kobject *kobj,
> ret = tlmi_save_bios_settings("");
> }
> }
> - if (!ret && !tlmi_priv.pending_changes) {
> - tlmi_priv.pending_changes = true;
> + if (!ret) {
> + char *s;
> +
> + if (!tlmi_priv.pending_changes)
Is the `if' doing anything? Overriding true with true is idempotent.
> + tlmi_priv.pending_changes = true;
> + /* Update setting so read back shows correctly */
> + s = kstrdup(new_setting, GFP_KERNEL);
> + kfree(setting->current_value);
> + /* if kstrdup fails, show will handle null value */
> + setting->current_value = s;
Since new_setting is going to be freed later, i.e., no one else will use
it, why not assign it to setting->current_value directly?
Hint: adopt __free() and guard(), and then no_free_ptr() is here to help
you.
> /* let userland know it may need to check reboot pending again */
> kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
What's the intent here? Notify on every successful write or only on
tlmi_priv.pending_changes flip?
Thanks,
Rong
> }
> @@ -1258,6 +1252,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
> kfree(setting->name);
> kfree(setting->display_name);
> kfree(setting->possible_values);
> + kfree(setting->current_value);
> kfree(setting);
> }
>
> @@ -1450,6 +1445,7 @@ static void tlmi_free_attr_record(int i)
> kfree(tlmi_priv.setting[i]->name);
> kfree(tlmi_priv.setting[i]->display_name);
> kfree(tlmi_priv.setting[i]->possible_values);
> + kfree(tlmi_priv.setting[i]->current_value);
> kfree(tlmi_priv.setting[i]);
> tlmi_priv.setting[i] = NULL;
> }
> @@ -1469,6 +1465,8 @@ static void tlmi_release_attr(void)
> kobject_put(pos);
>
> kset_unregister(tlmi_priv.attribute_kset);
> + /* Clear up settings array */
> + memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
>
> /* Free up any saved signatures */
> if (tlmi_priv.pwd_admin) {
> @@ -1707,9 +1705,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
> */
> for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
> struct tlmi_attr_setting *setting;
> - char *item = NULL;
> + char *item = NULL, *value;
>
> - tlmi_priv.setting[i] = NULL;
> ret = tlmi_setting(wdev, i, &item);
> if (ret)
> break;
> @@ -1720,9 +1717,6 @@ static int tlmi_analyze(struct wmi_device *wdev)
> continue;
> }
>
> - /* Remove the value part */
> - strreplace(item, ',', '\0');
> -
> /* Create a setting entry */
> setting = kzalloc_obj(*setting);
> if (!setting) {
> @@ -1733,10 +1727,31 @@ static int tlmi_analyze(struct wmi_device *wdev)
> setting->wdev = wdev;
> setting->index = i;
>
> + /* validate and split from `item,value` -> `value` */
> + value = strpbrk(item, ",");
> + if (!value || value == item || !strlen(value + 1)) {
> + pr_info("Incorrectly formed attribute %s\n", item);
> + kfree(item);
> + kfree(setting);
> + continue;
> + }
> +
> + /* On Workstations remove the Options part after the value */
> + strreplace(value, ';', '\0');
> + setting->current_value = kstrdup(value + 1, GFP_KERNEL);
> + if (!setting->current_value) {
> + ret = -ENOMEM;
> + kfree(item);
> + kfree(setting);
> + goto fail_clear_attr;
> + }
> +
> + strreplace(item, ',', '\0'); /* Remove the value part */
> setting->name = kstrdup(item, GFP_KERNEL);
> if (!setting->name) {
> ret = -ENOMEM;
> kfree(item);
> + kfree(setting->current_value);
> kfree(setting);
> goto fail_clear_attr;
> }
> @@ -1748,6 +1763,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> ret = -ENOMEM;
> kfree(item);
> kfree(setting->name);
> + kfree(setting->current_value);
> kfree(setting);
> goto fail_clear_attr;
> }
> @@ -1879,6 +1895,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> kfree(tlmi_priv.setting[i]->name);
> kfree(tlmi_priv.setting[i]->display_name);
> kfree(tlmi_priv.setting[i]->possible_values);
> + kfree(tlmi_priv.setting[i]->current_value);
> kfree(tlmi_priv.setting[i]);
> }
> }
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index 8ced29253f40..54d5c3b8233e 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -104,6 +104,7 @@ struct tlmi_attr_setting {
> char *name;
> char *display_name;
> char *possible_values;
> + char *current_value;
> };
>
> struct think_lmi {
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list
2026-12-04 2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
@ 2026-12-04 13:30 ` Rong Zhang
2026-12-04 15:21 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:30 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Use a linked list for storing attributes instead of a fixed array.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/think-lmi.c | 55 +++++++++++--------------
> drivers/platform/x86/lenovo/think-lmi.h | 3 +-
> 2 files changed, 25 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
> index 6580b1401f01..7a24985882ea 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.c
> +++ b/drivers/platform/x86/lenovo/think-lmi.c
> @@ -1249,6 +1249,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
> {
> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>
> + list_del(&setting->node);
I guess you need a scoped_guard() or lockdep_assert_held() for it, but is
it useful to keep the list in the first place? It seems that no one
touches it once probe finishes.
Thanks,
Rong
> kfree(setting->name);
> kfree(setting->display_name);
> kfree(setting->possible_values);
> @@ -1440,14 +1441,14 @@ static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
>
> /* ---- Initialisation --------------------------------------------------------- */
> /* Utility function to free record when not in the attribute_kset list */
> -static void tlmi_free_attr_record(int i)
> +static void tlmi_free_attr_record(struct tlmi_attr_setting *attr)
> {
> - kfree(tlmi_priv.setting[i]->name);
> - kfree(tlmi_priv.setting[i]->display_name);
> - kfree(tlmi_priv.setting[i]->possible_values);
> - kfree(tlmi_priv.setting[i]->current_value);
> - kfree(tlmi_priv.setting[i]);
> - tlmi_priv.setting[i] = NULL;
> + list_del(&attr->node);
> + kfree(attr->name);
> + kfree(attr->display_name);
> + kfree(attr->possible_values);
> + kfree(attr->current_value);
> + kfree(attr);
> }
>
> static void tlmi_release_attr(void)
> @@ -1465,8 +1466,6 @@ static void tlmi_release_attr(void)
> kobject_put(pos);
>
> kset_unregister(tlmi_priv.attribute_kset);
> - /* Clear up settings array */
> - memset(tlmi_priv.setting, 0, sizeof(tlmi_priv.setting));
>
> /* Free up any saved signatures */
> if (tlmi_priv.pwd_admin) {
> @@ -1505,7 +1504,8 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
>
> static int tlmi_sysfs_init(void)
> {
> - int i, ret = 0, auth_ret = 0;
> + struct tlmi_attr_setting *attr, *na;
> + int ret = 0, auth_ret = 0;
>
> guard(mutex)(&tlmi_mutex);
> tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
> @@ -1530,29 +1530,25 @@ static int tlmi_sysfs_init(void)
> goto fail_device_created;
> }
>
> - for (i = 0; i < TLMI_SETTINGS_COUNT; i++) {
> - /* Check if index is a valid setting - skip if it isn't */
> - if (!tlmi_priv.setting[i])
> - continue;
> -
> + list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node) {
> if (ret) { /* We had a critical failure. Just clean up */
> - tlmi_free_attr_record(i);
> + tlmi_free_attr_record(attr);
> continue;
> }
>
> /* check for duplicate or reserved values */
> if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
> - tlmi_priv.setting[i]->display_name) < 0) {
> - tlmi_free_attr_record(i);
> + attr->display_name) < 0) {
> + tlmi_free_attr_record(attr);
> continue;
> }
>
> /* Build attribute */
> - tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
> - ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
> - NULL, "%s", tlmi_priv.setting[i]->display_name);
> + attr->kobj.kset = tlmi_priv.attribute_kset;
> + ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
> + NULL, "%s", attr->display_name);
> if (ret) {
> - kobject_put(&tlmi_priv.setting[i]->kobj);
> + kobject_put(&attr->kobj);
> continue; /* use loop to clear remaining items */
> }
> }
> @@ -1664,6 +1660,7 @@ static struct tlmi_pwd_setting *tlmi_create_auth(const char *pwd_type,
>
> static int tlmi_analyze(struct wmi_device *wdev)
> {
> + struct tlmi_attr_setting *attr, *na;
> int i, ret;
>
> if (wmi_has_guid(LENOVO_SET_BIOS_SETTINGS_GUID) &&
> @@ -1699,6 +1696,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> pr_info("ThinkCenter modified support being used\n");
> }
>
> + INIT_LIST_HEAD(&tlmi_priv.settings);
> /*
> * Try to find the number of valid settings of this machine
> * and use it to create sysfs attributes.
> @@ -1804,7 +1802,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> if (setting->possible_values)
> strreplace(setting->possible_values, ',', ';');
>
> - tlmi_priv.setting[i] = setting;
> + list_add_tail(&setting->node, &tlmi_priv.settings);
> kfree(item);
> }
>
> @@ -1890,15 +1888,8 @@ static int tlmi_analyze(struct wmi_device *wdev)
> return 0;
>
> fail_clear_attr:
> - for (i = 0; i < TLMI_SETTINGS_COUNT; ++i) {
> - if (tlmi_priv.setting[i]) {
> - kfree(tlmi_priv.setting[i]->name);
> - kfree(tlmi_priv.setting[i]->display_name);
> - kfree(tlmi_priv.setting[i]->possible_values);
> - kfree(tlmi_priv.setting[i]->current_value);
> - kfree(tlmi_priv.setting[i]);
> - }
> - }
> + list_for_each_entry_safe(attr, na, &tlmi_priv.settings, node)
> + tlmi_free_attr_record(attr);
> kfree(tlmi_priv.pwd_admin);
> kfree(tlmi_priv.pwd_power);
> kfree(tlmi_priv.pwd_system);
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index 54d5c3b8233e..d0d8428ee440 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -100,6 +100,7 @@ struct tlmi_pwd_setting {
> struct tlmi_attr_setting {
> struct kobject kobj;
> struct wmi_device *wdev;
> + struct list_head node;
> int index;
> char *name;
> char *display_name;
> @@ -123,7 +124,7 @@ struct think_lmi {
> bool reboot_required;
> bool thinkcenter_mode;
>
> - struct tlmi_attr_setting *setting[TLMI_SETTINGS_COUNT];
> + struct list_head settings;
> struct device *class_dev;
> struct kset *attribute_kset;
> struct kset *authentication_kset;
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
@ 2026-12-04 13:41 ` Rong Zhang
2026-12-04 15:27 ` Mark Pearson
2026-12-05 9:54 ` kernel test robot
2026-12-05 9:55 ` kernel test robot
2 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:41 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Thinkpad, ThinkCenter and ThinkStation are implementing a new WMI API that
> is common across all platforms.
>
> This adds the initial infrastructure for reading in the BIOS settings.
>
> The tlmi-config module provides the main interface, using the config GUID,
> for changing settings.
>
> The tlmi-attr module reads in, and verifies, the BIOS attribute settings
> that are available.
>
> Future patches will add the sysfs infrastructure needed.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/Makefile | 1 +
> drivers/platform/x86/lenovo/think-lmi.h | 10 +
> drivers/platform/x86/lenovo/tlmi-attr.c | 212 ++++++++++++++++++++++
> drivers/platform/x86/lenovo/tlmi-config.c | 119 ++++++++++++
> 4 files changed, 342 insertions(+)
> create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
> create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
>
> diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
> index 12816d8d5e24..d22b56553297 100644
> --- a/drivers/platform/x86/lenovo/Makefile
> +++ b/drivers/platform/x86/lenovo/Makefile
> @@ -5,6 +5,7 @@
> #
> obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
> obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
> +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
> obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>
> lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index d0d8428ee440..82f3644b9089 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -12,6 +12,8 @@
> #define TLMI_LANG_MAXLEN 4
> #define TLMI_INDEX_MAX 32
>
> +#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
> +
> /* Possible error values */
> struct tlmi_err_codes {
> const char *err_str;
> @@ -106,6 +108,9 @@ struct tlmi_attr_setting {
> char *display_name;
> char *possible_values;
> char *current_value;
> + char *factory_default;
> + unsigned char access_level;
> + bool read_only;
> };
>
> struct think_lmi {
> @@ -128,6 +133,7 @@ struct think_lmi {
> struct device *class_dev;
> struct kset *attribute_kset;
> struct kset *authentication_kset;
> + struct wmi_device *config_wdev;
>
> struct tlmi_pwdcfg pwdcfg;
> struct tlmi_pwd_setting *pwd_admin;
> @@ -139,4 +145,8 @@ struct think_lmi {
> const struct tlmi_cert_guids *cert_guid;
> };
>
> +/* Used by tlmi to sync the different sub-drivers */
> +struct component_match;
> +void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> +
> #endif /* !_THINK_LMI_H_ */
> diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
> new file mode 100644
> index 000000000000..04c2ecf5053b
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo/tlmi-attr.c
> @@ -0,0 +1,212 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo TLMI attributes WMI interface driver.
> + *
> + * Read in the WMI configureable BIOS settings and their properties.
> + *
> + * This driver supports the "Common WMI" approach implemented on
> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> + */
> +
> +#include <linux/acpi.h>
> +#include <linux/cleanup.h>
> +#include <linux/component.h>
> +#include <linux/container_of.h>
> +#include <linux/device.h>
> +#include <linux/kdev_t.h>
> +#include <linux/kobject.h>
> +#include <linux/module.h>
> +#include <linux/string_helpers.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "think-lmi.h"
> +
> +static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> +{
> + if (setting) {
> + list_del(&setting->node);
> + kfree(setting->name);
> + kfree(setting->display_name);
> + kfree(setting->possible_values);
> + kfree(setting->current_value);
> + kfree(setting->factory_default);
> + kfree(setting);
> + }
> +}
> +
> +#define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
> +
> +static int tlmi_attr_sanitize(const union acpi_object *obj, bool *valid)
> +{
> + int i;
> +
> + if (obj->type != ACPI_TYPE_PACKAGE)
> + return -EINVAL;
> +
> + if (obj->package.count < ATTRDATA_ENTRIES)
> + return -EIO;
> +
> + /* First six entries should all be valid strings */
> + for (i = 0; i < 6; i++) {
> + if (obj->package.elements[i].type != ACPI_TYPE_STRING)
> + return -EIO;
> + if (!obj->package.elements[i].string.pointer[0]) {
> + /* If first entry empty, this is just an empty slot */
> + return i == 0 ? 0 : -EIO;
> + }
> + }
> + /* Remaining two are integers */
> + if (obj->package.elements[6].type != ACPI_TYPE_INTEGER)
> + return -EIO;
> + if (obj->package.elements[7].type != ACPI_TYPE_INTEGER)
> + return -EIO;
> +
> + *valid = true;
> + return 0;
> +}
> +
> +static int tlmi_attr_create_setting(int item, struct think_lmi *td, struct wmi_device *wdev)
> +{
> + struct tlmi_attr_setting *setting;
> + union acpi_object *obj __free(kfree) = NULL;
> + bool valid = false;
> + int ret;
> +
> + obj = wmidev_block_query(wdev, item);
> + if (!obj)
> + return 0; /* No valid entry here */
Could you use the modern WMI API to align with the Windows behavior? See
wmidev_query_block().
> +
> + /* Confirm we have a valid item */
> + ret = tlmi_attr_sanitize(obj, &valid);
> + if (!valid) {
> + if (ret)
> + pr_info("tlmi-attr: Incorrectly formatted entry %d\n", item);
> + return 0; /* Skip this entry */
> + }
> +
> + char *name __free(kfree) = kstrdup(obj->package.elements[0].string.pointer, GFP_KERNEL);
> + if (!name)
> + return -ENOMEM;
> +
> + char *current_value __free(kfree) = kstrdup(obj->package.elements[1].string.pointer,
> + GFP_KERNEL);
> + if (!current_value)
> + return -ENOMEM;
> +
> + char *possible_values __free(kfree) = kstrdup(obj->package.elements[2].string.pointer,
> + GFP_KERNEL);
> + if (!possible_values)
> + return -ENOMEM;
> +
> + char *factory_default __free(kfree) = kstrdup(obj->package.elements[3].string.pointer,
> + GFP_KERNEL);
> + if (!factory_default)
> + return -ENOMEM;
> +
> + char *display_name __free(kfree) = kstrdup(obj->package.elements[5].string.pointer,
> + GFP_KERNEL);
> + if (!display_name)
> + return -ENOMEM;
> +
> + setting = kzalloc_obj(*setting);
> + if (!setting)
> + return -ENOMEM;
> +
> + setting->index = item;
> + setting->access_level = obj->package.elements[6].integer.value;
> + setting->read_only = obj->package.elements[7].integer.value ? true : false;
> + setting->name = no_free_ptr(name);
> + setting->current_value = no_free_ptr(current_value);
> + setting->possible_values = no_free_ptr(possible_values);
> + setting->factory_default = no_free_ptr(factory_default);
> + setting->display_name = no_free_ptr(display_name);
> + setting->wdev = td->config_wdev; /* Used to set attributes */
> +
> + list_add(&setting->node, &td->settings);
> + return 0;
> +}
> +
> +static int tlmi_attr_component_bind(struct device *attr_dev, struct device *config_dev,
> + void *d)
> +{
> + struct wmi_device *wdev = dev_get_drvdata(attr_dev);
> + struct tlmi_attr_setting *attr, *na;
> + struct think_lmi *td = d;
> + int i, ret = 0;
> +
> + INIT_LIST_HEAD(&td->settings);
> + /*
> + * Try to find the number of valid settings of this machine
> + * and use it to create sysfs attributes.
> + */
> + for (i = 0; i < TLMI_SETTINGS_COUNT - 1; ++i) {
> + ret = tlmi_attr_create_setting(i, td, wdev);
> + if (ret)
> + break;
> + }
> + if (ret) { /* Clean up as unbind will not be called */
> + list_for_each_entry_safe(attr, na, &td->settings, node)
> + tlmi_attr_release_setting(attr);
> + }
If the list really useful? You can use `while (i--)' here.
> + return ret;
> +}
> +
> +static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *config_dev,
> + void *d)
> +{
> + struct tlmi_attr_setting *attr, *na;
> + struct think_lmi *td = d;
> +
> + list_for_each_entry_safe(attr, na, &td->settings, node)
> + tlmi_attr_release_setting(attr);
All settings must have been created on bind() success, in which case you
don't need the list on unbind() as well.
> +}
> +
> +static const struct component_ops tlmi_attr_component_ops = {
> + .bind = tlmi_attr_component_bind,
> + .unbind = tlmi_attr_component_unbind,
> +};
> +
> +static int tlmi_attr_probe(struct wmi_device *wdev, const void *context)
> +{
> + dev_set_drvdata(&wdev->dev, wdev);
> + return component_add(&wdev->dev, &tlmi_attr_component_ops);
> +}
> +
> +static void tlmi_attr_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &tlmi_attr_component_ops);
> +}
> +
> +static const struct wmi_device_id tlmi_attr_id_table[] = {
> + { TLMI_ATTRIBUTE_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver tlmi_attr_driver = {
> + .driver = {
> + .name = "tlmi-attr",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = tlmi_attr_id_table,
> + .probe = tlmi_attr_probe,
> + .remove = tlmi_attr_remove,
> + .no_singleton = true,
> +};
> +
> +static int tlmi_attr_match(struct device *dev, void *type)
> +{
> + return (dev->driver == &tlmi_attr_driver.driver);
> +}
> +
> +void tlmi_attr_match_add(struct device *master, struct component_match **matchptr)
> +{
> + component_match_add(master, matchptr, tlmi_attr_match, NULL);
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_attr_match_add, "TLMI-ATTR");
Use an underline instead of a hyphen. Meanwhile, could you name it
"THINKPAD_LMI_*" to align with the Kconfig name and improve
understandability?
> +
> +module_wmi_driver(tlmi_attr_driver);
> +
> +MODULE_DEVICE_TABLE(wmi, tlmi_attr_id_table);
> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> +MODULE_DESCRIPTION("TLMI Attributes WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> new file mode 100644
> index 000000000000..9f57b0ba8dc5
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo TLMI configuration WMI Data Block driver.
> + *
> + * Main controller for the tlmi-* suite of drivers.
> + * Provides ability to set and save BIOS settings.
> + *
> + * This driver supports the "Common WMI" approach implemented on
> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> + */
> +
> +#include <linux/component.h>
> +#include <linux/device.h>
> +#include <linux/dev_printk.h>
> +#include <linux/err.h>
> +#include <linux/firmware_attributes.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/mutex_types.h>
> +#include <linux/stddef.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "think-lmi.h"
> +
> +#define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
> +
> +/* Method IDS for configuration GUID */
> +#define SET_ID 1
> +#define SAVE_ID 2
> +
> +static int tlmi_config_bind(struct device *dev)
> +{
> + struct think_lmi *td = dev_get_drvdata(dev);
> + int ret;
> +
> + /* Triggers the bind callbacks for registered sub-components */
> + ret = component_bind_all(dev, td);
> + return ret;
> +}
> +
> +static void tlmi_config_unbind(struct device *dev)
> +{
> + struct think_lmi *td = dev_get_drvdata(dev);
> +
> + component_unbind_all(dev, td);
> +}
> +
> +static const struct component_master_ops aggregate_ops = {
> + .bind = tlmi_config_bind,
> + .unbind = tlmi_config_unbind,
> +};
> +
> +static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> +{
> + struct component_match *match = NULL;
> + guid_t tlmi_attr_guid;
> + struct think_lmi *td;
> + int ret;
> +
> + guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
ret =
if (ret)
> +
> + /* At minimum need to support BIOS settings */
> + if (!wmidev_exists(&tlmi_attr_guid))
> + return -EOPNOTSUPP;
> +
> + td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
> + if (!td)
> + return -ENOMEM;
> +
> + td->config_wdev = wdev;
> + dev_set_drvdata(&wdev->dev, td);
> +
> + td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
> + NULL, "%s", "tlmi");
no_singleton?
And why would you need to create it this early? Please postpone it to
component bind.
> + if (IS_ERR(td->class_dev))
> + return PTR_ERR(td->class_dev);
> + dev_set_drvdata(td->class_dev, td);
> +
> + /* Register the other components */
> + tlmi_attr_match_add(&wdev->dev, &match);
Check errors.
Thanks,
Rong
> +
> + ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
> + if (ret)
> + device_unregister(td->class_dev);
> +
> + return ret;
> +}
> +
> +static void tlmi_config_remove(struct wmi_device *wdev)
> +{
> + struct think_lmi *td = dev_get_drvdata(&wdev->dev);
> +
> + component_master_del(&wdev->dev, &aggregate_ops);
> + device_unregister(td->class_dev);
> +}
> +
> +static const struct wmi_device_id tlmi_config_id_table[] = {
> + { TLMI_CONFIG_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver tlmi_config_driver = {
> + .driver = {
> + .name = "tlmi-config",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = tlmi_config_id_table,
> + .probe = tlmi_config_probe,
> + .remove = tlmi_config_remove,
> + .no_singleton = true,
> +};
> +
> +module_wmi_driver(tlmi_config_driver);
> +
> +MODULE_IMPORT_NS("TLMI-ATTR");
> +MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> +MODULE_DESCRIPTION("TLMI Config WMI Driver");
> +MODULE_LICENSE("GPL");
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
@ 2026-12-04 13:44 ` Rong Zhang
2026-12-04 15:41 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:44 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Implement the sysfs entries for the attribute settings, along with the
> ability to modify and query them.
>
> Implement the save_settings and pending_reboot sysfs entries.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/think-lmi.h | 1 +
> drivers/platform/x86/lenovo/tlmi-attr.c | 4 +-
> drivers/platform/x86/lenovo/tlmi-config.c | 362 ++++++++++++++++++++++
> 3 files changed, 366 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index 82f3644b9089..07a235b3a886 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -148,5 +148,6 @@ struct think_lmi {
> /* Used by tlmi to sync the different sub-drivers */
> struct component_match;
> void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> +void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
>
> #endif /* !_THINK_LMI_H_ */
> diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
> index 04c2ecf5053b..8818010a45cd 100644
> --- a/drivers/platform/x86/lenovo/tlmi-attr.c
> +++ b/drivers/platform/x86/lenovo/tlmi-attr.c
> @@ -21,7 +21,7 @@
> #include <linux/wmi.h>
> #include "think-lmi.h"
>
> -static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> +void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
This was introduced by the previous patch. Please avoid unnecessary back-
and-forth changes.
> {
> if (setting) {
> list_del(&setting->node);
> @@ -33,6 +33,7 @@ static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> kfree(setting);
> }
> }
> +EXPORT_SYMBOL_NS_GPL(tlmi_attr_release_setting, "TLMI-ATTR");
>
> #define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
>
> @@ -157,6 +158,7 @@ static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *c
> struct tlmi_attr_setting *attr, *na;
> struct think_lmi *td = d;
>
> + /* This should not be needed - but make sure settings list is clear */
> list_for_each_entry_safe(attr, na, &td->settings, node)
> tlmi_attr_release_setting(attr);
> }
> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> index 9f57b0ba8dc5..ef5efae2e395 100644
> --- a/drivers/platform/x86/lenovo/tlmi-config.c
> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> @@ -18,6 +18,7 @@
> #include <linux/mutex.h>
> #include <linux/mutex_types.h>
> #include <linux/stddef.h>
> +#include <linux/string_helpers.h>
> #include <linux/types.h>
> #include <linux/wmi.h>
> #include "think-lmi.h"
> @@ -28,6 +29,359 @@
> #define SET_ID 1
> #define SAVE_ID 2
>
> +static DEFINE_MUTEX(tlmi_config_lock);
> +
> +/* ---- Helper functions---- */
> +
> +static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
> +{
> + struct wmi_string *wmistr = (struct wmi_string *)buffer;
> + u16 len;
> + int ret;
> +
> + if (!str || !buffer)
> + return -EINVAL;
> +
> + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
Use wmistr you introduced above.
Passing buffer_len is incorrect, see also
drivers/platform/wmi/tests/string_kunit.c for examples.
> + if (ret < 0)
> + return ret;
> +
> + len = le16_to_cpu(wmistr->length);
> + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
> + return len; /* minus extra null and + the length field */
> +}
> +
> +/* Send request to BIOS and scan return buffer for error codes */
> +static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> + struct wmi_buffer *wmibuf)
> +{
> + struct wmi_buffer wmibuf_return = {0, NULL};
= {};
> + char errstr[32];
> + int ret;
> +
> + ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
> + sizeof(struct wmi_string));
> + if (!ret && wmibuf_return.data) {
> + /* extract error string */
> + if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
The buffer's length contains the wmi_string's length field, why not
subtract it? And you didn't check the wmi_string's validity.
> + ret = -EINVAL;
> + else
> + ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
> + sizeof(errstr));
> + kfree(wmibuf_return.data);
Why not:
if (...)
return -EINVAL;
struct wmi_string *wmistr __free(kfree) = wmibuf_return.data;
ret = wmi_string_to_utf8s();
> + if (ret < 0)
> + return ret;
> +
> + if (!strcmp("Success", errstr))
> + return 0;
> + else if (!strcmp("Not Supported", errstr))
> + return -EOPNOTSUPP;
> + else if (!strcmp("Invalid Parameter", errstr))
> + return -EINVAL;
> + else if (!strcmp("Access Denied", errstr))
> + return -EACCES;
> + else if (!strcmp("System Busy", errstr))
> + return -EBUSY;
> + else if (!strcmp("System Locked", errstr))
> + return -EACCES;
> + dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
> + return -EIO;
-EPROTO?
> + }
> + return ret;
> +}
> +
> +static ssize_t common_type_show(char *possible_values, char *buf)
> +{
> + if (possible_values) {
> + /* Figure out what setting type is as BIOS does not return this */
> + if (strchr(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 common_current_value_store(char *name, const char *buf, int wmi_id,
`name' should be const char * if you are not intended to manipulate it.
> + struct think_lmi *td)
> +{
> + char *new_setting __free(kfree) = NULL;
> + char *wmidata __free(kfree) = NULL;
Move them to where the resources are allocated.
> + size_t namelen, valuelen;
> + struct wmi_buffer wmibuf;
> + char *start;
> + int ix = 0;
> +
> + /* If a save has been done then a reboot is needed */
> + if (td->reboot_required)
> + return -EPERM;
> +
> + /* Strip out CR if one is present */
\n is LF.
> + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> + if (!new_setting)
> + return -ENOMEM;
I am not in favor of the idea of abusing kstrdup_and_replace(), because:
- Only the trailing LF should be stripped
- You don't take the advantage of the sysfs buffer size
I'd suggest:
if (size && buf[size - 1] == '\n')
size -= 1;
if (!size)
return -EINVAL;
char *new_setting __free(kfree) = kmemdup_nul(buf, size, GFP_KERNEL);
If LF in between is not allowed, please return -EINVAL instead of
silently clipping the string.
> +
> + /* Calculate and alloc buffer for command string */
> + namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
> + valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
> + wmibuf.length = namelen + valuelen;
> + wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
> + wmibuf.data = wmidata;
> + if (!wmibuf.data)
> + return -ENOMEM;
> +
> + /* build argument buffer from inputs */
> + start = wmibuf.data;
> + ix = tlmi_populate_string_buffer(start, namelen, name);
> + if (ix < 0)
> + return ix;
> +
> + start += ix;
> + ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
> + if (ix < 0)
> + return ix;
> +
> + return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
> +}
> +
> +/* ---- Attribute sysfs ---- */
> +static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
> +{
> + return container_of(kobj, struct tlmi_attr_setting, kobj);
> +}
> +
> +static ssize_t display_name_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->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);
> +
> + guard(mutex)(&tlmi_config_lock);
> +
> + if (!setting->current_value)
> + return sysfs_emit(buf, "unknown\n");
> + return sysfs_emit(buf, "%s\n", setting->current_value);
> +}
> +
> +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 ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> +
> + return common_type_show(setting->possible_values, buf);
> +}
> +
> +static ssize_t current_value_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + int ret;
> +
> + guard(mutex)(&tlmi_config_lock);
> +
> + ret = common_current_value_store(setting->name, buf, SET_ID, td);
> + if (!ret) {
> + char *s;
> +
> + td->save_required = true;
> + /* Update setting so read back shows correctly */
> + s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
??? Please don't repeat the same operation twice.
> + kfree(setting->current_value);
> + /* if kstrdup fails, we'll handle it in the show */
> + setting->current_value = s;
> + return count;
> + }
> + return ret;
> +}
> +
> +static struct kobj_attribute attr_display_name = __ATTR_RO(display_name);
> +
> +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_display_name.attr,
> + &attr_current_val.attr,
> + &attr_possible_values.attr,
> + &attr_type.attr,
> + NULL
> +};
> +
> +static const struct attribute_group tlmi_attr_group = {
> + .attrs = tlmi_attrs,
> +};
> +__ATTRIBUTE_GROUPS(tlmi_attr);
> +
> +static void tlmi_attr_setting_release(struct kobject *kobj)
> +{
> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> +
> + tlmi_attr_release_setting(setting);
> +}
> +
> +static const struct kobj_type tlmi_attr_setting_ktype = {
> + .release = &tlmi_attr_setting_release,
> + .sysfs_ops = &kobj_sysfs_ops,
> + .default_groups = tlmi_attr_groups,
> +};
> +
> +/* ---- sysfs entries --------------------------------------------------------- */
> +static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> +
Why doesn't this need guard(mutex)(&tlmi_config_lock)?
> + return sysfs_emit(buf, "%d\n", td->pending_changes);
> +}
> +
> +static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
> +
> +static ssize_t save_settings_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> +
Ditto?
> + return sysfs_emit(buf, "%d\n", td->save_required);
> +}
> +
> +static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> + char *wmidata __free(kfree) = NULL;
> + struct wmi_buffer wmibuf;
> + int ret = 0;
> +
> + /* save command triggered by writing 'save' */
> + if (!sysfs_streq(buf, "save"))
> + return -EINVAL;
> +
> + /* Use lock in case multiple WMI operations needed */
> + guard(mutex)(&tlmi_config_lock);
> +
> + /* Check there is actually something to save */
> + if (!td->save_required)
> + return -ENOENT;
Returning -ENOENT on a file could be confusing IMO.
Though thinklmi is already doing so, sigh...
Thanks,
Rong
> +
> + wmibuf.length = struct_size_t(struct wmi_string, chars, 1 + 1);
> + wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
> + wmibuf.data = wmidata;
> + if (!wmibuf.data)
> + return -ENOMEM;
> +
> + ret = tlmi_populate_string_buffer(wmibuf.data, 1, "\0");
> + if (ret < 0)
> + return ret;
> +
> + ret = tlmi_request(td->config_wdev, 0, SAVE_ID, &wmibuf);
> + if (ret < 0)
> + return ret;
> +
> + td->save_required = false;
> + td->reboot_required = true;
> +
> + if (!td->pending_changes) {
> + td->pending_changes = true;
> + /* let userland know it may need to check reboot pending again */
> + kobject_uevent(&td->class_dev->kobj, KOBJ_CHANGE);
> + }
> + return count;
> +}
> +
> +static struct kobj_attribute save_settings = __ATTR_RW(save_settings);
> +
> +static void tlmi_config_sysfs_release(struct think_lmi *td)
> +{
> + struct kobject *pos, *n;
> +
> + if (!td->attribute_kset)
> + return;
> +
> + sysfs_remove_file(&td->attribute_kset->kobj, &pending_reboot.attr);
> + sysfs_remove_file(&td->attribute_kset->kobj, &save_settings.attr);
> +
> + list_for_each_entry_safe(pos, n, &td->attribute_kset->list, entry)
> + kobject_put(pos);
> +
> + kset_unregister(td->attribute_kset);
> + td->attribute_kset = NULL;
> +}
> +
> +static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
> +{
> + struct kobject *duplicate;
> +
> + if (!strcmp(name, ""))
> + return -EINVAL;
> + if (!strcmp(name, "Reserved"))
> + return -EINVAL;
> +
> + duplicate = kset_find_obj(attribute_kset, name);
> + if (duplicate) {
> + /* kset_find_obj() returns a reference */
> + kobject_put(duplicate);
> + return -EBUSY;
> + }
> +
> + return 0;
> +}
> +
> +static int tlmi_config_sysfs_init(struct think_lmi *td)
> +{
> + struct tlmi_attr_setting *attr, *na;
> + int ret;
> +
> + /* Create sysfs entries */
> + td->attribute_kset = kset_create_and_add("attributes", NULL,
> + &td->class_dev->kobj);
> + if (!td->attribute_kset)
> + return -ENOMEM;
> +
> + list_for_each_entry_safe(attr, na, &td->settings, node) {
> + /* check for duplicate or reserved values */
> + if (tlmi_validate_setting_name(td->attribute_kset,
> + attr->name) < 0)
> + continue;
> +
> + /* Build attribute */
> + attr->kobj.kset = td->attribute_kset;
> + ret = kobject_init_and_add(&attr->kobj, &tlmi_attr_setting_ktype,
> + NULL, "%s", attr->name);
> + if (ret) {
> + kobject_put(&attr->kobj);
> + goto out;
> + }
> + }
> +
> + ret = sysfs_create_file(&td->attribute_kset->kobj, &pending_reboot.attr);
> + if (ret)
> + goto out;
> +
> + ret = sysfs_create_file(&td->attribute_kset->kobj, &save_settings.attr);
> +
> +out:
> + if (ret) /* Clean up if any failures */
> + tlmi_config_sysfs_release(td);
> + return ret;
> +}
> +
> static int tlmi_config_bind(struct device *dev)
> {
> struct think_lmi *td = dev_get_drvdata(dev);
> @@ -35,6 +389,13 @@ static int tlmi_config_bind(struct device *dev)
>
> /* Triggers the bind callbacks for registered sub-components */
> ret = component_bind_all(dev, td);
> + if (ret)
> + return ret;
> + /* Create sysfs entries */
> + ret = tlmi_config_sysfs_init(td);
> + if (ret)
> + component_unbind_all(dev, td);
> +
> return ret;
> }
>
> @@ -42,6 +403,7 @@ static void tlmi_config_unbind(struct device *dev)
> {
> struct think_lmi *td = dev_get_drvdata(dev);
>
> + tlmi_config_sysfs_release(td);
> component_unbind_all(dev, td);
> }
>
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
@ 2026-12-04 13:48 ` Rong Zhang
2026-12-04 15:44 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:48 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Add authdata module for reading in the authorisation account
> details from the BIOS.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/Makefile | 2 +-
> drivers/platform/x86/lenovo/think-lmi.h | 13 ++
> drivers/platform/x86/lenovo/tlmi-authdata.c | 135 ++++++++++++++++++++
> drivers/platform/x86/lenovo/tlmi-config.c | 10 +-
> 4 files changed, 156 insertions(+), 4 deletions(-)
> create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
>
> diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
> index d22b56553297..f1600b562273 100644
> --- a/drivers/platform/x86/lenovo/Makefile
> +++ b/drivers/platform/x86/lenovo/Makefile
> @@ -5,7 +5,7 @@
> #
> obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
> obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
> -obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
> +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
> obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>
> lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index 07a235b3a886..75b21dcc2f42 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -13,6 +13,7 @@
> #define TLMI_INDEX_MAX 32
>
> #define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
> +#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
>
> /* Possible error values */
> struct tlmi_err_codes {
> @@ -75,9 +76,20 @@ struct tlmi_pwdcfg_ext {
> uint32_t nvme_master_password;
> };
>
> +/* fields specific to tlmi-authdata driver */
> +struct tlmi_pwdcfg_authdata {
> + bool strong_password;
> + bool deploy_mode;
> + bool sys_mgr_pwd_ctrl;
> + bool power_on_pwd_ctrl;
> + bool storage_pwd_ctrl;
> + bool sys_mgr_setup_ctrl;
> +};
> +
> struct tlmi_pwdcfg {
> struct tlmi_pwdcfg_core core;
> struct tlmi_pwdcfg_ext ext;
> + struct tlmi_pwdcfg_authdata authdata;
> };
>
> /* password setting details */
> @@ -149,5 +161,6 @@ struct think_lmi {
> struct component_match;
> void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
> +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
>
> #endif /* !_THINK_LMI_H_ */
> diff --git a/drivers/platform/x86/lenovo/tlmi-authdata.c b/drivers/platform/x86/lenovo/tlmi-authdata.c
> new file mode 100644
> index 000000000000..668d07029139
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo/tlmi-authdata.c
> @@ -0,0 +1,135 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo ThinkLMI authentication data WMI interface driver.
> + *
> + * Read in the WMI authentication settings and their properties.
> + *
> + * This driver supports the "Common WMI" approach implemented on
> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> + */
> +
> +#include <linux/cleanup.h>
> +#include <linux/component.h>
> +#include <linux/device.h>
> +#include <linux/module.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "think-lmi.h"
> +
> +#define AUTHDATA_ENTRIES 15 /*number of entries returned from BIOS */
> +
> +static int tlmi_authdata_sanitize(const union acpi_object *obj)
> +{
> + int i;
> +
> + /*Scan through query result and check it's sane*/
> + if (obj->type != ACPI_TYPE_PACKAGE)
> + return -EINVAL;
> +
> + if (obj->package.count < AUTHDATA_ENTRIES)
> + return -EIO;
> +
> + for (i = 0; i < AUTHDATA_ENTRIES; i++) {
> + /* Every entry is an integer which makes this easy */
> + if (obj->package.elements[i].type != ACPI_TYPE_INTEGER)
> + return -EIO;
> + }
> + return 0;
> +}
> +
> +/* Get password settings from BIOS */
> +static int tlmi_authdata_get(struct wmi_device *wdev, struct think_lmi *td)
> +{
> + const union acpi_object *obj __free(kfree) = NULL;
> + int ret;
> +
> + obj = wmidev_block_query(wdev, 0);
> + if (!obj)
> + return -EIO;
Use modern WMI APIs and move __free() declaration to wherever the
resource is allocated.
> +
> + ret = tlmi_authdata_sanitize(obj);
> + if (ret)
> + return ret;
> +
> + td->pwdcfg.core.password_state = obj->package.elements[0].integer.value;
> + td->pwdcfg.core.min_length = obj->package.elements[1].integer.value;
> + td->pwdcfg.core.max_length = obj->package.elements[2].integer.value;
> + td->pwdcfg.authdata.strong_password = obj->package.elements[3].integer.value;
> + td->pwdcfg.core.supported_encodings = obj->package.elements[4].integer.value;
> + td->pwdcfg.core.supported_keyboard = obj->package.elements[5].integer.value;
> + td->pwdcfg.ext.hdd_user_password = obj->package.elements[6].integer.value;
> + td->pwdcfg.ext.hdd_master_password = obj->package.elements[7].integer.value;
> + td->pwdcfg.ext.nvme_user_password = obj->package.elements[8].integer.value;
> + td->pwdcfg.ext.nvme_master_password = obj->package.elements[9].integer.value;
> + td->pwdcfg.authdata.deploy_mode = obj->package.elements[10].integer.value;
> + td->pwdcfg.authdata.sys_mgr_pwd_ctrl = obj->package.elements[11].integer.value;
> + td->pwdcfg.authdata.power_on_pwd_ctrl = obj->package.elements[12].integer.value;
> + td->pwdcfg.authdata.storage_pwd_ctrl = obj->package.elements[13].integer.value;
> + td->pwdcfg.authdata.sys_mgr_setup_ctrl = obj->package.elements[14].integer.value;
> +
> + if (WARN_ON(td->pwdcfg.core.max_length >= TLMI_PWD_BUFSIZE))
> + td->pwdcfg.core.max_length = TLMI_PWD_BUFSIZE - 1;
> + if (WARN_ON(td->pwdcfg.core.min_length > td->pwdcfg.core.max_length))
> + td->pwdcfg.core.min_length = td->pwdcfg.core.max_length;
Why would you need to WARN_ON() firmware stuff? Usually it's meant for
kernel stuff.
> +
> + return 0;
> +}
> +
> +static int tlmi_authdata_component_bind(struct device *authdata_dev, struct device *config_dev,
> + void *d)
> +{
> + struct wmi_device *wdev = dev_get_drvdata(authdata_dev);
> + struct think_lmi *td = d;
> +
> + return tlmi_authdata_get(wdev, td);
> +}
> +
> +static const struct component_ops tlmi_authdata_component_ops = {
> + .bind = tlmi_authdata_component_bind,
> +};
> +
> +static int tlmi_authdata_probe(struct wmi_device *wdev, const void *context)
> +{
> + dev_set_drvdata(&wdev->dev, wdev);
> +
> + return component_add(&wdev->dev, &tlmi_authdata_component_ops);
> +}
> +
> +static void tlmi_authdata_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &tlmi_authdata_component_ops);
> +}
> +
> +static const struct wmi_device_id tlmi_authdata_id_table[] = {
> + { TLMI_AUTHENTICATION_DATA_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver tlmi_authdata_driver = {
> + .driver = {
> + .name = "tlmi-authdata",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = tlmi_authdata_id_table,
> + .probe = tlmi_authdata_probe,
> + .remove = tlmi_authdata_remove,
> + .no_singleton = true,
> +};
> +
> +static int tlmi_authdata_match(struct device *dev, void *type)
> +{
> + return (dev->driver == &tlmi_authdata_driver.driver);
> +}
> +
> +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr)
> +{
> + component_match_add(master, matchptr, tlmi_authdata_match, NULL);
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_authdata_match_add, "TLMI-AUTHDATA");
> +
> +module_wmi_driver(tlmi_authdata_driver);
> +
> +MODULE_DEVICE_TABLE(wmi, tlmi_authdata_id_table);
> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> +MODULE_DESCRIPTION("ThinkLMI Authentication Data WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> index ef5efae2e395..ddbf0307f810 100644
> --- a/drivers/platform/x86/lenovo/tlmi-config.c
> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> @@ -415,14 +415,16 @@ static const struct component_master_ops aggregate_ops = {
> static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> {
> struct component_match *match = NULL;
> - guid_t tlmi_attr_guid;
> + guid_t tlmi_attr_guid, tlmi_authdata_guid;
> struct think_lmi *td;
> int ret;
>
> guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
> + guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
ret =
if (ret)
>
> - /* At minimum need to support BIOS settings */
> - if (!wmidev_exists(&tlmi_attr_guid))
> + /* At minimum need to support BIOS and authentication settings */
> + if (!wmidev_exists(&tlmi_attr_guid) ||
> + !wmidev_exists(&tlmi_authdata_guid))
> return -EOPNOTSUPP;
>
> td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
> @@ -440,6 +442,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
>
> /* Register the other components */
> tlmi_attr_match_add(&wdev->dev, &match);
> + tlmi_authdata_match_add(&wdev->dev, &match);
Check errors.
Thanks,
Rong
>
> ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
> if (ret)
> @@ -475,6 +478,7 @@ static struct wmi_driver tlmi_config_driver = {
> module_wmi_driver(tlmi_config_driver);
>
> MODULE_IMPORT_NS("TLMI-ATTR");
> +MODULE_IMPORT_NS("TLMI-AUTHDATA");
> MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
> MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> MODULE_DESCRIPTION("TLMI Config WMI Driver");
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
2026-12-04 2:20 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
@ 2026-12-04 13:49 ` Rong Zhang
2026-12-04 15:50 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:49 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> The tlmi_populate_string_buffer and tlmi_request are going to be
> needed in the upcoming tlmi-auth module, as well as the current
> tlmi-config module.
>
> As we can't have circular dependencies they need to move out of
> tlmi-config.
>
> The wmi-helpers module already provides helper functions for the
> Lenovo Legion platforms, and seems a logical place for these to
> move too.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/Kconfig | 1 +
> drivers/platform/x86/lenovo/tlmi-config.c | 59 +-------------------
> drivers/platform/x86/lenovo/wmi-helpers.c | 65 ++++++++++++++++++++++-
> drivers/platform/x86/lenovo/wmi-helpers.h | 5 ++
> 4 files changed, 72 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
> index 16569406c946..c59461cf5f4a 100644
> --- a/drivers/platform/x86/lenovo/Kconfig
> +++ b/drivers/platform/x86/lenovo/Kconfig
> @@ -218,6 +218,7 @@ config THINKPAD_LMI
> depends on ACPI_WMI
> depends on DMI
> select FW_ATTR_CLASS
> + select LENOVO_WMI_HELPERS
Ba aware of
https://msgid.link/f8815e94ddc161495ca80b04d7e3388549edafeb.camel@rong.moe
if you'd need to rebase on top of David's series.
> help
> This driver allows changing BIOS settings on Lenovo machines whose
> BIOS support the WMI interface.
> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> index ddbf0307f810..bb9c5f720c24 100644
> --- a/drivers/platform/x86/lenovo/tlmi-config.c
> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> @@ -22,6 +22,7 @@
> #include <linux/types.h>
> #include <linux/wmi.h>
> #include "think-lmi.h"
> +#include "wmi-helpers.h"
>
> #define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
>
> @@ -33,63 +34,6 @@ static DEFINE_MUTEX(tlmi_config_lock);
>
> /* ---- Helper functions---- */
>
> -static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
> -{
> - struct wmi_string *wmistr = (struct wmi_string *)buffer;
> - u16 len;
> - int ret;
> -
> - if (!str || !buffer)
> - return -EINVAL;
> -
> - ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
> - if (ret < 0)
> - return ret;
> -
> - len = le16_to_cpu(wmistr->length);
> - wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
> - return len; /* minus extra null and + the length field */
> -}
> -
> -/* Send request to BIOS and scan return buffer for error codes */
> -static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> - struct wmi_buffer *wmibuf)
> -{
> - struct wmi_buffer wmibuf_return = {0, NULL};
> - char errstr[32];
> - int ret;
> -
> - ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
> - sizeof(struct wmi_string));
> - if (!ret && wmibuf_return.data) {
> - /* extract error string */
> - if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
> - ret = -EINVAL;
> - else
> - ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
> - sizeof(errstr));
> - kfree(wmibuf_return.data);
> - if (ret < 0)
> - return ret;
> -
> - if (!strcmp("Success", errstr))
> - return 0;
> - else if (!strcmp("Not Supported", errstr))
> - return -EOPNOTSUPP;
> - else if (!strcmp("Invalid Parameter", errstr))
> - return -EINVAL;
> - else if (!strcmp("Access Denied", errstr))
> - return -EACCES;
> - else if (!strcmp("System Busy", errstr))
> - return -EBUSY;
> - else if (!strcmp("System Locked", errstr))
> - return -EACCES;
> - dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
> - return -EIO;
> - }
> - return ret;
> -}
> -
What? Wasn't these just introduced before? Could you add them to the
right place from the beginning?
> static ssize_t common_type_show(char *possible_values, char *buf)
> {
> if (possible_values) {
> @@ -477,6 +421,7 @@ static struct wmi_driver tlmi_config_driver = {
>
> module_wmi_driver(tlmi_config_driver);
>
> +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
> MODULE_IMPORT_NS("TLMI-ATTR");
> MODULE_IMPORT_NS("TLMI-AUTHDATA");
> MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
> index 687caa226263..e735771bb8d7 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.c
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
> @@ -1,6 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0-or-later
> /*
> - * Lenovo Legion WMI helpers driver.
> + * Lenovo Legion and TLMI WMI helpers driver.
> *
> * The Lenovo Legion WMI interface is broken up into multiple GUID interfaces
> * that require cross-references between GUID's for some functionality. The
> @@ -13,6 +13,10 @@
> * drivers uses a common procedure to get data from the WMI interface,
> * enumerated here.
> *
> + * TLMI interface uses multiple GUID interfaces for BIOS settings and
> + * authentication settings. A common procedure is used to get data from the
> + * WMI interface and check for return error strings.
> + *
> * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> */
>
> @@ -33,6 +37,65 @@
> /* Thermal mode notifier chain. */
> static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
>
> +ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
Why not void *buffer?
> +{
> + struct wmi_string *wmistr = (struct wmi_string *)buffer;
> + u16 len;
> + int ret;
> +
> + if (!str || !buffer)
> + return -EINVAL;
> +
> + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
> + if (ret < 0)
> + return ret;
> +
> + len = le16_to_cpu(wmistr->length);
> + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
> + return len; /* minus extra null and + the length field */
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_populate_string_buffer, "LENOVO_WMI_HELPERS");
I believe this helper can be named lwmi_* as it's not coupled with
thinklmi...
> +
> +/* Send request to BIOS and scan return buffer for error codes */
> +int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> + struct wmi_buffer *wmibuf)
...while this is coupled with thinklmi, so this can be named tlmi_*.
Thanks,
Rong
> +{
> + struct wmi_buffer wmibuf_return = {0, NULL};
> + char errstr[32];
> + int ret;
> +
> + ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
> + sizeof(struct wmi_string));
> + if (!ret && wmibuf_return.data) {
> + /* extract error string */
> + if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
> + ret = -EINVAL;
> + else
> + ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
> + sizeof(errstr));
> + kfree(wmibuf_return.data);
> + if (ret < 0)
> + return ret;
> +
> + if (!strcmp("Success", errstr))
> + return 0;
> + else if (!strcmp("Not Supported", errstr))
> + return -EOPNOTSUPP;
> + else if (!strcmp("Invalid Parameter", errstr))
> + return -EINVAL;
> + else if (!strcmp("Access Denied", errstr))
> + return -EACCES;
> + else if (!strcmp("System Busy", errstr))
> + return -EBUSY;
> + else if (!strcmp("System Locked", errstr))
> + return -EACCES;
> + dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
> + return -EIO;
> + }
> + return ret;
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_request, "LENOVO_WMI_HELPERS");
> +
> /**
> * lwmi_dev_evaluate_int() - Helper function for calling WMI methods that
> * return an integer.
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
> index 039fe61003ce..f9c05aa25d69 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.h
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.h
> @@ -10,6 +10,7 @@
> struct device;
> struct notifier_block;
> struct wmi_device;
> +struct wmi_buffer;
>
> struct wmi_method_args_32 {
> u32 arg0;
> @@ -31,6 +32,10 @@ enum thermal_mode {
> LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
> };
>
> +ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str);
> +int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> + struct wmi_buffer *wmibuf);
> +
> int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
> unsigned char *buf, size_t size, u32 *retval);
>
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
@ 2026-12-04 13:52 ` Rong Zhang
2026-12-05 9:55 ` kernel test robot
1 sibling, 0 replies; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 13:52 UTC (permalink / raw)
To: Mark Pearson
Cc: derekjohn.clark, hansg, ilpo.jarvinen, platform-driver-x86,
linux-kernel
Hi Mark,
On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> Add interface to authentication settings using it's associated GUID.
> tlmi-auth uses the data read in by tlmi-authdata.
>
> Enables ability to configure admin, system, power-on, hdd and nvme
> passwords.
> Enables certificate support.
>
> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> ---
> drivers/platform/x86/lenovo/Makefile | 2 +-
> drivers/platform/x86/lenovo/think-lmi.h | 6 +
> drivers/platform/x86/lenovo/tlmi-auth.c | 958 ++++++++++++++++++++++
> drivers/platform/x86/lenovo/tlmi-config.c | 50 +-
> 4 files changed, 1009 insertions(+), 7 deletions(-)
> create mode 100644 drivers/platform/x86/lenovo/tlmi-auth.c
>
> diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
> index f1600b562273..6434e77f4ed3 100644
> --- a/drivers/platform/x86/lenovo/Makefile
> +++ b/drivers/platform/x86/lenovo/Makefile
> @@ -5,7 +5,7 @@
> #
> obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
> obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
> -obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
> +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o tlmi-auth.o
> obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>
> lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> index 75b21dcc2f42..6ab9a7e6fabf 100644
> --- a/drivers/platform/x86/lenovo/think-lmi.h
> +++ b/drivers/platform/x86/lenovo/think-lmi.h
> @@ -13,6 +13,7 @@
> #define TLMI_INDEX_MAX 32
>
> #define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
> +#define TLMI_AUTHENTICATION_GUID "5cb5f556-30ce-40d3-a135-7ca0648a5a52"
> #define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
>
> /* Possible error values */
> @@ -95,6 +96,7 @@ struct tlmi_pwdcfg {
> /* password setting details */
> struct tlmi_pwd_setting {
> struct kobject kobj;
> + struct wmi_device *wdev;
> bool pwd_enabled;
> char password[TLMI_PWD_BUFSIZE];
> const char *pwd_type;
> @@ -146,6 +148,7 @@ struct think_lmi {
> struct kset *attribute_kset;
> struct kset *authentication_kset;
> struct wmi_device *config_wdev;
> + struct wmi_device *auth_wdev;
>
> struct tlmi_pwdcfg pwdcfg;
> struct tlmi_pwd_setting *pwd_admin;
> @@ -153,6 +156,7 @@ struct think_lmi {
> struct tlmi_pwd_setting *pwd_system;
> struct tlmi_pwd_setting *pwd_hdd;
> struct tlmi_pwd_setting *pwd_nvme;
> + struct mutex tlmi_auth_lock; /* shared between auth and config */
>
> const struct tlmi_cert_guids *cert_guid;
> };
> @@ -162,5 +166,7 @@ struct component_match;
> void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
> void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
> +void tlmi_auth_match_add(struct device *master, struct component_match **matchptr);
> +int tlmi_auth_authenticate_user(struct think_lmi *td);
>
> #endif /* !_THINK_LMI_H_ */
> diff --git a/drivers/platform/x86/lenovo/tlmi-auth.c b/drivers/platform/x86/lenovo/tlmi-auth.c
> new file mode 100644
> index 000000000000..d18cf6390663
> --- /dev/null
> +++ b/drivers/platform/x86/lenovo/tlmi-auth.c
> @@ -0,0 +1,958 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Lenovo ThinkLMI Authentication WMI interface driver.
> + *
> + * Manage the WMI authentication settings and their properties.
> + *
> + * This driver supports the "Common WMI" approach implemented on
> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> + */
> +
> +#include <linux/component.h>
> +#include <linux/device.h>
> +#include <linux/dmi.h>
> +#include <linux/kdev_t.h>
> +#include <linux/kobject.h>
> +#include <linux/limits.h>
> +#include <linux/module.h>
> +#include <linux/string_helpers.h>
> +#include <linux/types.h>
> +#include <linux/wmi.h>
> +#include "think-lmi.h"
> +#include "wmi-helpers.h"
> +
> +#define MAX_HDD_INDEX 4
> +#define MAX_NVME_INDEX 8
> +
> +enum pwd_type_v2 {
> + SVP = 0,
> + SMP = 1,
> + POP = 2,
> + HDD = 3, /* 3 to 6 */
> + NVME = HDD + MAX_HDD_INDEX, /* 7 to 14 */
> + MASTERHDD = NVME + MAX_NVME_INDEX, /* 15 to 18 */
> + MASTERNVME = MASTERHDD + MAX_HDD_INDEX, /* 19 to 26 */
> +};
> +
> +/* Method IDS for Access GUID */
> +#define SET_PASSWORD 1
> +#define AUTHENTICATE 2
> +#define SET_CERT 3
> +#define UPDATE_CERT 4
> +#define CLEAR_CERT 5
> +#define CERT_TO_PWD 6
> +#define CERT_THUMBPRINT 7
> +
> +#define TLMI_POP_PWD BIT(0) /* Power-on */
> +#define TLMI_SVP_PWD BIT(1) /* Supervisor */
> +#define TLMI_SMP_PWD BIT(2) /* System Management */
> +#define TLMI_SVC_PWD BIT(7) /* Supervisor Certificate */
> +#define TLMI_SMC_PWD BIT(8) /* System Certificate */
> +
> +static const char * const level_options[] = {
> + [TLMI_LEVEL_USER] = "user",
> + [TLMI_LEVEL_MASTER] = "master",
> +};
> +
> +int tlmi_auth_authenticate_user(struct think_lmi *td)
> +{
> + struct wmi_buffer wmibuf;
> + char *password;
> + int ret;
> +
> + lockdep_assert_held(&td->tlmi_auth_lock);
> +
> + /* If certificate used, we use signatures not passwords*/
> + if (td->pwd_admin->cert_installed ||
> + td->pwd_system->cert_installed)
> + return 0;
> +
> + /* If admin password configured, use that. If not try system */
> + if (strlen(td->pwd_admin->password) > 0)
> + password = td->pwd_admin->password;
> + else if (strlen(td->pwd_system->password) > 0)
> + password = td->pwd_system->password;
> + else
> + /* No password configured, so no need to run authentication */
> + return 0;
> +
> + wmibuf.length = struct_size_t(struct wmi_string, chars, strlen(password) + 1);
> + char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
> + if (!wmidata)
> + return -ENOMEM;
> + wmibuf.data = wmidata;
> +
> + ret = tlmi_populate_string_buffer(wmibuf.data, wmibuf.length, password);
> + if (ret < 0)
> + return ret;
> +
> + return tlmi_request(td->auth_wdev, 0, AUTHENTICATE, &wmibuf);
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_auth_authenticate_user, "TLMI-AUTH");
> +
> +/* ---- Authentication sysfs ---- */
> +static inline struct tlmi_pwd_setting *to_tlmi_pwd_setting(struct kobject *kobj)
> +{
> + return container_of(kobj, struct tlmi_pwd_setting, kobj);
> +}
> +
> +static ssize_t is_enabled_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + return sysfs_emit(buf, "%d\n", setting->pwd_enabled || setting->cert_installed);
> +}
> +
> +static struct kobj_attribute auth_is_pass_set = __ATTR_RO(is_enabled);
> +
> +static ssize_t current_password_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + size_t pwdlen;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + /* Strip newline; setting password won't work if one is present. */
> + pwdlen = strchrnul(buf, '\n') - buf;
Only the last LF can be stripped. If you'd really want to handle LF in
between, return -EINVAL.
> + /* pwdlen == 0 is allowed to clear the password */
> + if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
> + return -EINVAL;
Could you factor out a helper function for the sanity checks of password
string? You are replicating mostly the same code below.
> +
> + strscpy(setting->password, buf, pwdlen + 1);
> + return count;
> +}
> +
> +static struct kobj_attribute auth_current_password = __ATTR_WO(current_password);
> +
> +static ssize_t new_password_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + enum pwd_type_v2 pwd_type;
> + size_t pwdlen, cur_pwdlen;
> + struct wmi_buffer wmibuf;
> + char *start;
> + int ix = 0;
> + int ret;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + /* Authorisation needs to be done first */
> + ret = tlmi_auth_authenticate_user(td);
> + /* Ignore most errors. We might be in deployment mode */
Could you add a dev_warn/info/dbg() when something is ignored?
> + if (ret == -ENOMEM)
> + return ret;
> +
> + /* Strip out CR if one is present, setting password won't work if it is present */
> + char *new_pwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
Only the last LF can be stripped, too.
I believe v2 will have a considerable amount of changes, so my review
will pause here. I will wait until your v2 to restart reviewing.
Thanks,
Rong
> + if (!new_pwd)
> + return -ENOMEM;
> +
> + pwdlen = strlen(new_pwd);
> + /* pwdlen == 0 is allowed to clear the password */
> + if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
> + return -EINVAL;
> +
> + cur_pwdlen = struct_size_t(struct wmi_string, chars, strlen(setting->password) + 1);
> + pwdlen = struct_size_t(struct wmi_string, chars, strlen(new_pwd) + 1);
> + wmibuf.length = 2 + cur_pwdlen + pwdlen;
> + char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
> + if (!wmidata)
> + return -ENOMEM;
> + wmibuf.data = wmidata;
> +
> + if (setting == td->pwd_admin) {
> + pwd_type = SVP;
> + } else if (setting == td->pwd_power) {
> + pwd_type = POP;
> + } else if (setting == td->pwd_system) {
> + pwd_type = SMP;
> + } else if (setting == td->pwd_hdd) {
> + if (setting->level == TLMI_LEVEL_MASTER)
> + pwd_type = MASTERHDD;
> + else
> + pwd_type = HDD;
> + pwd_type += setting->index - 1;
> + } else if (setting == td->pwd_nvme) {
> + if (setting->level == TLMI_LEVEL_MASTER)
> + pwd_type = MASTERNVME;
> + else
> + pwd_type = NVME;
> + pwd_type += setting->index - 1;
> + } else {
> + return -EOPNOTSUPP;
> + }
> +
> + start = wmibuf.data;
> + start[0] = pwd_type;
> + start += 2;
> +
> + ix = tlmi_populate_string_buffer(start, cur_pwdlen, setting->password);
> + if (ix < 0)
> + return ix;
> + start += ix;
> + ix = tlmi_populate_string_buffer(start, pwdlen, new_pwd);
> + if (ix < 0)
> + return ix;
> +
> + ret = tlmi_request(td->auth_wdev, 0, SET_PASSWORD, &wmibuf);
> + return ret ?: count;
> +}
> +
> +static struct kobj_attribute auth_new_password = __ATTR_WO(new_password);
> +
> +static ssize_t min_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + return sysfs_emit(buf, "%d\n", setting->minlen);
> +}
> +
> +static struct kobj_attribute auth_min_pass_length = __ATTR_RO(min_password_length);
> +
> +static ssize_t max_password_length_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + return sysfs_emit(buf, "%d\n", setting->maxlen);
> +}
> +
> +static struct kobj_attribute auth_max_pass_length = __ATTR_RO(max_password_length);
> +
> +static ssize_t mechanism_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + if (setting->cert_installed)
> + return sysfs_emit(buf, "certificate\n");
> + return sysfs_emit(buf, "password\n");
> +}
> +
> +static struct kobj_attribute auth_mechanism = __ATTR_RO(mechanism);
> +
> +static ssize_t role_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + return sysfs_emit(buf, "%s\n", setting->role);
> +}
> +
> +static struct kobj_attribute auth_role = __ATTR_RO(role);
> +
> +static ssize_t index_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + return sysfs_emit(buf, "%d\n", setting->index);
> +}
> +
> +static ssize_t index_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + int err, val, max;
> +
> + err = kstrtoint(buf, 10, &val);
> + if (err < 0)
> + return err;
> +
> + if (setting == td->pwd_hdd)
> + max = MAX_HDD_INDEX;
> + else if (setting == td->pwd_nvme)
> + max = MAX_NVME_INDEX;
> + else
> + return -EOPNOTSUPP;
> +
> + if (val <= 0 || val > max)
> + return -EINVAL;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> + setting->index = val;
> + return count;
> +}
> +
> +static struct kobj_attribute auth_index = __ATTR_RW(index);
> +
> +static ssize_t level_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + return sysfs_emit(buf, "%s\n", level_options[setting->level]);
> +}
> +
> +static ssize_t level_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + int i;
> +
> + /* Scan for a matching profile */
> + i = sysfs_match_string(level_options, buf);
> + if (i < 0)
> + return -EINVAL;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> + setting->level = i;
> + return count;
> +}
> +
> +static struct kobj_attribute auth_level = __ATTR_RW(level);
> +
> +static char *thumbtypes[] = {"SHA1", "SHA256", "SHA384", "SHA512", "MD5"};
> +#define MAX_SHA_LEN 513
> +
> +static ssize_t cert_thumbprint(char *buf, char *type, unsigned char alg, int *count,
> + struct think_lmi *td)
> +{
> + struct wmi_buffer wmibuf, wmibuf_thumb;
> + int ix, ret;
> + char *start;
> +
> + if (!type)
> + return -EINVAL;
> +
> + wmibuf.length = struct_size_t(struct wmi_string, chars, strlen(type) + 2);
> + char *wmidata __free(kfree) = kzalloc(wmibuf.length, GFP_KERNEL);
> + if (!wmidata)
> + return -ENOMEM;
> + wmibuf.data = wmidata;
> +
> + char *thumbstr __free(kfree) = kzalloc(MAX_SHA_LEN, GFP_KERNEL);
> + if (!thumbstr)
> + return -ENOMEM;
> +
> + start = wmibuf.data;
> + ix = tlmi_populate_string_buffer(start, wmibuf.length, type);
> + if (ix < 0)
> + return ix;
> + start += ix;
> + *start = alg;
> +
> + ret = wmidev_invoke_method(td->auth_wdev, 0, CERT_THUMBPRINT, &wmibuf, &wmibuf_thumb,
> + sizeof(struct wmi_string));
> + if (ret < 0)
> + return ret;
> +
> + if (wmibuf_thumb.data) {
> + /* Check for valid string */
> + if (wmibuf_thumb.length < 2 || wmibuf_thumb.length > MAX_SHA_LEN * 2)
> + ret = -EINVAL;
> + else
> + /* Extract thumbprint */
> + ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_thumb.data,
> + thumbstr, MAX_SHA_LEN);
> + kfree(wmibuf_thumb.data);
> + if (ret > 0)
> + *count += sysfs_emit_at(buf, *count, "%s : %s\n",
> + thumbtypes[alg], thumbstr);
> + }
> +
> + return ret;
> +}
> +
> +static ssize_t certificate_thumbprint_show(struct kobject *kobj, struct kobj_attribute *attr,
> + char *buf)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + unsigned int i;
> + int ret, count = 0;
> +
> + if (!setting->cert_installed)
> + return -EOPNOTSUPP;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + for (i = 0; i < ARRAY_SIZE(thumbtypes); i++) {
> + ret = cert_thumbprint(buf, setting == td->pwd_admin ? "SVC" : "SMC",
> + i, &count, td);
> + if (ret < 0)
> + return ret;
> + }
> +
> + return count;
> +}
> +
> +static struct kobj_attribute auth_cert_thumb = __ATTR_RO(certificate_thumbprint);
> +
> +static ssize_t cert_to_password_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + size_t typelen, pwdlen, siglen;
> + char *start, *cert_type;
> + struct wmi_buffer wmibuf;
> + int ret = -EINVAL;
> + int ix;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + if (!setting->cert_installed)
> + return -EINVAL;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + if (!setting->signature || !setting->signature[0])
> + return -EACCES;
> +
> + /* Strip out CR if one is present */
> + char *passwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> + if (!passwd)
> + return -ENOMEM;
> +
> + cert_type = (setting == td->pwd_admin) ? "SVC" : "SMC";
> + typelen = struct_size_t(struct wmi_string, chars, strlen(cert_type) + 1);
> + pwdlen = struct_size_t(struct wmi_string, chars, strlen(passwd) + 1);
> + siglen = struct_size_t(struct wmi_string, chars, strlen(setting->signature) + 1);
> + wmibuf.length = typelen + pwdlen + siglen;
> +
> + char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
> + if (!wmidata)
> + return -ENOMEM;
> + wmibuf.data = wmidata;
> +
> + start = wmibuf.data;
> + ix = tlmi_populate_string_buffer(start, typelen, cert_type);
> + if (ix < 0)
> + return ix;
> +
> + start += ix;
> + ix = tlmi_populate_string_buffer(start, pwdlen, passwd);
> + if (ix < 0)
> + return ix;
> +
> + start += ix;
> + ix = tlmi_populate_string_buffer(start, siglen, setting->signature);
> + if (ix < 0)
> + return ix;
> +
> + ret = tlmi_request(td->auth_wdev, 0, CERT_TO_PWD, &wmibuf);
> +
> + return ret ?: count;
> +}
> +
> +static struct kobj_attribute auth_cert_to_password = __ATTR_WO(cert_to_password);
> +
> +static ssize_t certificate_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + struct tlmi_pwd_setting *pwd_admin = td->pwd_admin;
> + size_t typelen, certlen, pwdlen, siglen, seriallen;
> + struct wmi_buffer wmibuf;
> + char *start;
> + char *signature, *cert_type;
> + int install_mode = SET_CERT;
> + const char *serial;
> + int ix = 0;
> + int ret;
> +
> + char *new_cert __free(kfree_sensitive) = NULL;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + cert_type = (setting == pwd_admin) ? "SVC" : "SMC";
> + typelen = struct_size_t(struct wmi_string, chars, strlen(cert_type) + 1);
> +
> + if ((buf[0] == '\0') || (buf[0] == '\n')) {
> + /*
> + * Clear installed certificate
> + * Format: 'Type, serial#, signature'
> + */
> +
> + /* Check that signature is set */
> + if (!setting->signature || !setting->signature[0])
> + return -EACCES;
> +
> + install_mode = CLEAR_CERT;
> + serial = dmi_get_system_info(DMI_PRODUCT_SERIAL);
> + if (!serial)
> + return -ENODEV;
> + seriallen = struct_size_t(struct wmi_string, chars, strlen(serial) + 1);
> + signature = setting->signature;
> + siglen = struct_size_t(struct wmi_string, chars, strlen(signature) + 1);
> + wmibuf.length = typelen + seriallen + siglen;
> + } else {
> + /* New install, or update */
> + /* Strip out CR from certificate if one is present */
> + new_cert = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> + if (!new_cert)
> + return -ENOMEM;
> + certlen = struct_size_t(struct wmi_string, chars, strlen(new_cert) + 1);
> +
> + if (setting->cert_installed) {
> + /*
> + * Update installed certificate
> + * Format: 'Type, Certificate, signature'
> + */
> + install_mode = UPDATE_CERT;
> + /* If admin account enabled - need to use its signature */
> + if (pwd_admin && pwd_admin->pwd_enabled)
> + signature = pwd_admin->signature;
> + else
> + signature = setting->signature;
> + if (!signature)
> + return -EINVAL;
> +
> + siglen = struct_size_t(struct wmi_string, chars, strlen(signature) + 1);
> + wmibuf.length = typelen + certlen + siglen;
> + } else {
> + /*
> + * Install a new certificate
> + * Format: 'Type, Certificate, Password'
> + */
> + install_mode = SET_CERT;
> + /* To set admin cert, a password must be enabled */
> + if (setting == pwd_admin &&
> + (!setting->pwd_enabled || !setting->password[0]))
> + return -EACCES;
> +
> + pwdlen = struct_size_t(struct wmi_string, chars,
> + strlen(setting->password) + 1);
> + wmibuf.length = typelen + certlen + pwdlen;
> + }
> + }
> +
> + /* Set up WMI buffer */
> + char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
> + if (!wmidata)
> + return -ENOMEM;
> + wmibuf.data = wmidata;
> +
> + start = wmibuf.data;
> + ix = tlmi_populate_string_buffer(start, typelen, cert_type);
> + if (ix < 0)
> + return ix;
> +
> + start += ix;
> + if (install_mode == CLEAR_CERT)
> + ix = tlmi_populate_string_buffer(start, seriallen, serial);
> + else
> + ix = tlmi_populate_string_buffer(start, certlen, new_cert);
> + if (ix < 0)
> + return ix;
> +
> + start += ix;
> + if (install_mode == SET_CERT)
> + ix = tlmi_populate_string_buffer(start, pwdlen, setting->password);
> + else
> + ix = tlmi_populate_string_buffer(start, siglen, signature);
> + if (ix < 0)
> + return ix;
> +
> + ret = tlmi_request(td->auth_wdev, 0, install_mode, &wmibuf);
> +
> + return ret ?: count;
> +}
> +
> +static struct kobj_attribute auth_certificate = __ATTR_WO(certificate);
> +
> +static ssize_t signature_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + char *new_signature;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + /* Strip out CR if one is present */
> + new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> + if (!new_signature)
> + return -ENOMEM;
> +
> + /* Free any previous signature */
> + kfree_sensitive(setting->signature);
> + setting->signature = new_signature;
> +
> + return count;
> +}
> +
> +static struct kobj_attribute auth_signature = __ATTR_WO(signature);
> +
> +static ssize_t save_signature_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> + char *new_signature;
> +
> + if (!capable(CAP_SYS_ADMIN))
> + return -EPERM;
> +
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + /* Strip out CR if one is present */
> + new_signature = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> + if (!new_signature)
> + return -ENOMEM;
> +
> + /* Free any previous signature */
> + kfree_sensitive(setting->save_signature);
> + setting->save_signature = new_signature;
> +
> + return count;
> +}
> +
> +static struct kobj_attribute auth_save_signature = __ATTR_WO(save_signature);
> +
> +static umode_t auth_attr_is_visible(struct kobject *kobj,
> + struct attribute *attr, int n)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> +
> + /* We only want to display level and index settings on HDD/NVMe */
> + if (attr == &auth_index.attr || attr == &auth_level.attr) {
> + if (setting == td->pwd_hdd || setting == td->pwd_nvme)
> + return attr->mode;
> + return 0;
> + }
> +
> + return attr->mode;
> +}
> +
> +static struct attribute *auth_attrs[] = {
> + &auth_is_pass_set.attr,
> + &auth_min_pass_length.attr,
> + &auth_max_pass_length.attr,
> + &auth_current_password.attr,
> + &auth_new_password.attr,
> + &auth_role.attr,
> + &auth_mechanism.attr,
> + &auth_index.attr,
> + &auth_level.attr,
> + &auth_certificate.attr,
> + &auth_signature.attr,
> + &auth_save_signature.attr,
> + &auth_cert_thumb.attr,
> + &auth_cert_to_password.attr,
> + NULL
> +};
> +
> +static const struct attribute_group auth_attr_group = {
> + .is_visible = auth_attr_is_visible,
> + .attrs = auth_attrs,
> +};
> +__ATTRIBUTE_GROUPS(auth_attr);
> +
> +static void tlmi_pwd_setting_release(struct kobject *kobj)
> +{
> + struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
> +
> + kfree_sensitive(setting->save_signature);
> + kfree_sensitive(setting->signature);
> + kfree_sensitive(setting);
> +}
> +
> +static const struct kobj_type tlmi_pwd_setting_ktype = {
> + .release = &tlmi_pwd_setting_release,
> + .sysfs_ops = &kobj_sysfs_ops,
> + .default_groups = auth_attr_groups,
> +};
> +
> +static void tlmi_auth_sysfs_release(struct think_lmi *td)
> +{
> + struct kobject *pos, *n;
> +
> + if (!td || !td->authentication_kset)
> + return;
> +
> + /* Authentication structures */
> + list_for_each_entry_safe(pos, n, &td->authentication_kset->list, entry)
> + kobject_put(pos);
> +
> + kset_unregister(td->authentication_kset);
> +
> + /* Prevent dangling pointers */
> + td->authentication_kset = NULL;
> + td->pwd_admin = NULL;
> + td->pwd_system = NULL;
> + td->pwd_power = NULL;
> + td->pwd_hdd = NULL;
> + td->pwd_nvme = NULL;
> +}
> +
> +static int tlmi_auth_sysfs_init(struct think_lmi *td)
> +{
> + int ret;
> +
> + if (!td)
> + return -EINVAL;
> +
> + /* Create authentication entries */
> + td->authentication_kset = kset_create_and_add("authentication", NULL,
> + &td->class_dev->kobj);
> + if (!td->authentication_kset) {
> + ret = -ENOMEM;
> + goto out_admin_fail;
> + }
> +
> + td->pwd_admin->kobj.kset = td->authentication_kset;
> + ret = kobject_init_and_add(&td->pwd_admin->kobj, &tlmi_pwd_setting_ktype,
> + NULL, "%s", "Admin");
> + if (ret)
> + goto out_admin_fail;
> +
> + td->pwd_power->kobj.kset = td->authentication_kset;
> + ret = kobject_init_and_add(&td->pwd_power->kobj, &tlmi_pwd_setting_ktype,
> + NULL, "%s", "Power-on");
> + if (ret)
> + goto out_power_fail;
> +
> + td->pwd_system->kobj.kset = td->authentication_kset;
> + ret = kobject_init_and_add(&td->pwd_system->kobj, &tlmi_pwd_setting_ktype,
> + NULL, "%s", "System");
> + if (ret)
> + goto out_system_fail;
> +
> + td->pwd_hdd->kobj.kset = td->authentication_kset;
> + ret = kobject_init_and_add(&td->pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
> + NULL, "%s", "HDD");
> + if (ret)
> + goto out_hdd_fail;
> +
> + td->pwd_nvme->kobj.kset = td->authentication_kset;
> + ret = kobject_init_and_add(&td->pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
> + NULL, "%s", "NVMe");
> + if (ret)
> + goto out_nvme_fail;
> +
> + return 0;
> +
> +out_admin_fail:
> + kobject_put(&td->pwd_admin->kobj);
> + td->pwd_admin = NULL;
> +out_power_fail:
> + kobject_put(&td->pwd_power->kobj);
> + td->pwd_power = NULL;
> +out_system_fail:
> + kobject_put(&td->pwd_system->kobj);
> + td->pwd_system = NULL;
> +out_hdd_fail:
> + kobject_put(&td->pwd_hdd->kobj);
> + td->pwd_hdd = NULL;
> +out_nvme_fail:
> + kobject_put(&td->pwd_nvme->kobj);
> + td->pwd_nvme = NULL;
> + return ret;
> +}
> +
> +static int tlmi_create_auth(struct think_lmi *td,
> + const char *pwd_role,
> + struct tlmi_pwd_setting **setting)
> +{
> + struct tlmi_pwd_setting *new_pwd;
> +
> + new_pwd = kzalloc_obj(*new_pwd);
> + if (!new_pwd)
> + return -ENOMEM;
> +
> + new_pwd->role = pwd_role;
> + new_pwd->minlen = td->pwdcfg.core.min_length;
> + new_pwd->maxlen = td->pwdcfg.core.max_length;
> + new_pwd->index = 1;
> + new_pwd->level = TLMI_LEVEL_MASTER;
> + new_pwd->wdev = td->auth_wdev;
> +
> + *setting = new_pwd;
> + return 0;
> +}
> +
> +static int tlmi_auth_setup(struct think_lmi *td)
> +{
> + struct tlmi_pwd_setting *admin __free(kfree) = NULL;
> + struct tlmi_pwd_setting *power __free(kfree) = NULL;
> + struct tlmi_pwd_setting *system __free(kfree) = NULL;
> + struct tlmi_pwd_setting *hdd __free(kfree) = NULL;
> + struct tlmi_pwd_setting *nvme __free(kfree) = NULL;
> + unsigned int index;
> + int ret;
> +
> + if (!td)
> + return -EINVAL;
> +
> + ret = tlmi_create_auth(td, "bios-admin", &admin);
> + if (ret)
> + return ret;
> +
> + ret = tlmi_create_auth(td, "power-on", &power);
> + if (ret)
> + return ret;
> +
> + ret = tlmi_create_auth(td, "system", &system);
> + if (ret)
> + return ret;
> +
> + ret = tlmi_create_auth(td, "hdd", &hdd);
> + if (ret)
> + return ret;
> +
> + ret = tlmi_create_auth(td, "nvme", &nvme);
> + if (ret)
> + return ret;
> +
> + td->pwd_admin = no_free_ptr(admin);
> + td->pwd_power = no_free_ptr(power);
> + td->pwd_system = no_free_ptr(system);
> + td->pwd_hdd = no_free_ptr(hdd);
> + td->pwd_nvme = no_free_ptr(nvme);
> +
> + if (td->pwdcfg.core.password_state & TLMI_SVP_PWD)
> + td->pwd_admin->pwd_enabled = true;
> +
> + if (td->pwdcfg.core.password_state & TLMI_POP_PWD)
> + td->pwd_power->pwd_enabled = true;
> +
> + if (td->pwdcfg.core.password_state & TLMI_SMP_PWD)
> + td->pwd_system->pwd_enabled = true;
> +
> + if (td->pwdcfg.core.password_state & TLMI_SVC_PWD)
> + td->pwd_admin->cert_installed = true;
> + if (td->pwdcfg.core.password_state & TLMI_SMC_PWD)
> + td->pwd_system->cert_installed = true;
> +
> + if (td->pwdcfg.ext.hdd_user_password ||
> + td->pwdcfg.ext.hdd_master_password) {
> + td->pwd_hdd->pwd_enabled = true;
> + if (td->pwdcfg.ext.hdd_master_password)
> + index = ffs(td->pwdcfg.ext.hdd_master_password);
> + else
> + index = ffs(td->pwdcfg.ext.hdd_user_password);
> + /* Sanitize result */
> + if (index > MAX_HDD_INDEX || !index) {
> + pr_info("tlmi-auth: Invalid HDD password index %u. Setting to %d\n",
> + index, MAX_HDD_INDEX);
> + index = MAX_HDD_INDEX;
> + }
> + td->pwd_hdd->index = index;
> + }
> +
> + if (td->pwdcfg.ext.nvme_user_password ||
> + td->pwdcfg.ext.nvme_master_password) {
> + td->pwd_nvme->pwd_enabled = true;
> + if (td->pwdcfg.ext.nvme_master_password)
> + index = ffs(td->pwdcfg.ext.nvme_master_password);
> + else
> + index = ffs(td->pwdcfg.ext.nvme_user_password);
> + /* Sanitize result */
> + if (index > MAX_NVME_INDEX || !index) {
> + pr_info("tlmi-auth: Invalid NVME password index %d. Setting to %d\n",
> + index, MAX_NVME_INDEX);
> + index = MAX_NVME_INDEX;
> + }
> + td->pwd_nvme->index = index;
> + }
> +
> + mutex_init(&td->tlmi_auth_lock);
> +
> + return ret;
> +}
> +
> +static int tlmi_auth_component_bind(struct device *auth_dev, struct device *config_dev,
> + void *d)
> +{
> + struct think_lmi *td = d;
> + int ret;
> +
> + td->auth_wdev = to_wmi_device(auth_dev);
> + dev_set_drvdata(&td->auth_wdev->dev, td);
> +
> + ret = tlmi_auth_setup(td);
> + if (ret)
> + return ret;
> +
> + ret = tlmi_auth_sysfs_init(td);
> + if (ret)
> + tlmi_auth_sysfs_release(td);
> + return ret;
> +}
> +
> +static void tlmi_auth_component_unbind(struct device *auth_dev, struct device *cfg_dev, void *d)
> +{
> + struct think_lmi *td = d;
> +
> + tlmi_auth_sysfs_release(td);
> +}
> +
> +static const struct component_ops tlmi_auth_component_ops = {
> + .bind = tlmi_auth_component_bind,
> + .unbind = tlmi_auth_component_unbind,
> +};
> +
> +static int tlmi_auth_probe(struct wmi_device *wdev, const void *context)
> +{
> + return component_add(&wdev->dev, &tlmi_auth_component_ops);
> +}
> +
> +static void tlmi_auth_remove(struct wmi_device *wdev)
> +{
> + component_del(&wdev->dev, &tlmi_auth_component_ops);
> +}
> +
> +static const struct wmi_device_id tlmi_auth_id_table[] = {
> + { TLMI_AUTHENTICATION_GUID, NULL },
> + {}
> +};
> +
> +static struct wmi_driver tlmi_auth_driver = {
> + .driver = {
> + .name = "tlmi-auth",
> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> + },
> + .id_table = tlmi_auth_id_table,
> + .probe = tlmi_auth_probe,
> + .remove = tlmi_auth_remove,
> + .no_singleton = true,
> +};
> +
> +static int tlmi_auth_match(struct device *dev, void *type)
> +{
> + return (dev->driver == &tlmi_auth_driver.driver);
> +}
> +
> +void tlmi_auth_match_add(struct device *master, struct component_match **matchptr)
> +{
> + component_match_add(master, matchptr, tlmi_auth_match, NULL);
> +}
> +EXPORT_SYMBOL_NS_GPL(tlmi_auth_match_add, "TLMI-AUTH");
> +
> +module_wmi_driver(tlmi_auth_driver);
> +
> +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
> +MODULE_DEVICE_TABLE(wmi, tlmi_auth_id_table);
> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> +MODULE_DESCRIPTION("ThinkLMI Authentication WMI Driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> index bb9c5f720c24..702e6754fcb4 100644
> --- a/drivers/platform/x86/lenovo/tlmi-config.c
> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> @@ -50,7 +50,7 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
> {
> char *new_setting __free(kfree) = NULL;
> char *wmidata __free(kfree) = NULL;
> - size_t namelen, valuelen;
> + size_t namelen, valuelen, siglen;
> struct wmi_buffer wmibuf;
> char *start;
> int ix = 0;
> @@ -64,10 +64,17 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
> if (!new_setting)
> return -ENOMEM;
>
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> /* Calculate and alloc buffer for command string */
> namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
> valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
> - wmibuf.length = namelen + valuelen;
> + if (td->pwd_admin && td->pwd_admin->signature)
> + siglen = struct_size_t(struct wmi_string, chars,
> + strlen(td->pwd_admin->signature) + 1);
> + else
> + siglen = struct_size_t(struct wmi_string, chars, 1 + 1);
> + wmibuf.length = namelen + valuelen + siglen;
> wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
> wmibuf.data = wmidata;
> if (!wmibuf.data)
> @@ -83,6 +90,14 @@ static ssize_t common_current_value_store(char *name, const char *buf, int wmi_i
> ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
> if (ix < 0)
> return ix;
> + start += ix;
> + if (td->pwd_admin && td->pwd_admin->signature)
> + ix = tlmi_populate_string_buffer(start, siglen,
> + td->pwd_admin->signature);
> + else
> + ix = tlmi_populate_string_buffer(start, siglen, "\0");
> + if (ix < 0)
> + return ix;
>
> return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
> }
> @@ -209,8 +224,10 @@ static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *
> const char *buf, size_t count)
> {
> struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> + struct tlmi_pwd_setting *pwd_admin = td->pwd_admin;
> char *wmidata __free(kfree) = NULL;
> struct wmi_buffer wmibuf;
> + size_t siglen;
> int ret = 0;
>
> /* save command triggered by writing 'save' */
> @@ -224,13 +241,30 @@ static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *
> if (!td->save_required)
> return -ENOENT;
>
> - wmibuf.length = struct_size_t(struct wmi_string, chars, 1 + 1);
> + guard(mutex)(&td->tlmi_auth_lock);
> +
> + /* Authorisation (if needed) is done just before save */
> + ret = tlmi_auth_authenticate_user(td);
> + /* Ignore most errors. We might be in deployment mode */
> + if (ret == -ENOMEM)
> + return ret;
> +
> + if (td->pwd_admin && td->pwd_admin->save_signature)
> + siglen = struct_size_t(struct wmi_string, chars,
> + strlen(td->pwd_admin->save_signature) + 1);
> + else
> + siglen = struct_size_t(struct wmi_string, chars, 1 + 1);
> + wmibuf.length = siglen;
> wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
> wmibuf.data = wmidata;
> if (!wmibuf.data)
> return -ENOMEM;
>
> - ret = tlmi_populate_string_buffer(wmibuf.data, 1, "\0");
> + if (pwd_admin && pwd_admin->save_signature)
> + ret = tlmi_populate_string_buffer(wmibuf.data, wmibuf.length,
> + pwd_admin->save_signature);
> + else
> + ret = tlmi_populate_string_buffer(wmibuf.data, siglen, "\0");
> if (ret < 0)
> return ret;
>
> @@ -359,16 +393,18 @@ static const struct component_master_ops aggregate_ops = {
> static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> {
> struct component_match *match = NULL;
> - guid_t tlmi_attr_guid, tlmi_authdata_guid;
> + guid_t tlmi_attr_guid, tlmi_authdata_guid, tlmi_auth_guid;
> struct think_lmi *td;
> int ret;
>
> guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
> guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
> + guid_parse(TLMI_AUTHENTICATION_GUID, &tlmi_auth_guid);
>
> /* At minimum need to support BIOS and authentication settings */
> if (!wmidev_exists(&tlmi_attr_guid) ||
> - !wmidev_exists(&tlmi_authdata_guid))
> + !wmidev_exists(&tlmi_authdata_guid) ||
> + !wmidev_exists(&tlmi_auth_guid))
> return -EOPNOTSUPP;
>
> td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
> @@ -387,6 +423,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> /* Register the other components */
> tlmi_attr_match_add(&wdev->dev, &match);
> tlmi_authdata_match_add(&wdev->dev, &match);
> + tlmi_auth_match_add(&wdev->dev, &match);
>
> ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
> if (ret)
> @@ -424,6 +461,7 @@ module_wmi_driver(tlmi_config_driver);
> MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
> MODULE_IMPORT_NS("TLMI-ATTR");
> MODULE_IMPORT_NS("TLMI-AUTHDATA");
> +MODULE_IMPORT_NS("TLMI-AUTH");
> MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
> MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> MODULE_DESCRIPTION("TLMI Config WMI Driver");
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 00/13] New Lenovo common WMI driver - tlmi
2026-12-04 13:19 ` [PATCH 00/13] New Lenovo common WMI driver - tlmi Rong Zhang
@ 2026-12-04 14:42 ` Mark Pearson
2026-12-04 17:49 ` Rong Zhang
0 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 14:42 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:19 AM, Rong Zhang wrote:
> Hi Mark,
>
> Thanks for working on this.
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> This series introduces support for a new Lenovo 'common WMI'
>> implementation.
>>
>> The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
>> WMI methods for interfacing with the BIOS settings. This implementation
>> will be available for 2027 platforms and is intended to be common across
>> the business units.
>>
>> The new driver is called tlmi and can run alongside the existing
>> think-lmi driver. Initially the BIOS's will support both interfaces.
>>
>> The first 5 patches in the series update the existing think-lmi driver
>> with changes that means it can share structures with the new tlmi
>> driver. They also introduce fixes for issues I found when implementing
>> tlmi.
>> The remaining patches introduce the new tlmi functionality. I've tried
>> to break them up into reviewable chunks.
>>
>> The tlmi driver for now offers the same functionality as think-lmi -
>> with support for modifying BIOS settings and authentication options.
>> It also introduces 'platform' settings and 'function' settings.
>>
>> During implementation I needed some functionality to be common between
>> modules. Using the wmi-helpers module seemed a good place for this, but
>> please let me know if it's not suitable.
>>
>> Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
>> Thinkstation P5 G2.
>>
>> Much of this implementation builds on the recommendations from Armin,
>> Derek and Ilpo from the original RFC. Many thanks for the guidance.
>>
>> Mark Pearson (13):
>> platform/x86: lenovo: think-lmi: Convert name arrays to pointers
>> platform/x86: lenovo: think-lmi: Clean up attributes if not added to
>> list
>> platform/x86: lenovo: think-lmi: cache current value at init
>> platform/x86: lenovo: think-lmi: store attributes as linked list
>> platform/x86: lenovo: tlmi: New tlmi driver for common WMI
>> implementation
>> platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
>> platform/x86: lenovo: tlmi: Retrieve auth information
>> platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
>> platform/x86: lenovo: tlmi: Add authentication sysfs entries
>> platform/x86: lenovo: tlmi: Add platform attribute support
>> platform/x86: lenovo: tlmi: Add function attributes support
>> platform/x86: lenovo: tlmi: Add method identifier
>> docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
>
> Sashiko found quite a lot of issues in the series, so I am not going to
> seriously review this series yet, in case you'd need to change the design
> a lot in the next revision.
>
Yeah....that's going to keep me busy. They didn't show up in my inbox so I had to go looking for them.
I'd been running sashiko with a few tokens I managed to get through work and thought I had it at the stage where it was pretty clean (and I'd run out of tokens). Looks like some new things which is interesting.
> That being said, I will glance at each patch and see if I have some
> additional suggestions on the design.
>
Thanks - appreciate it - especially if I'm doing things incorrectly from a design perspective.
This whole feature turned out to be more of a beast than I expected.
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list
2026-12-04 13:20 ` Rong Zhang
@ 2026-12-04 15:09 ` Mark Pearson
0 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:09 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:20 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> If we fail to add an attribute to the attribute_kset list then it will not
>> get freed during the subsequent kobject_put.
>> Make sure to free resources before going ahead with the rest of the
>> cleanup.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/think-lmi.c | 87 ++++++++++++++++++-------
>> 1 file changed, 65 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
>> index c060a0a360ca..63ea212b4bda 100644
>> --- a/drivers/platform/x86/lenovo/think-lmi.c
>> +++ b/drivers/platform/x86/lenovo/think-lmi.c
>> @@ -1444,6 +1444,16 @@ static ssize_t debug_cmd_store(struct kobject *kobj, struct kobj_attribute *attr
>> static struct kobj_attribute debug_cmd = __ATTR_WO(debug_cmd);
>>
>> /* ---- Initialisation --------------------------------------------------------- */
>> +/* Utility function to free record when not in the attribute_kset list */
>> +static void tlmi_free_attr_record(int i)
>> +{
>> + kfree(tlmi_priv.setting[i]->name);
>> + kfree(tlmi_priv.setting[i]->display_name);
>> + kfree(tlmi_priv.setting[i]->possible_values);
>> + kfree(tlmi_priv.setting[i]);
>> + tlmi_priv.setting[i] = NULL;
>> +}
>> +
>> static void tlmi_release_attr(void)
>> {
>> struct kobject *pos, *n;
>> @@ -1461,8 +1471,10 @@ static void tlmi_release_attr(void)
>> kset_unregister(tlmi_priv.attribute_kset);
>>
>> /* Free up any saved signatures */
>> - kfree(tlmi_priv.pwd_admin->signature);
>> - kfree(tlmi_priv.pwd_admin->save_signature);
>> + if (tlmi_priv.pwd_admin) {
>> + kfree(tlmi_priv.pwd_admin->signature);
>> + kfree(tlmi_priv.pwd_admin->save_signature);
>> + }
>> if (tlmi_priv.pwd_system) {
>> kfree(tlmi_priv.pwd_system->signature);
>> kfree(tlmi_priv.pwd_system->save_signature);
>> @@ -1495,8 +1507,9 @@ static int tlmi_validate_setting_name(struct kset *attribute_kset, char *name)
>>
>> static int tlmi_sysfs_init(void)
>> {
>> - int i, ret;
>> + int i, ret = 0, auth_ret = 0;
>>
>> + guard(mutex)(&tlmi_mutex);
>
> It'd better to add a comment explaining what's serialized during
> initialization (gating attribute access?).
>
>> tlmi_priv.class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
>> NULL, "%s", "thinklmi");
>> if (IS_ERR(tlmi_priv.class_dev)) {
>> @@ -1524,14 +1537,15 @@ static int tlmi_sysfs_init(void)
>> if (!tlmi_priv.setting[i])
>> continue;
>>
>> + if (ret) { /* We had a critical failure. Just clean up */
>> + tlmi_free_attr_record(i);
>> + continue;
>> + }
>> +
>> /* check for duplicate or reserved values */
>> if (tlmi_validate_setting_name(tlmi_priv.attribute_kset,
>> tlmi_priv.setting[i]->display_name) < 0) {
>> - kfree(tlmi_priv.setting[i]->name);
>> - kfree(tlmi_priv.setting[i]->display_name);
>> - kfree(tlmi_priv.setting[i]->possible_values);
>> - kfree(tlmi_priv.setting[i]);
>> - tlmi_priv.setting[i] = NULL;
>> + tlmi_free_attr_record(i);
>> continue;
>> }
>>
>> @@ -1539,9 +1553,14 @@ static int tlmi_sysfs_init(void)
>> tlmi_priv.setting[i]->kobj.kset = tlmi_priv.attribute_kset;
>> ret = kobject_init_and_add(&tlmi_priv.setting[i]->kobj, &tlmi_attr_setting_ktype,
>> NULL, "%s", tlmi_priv.setting[i]->display_name);
>> - if (ret)
>> - goto fail_create_attr;
>> + if (ret) {
>> + kobject_put(&tlmi_priv.setting[i]->kobj);
>> + continue; /* use loop to clear remaining items */
>> + }
>> }
>> + /* Check if we had an error during the attribute creations */
>> + if (ret)
>> + goto fail_create_attr;
>>
>> ret = sysfs_create_file(&tlmi_priv.attribute_kset->kobj, &pending_reboot.attr);
>> if (ret)
>> @@ -1561,39 +1580,63 @@ static int tlmi_sysfs_init(void)
>> tlmi_priv.pwd_admin->kobj.kset = tlmi_priv.authentication_kset;
>> ret = kobject_init_and_add(&tlmi_priv.pwd_admin->kobj, &tlmi_pwd_setting_ktype,
>> NULL, "%s", "Admin");
>> - if (ret)
>> - goto fail_create_attr;
>> -
>> + if (ret) {
>> + kobject_put(&tlmi_priv.pwd_admin->kobj);
>> + tlmi_priv.pwd_admin = NULL;
>> + auth_ret = ret;
>> + }
>
> Let's factor out a helper function like:
>
> kobj.kset = ...
> ret = kobject_init_and_add();
> if (ret) {
> ...
> }
>
>> tlmi_priv.pwd_power->kobj.kset = tlmi_priv.authentication_kset;
>> ret = kobject_init_and_add(&tlmi_priv.pwd_power->kobj, &tlmi_pwd_setting_ktype,
>> NULL, "%s", "Power-on");
>> - if (ret)
>> - goto fail_create_attr;
>> + if (ret) {
>> + kobject_put(&tlmi_priv.pwd_power->kobj);
>> + tlmi_priv.pwd_power = NULL;
>> + auth_ret = ret;
>> + }
>>
>> if (tlmi_priv.opcode_support) {
>> tlmi_priv.pwd_system->kobj.kset = tlmi_priv.authentication_kset;
>> ret = kobject_init_and_add(&tlmi_priv.pwd_system->kobj, &tlmi_pwd_setting_ktype,
>> NULL, "%s", "System");
>> - if (ret)
>> - goto fail_create_attr;
>> + if (ret) {
>> + kobject_put(&tlmi_priv.pwd_system->kobj);
>> + tlmi_priv.pwd_system = NULL;
>> + auth_ret = ret;
>> + }
>>
>> tlmi_priv.pwd_hdd->kobj.kset = tlmi_priv.authentication_kset;
>> ret = kobject_init_and_add(&tlmi_priv.pwd_hdd->kobj, &tlmi_pwd_setting_ktype,
>> NULL, "%s", "HDD");
>> - if (ret)
>> - goto fail_create_attr;
>> + if (ret) {
>> + kobject_put(&tlmi_priv.pwd_hdd->kobj);
>> + tlmi_priv.pwd_hdd = NULL;
>> + auth_ret = ret;
>> + }
>>
>> tlmi_priv.pwd_nvme->kobj.kset = tlmi_priv.authentication_kset;
>> ret = kobject_init_and_add(&tlmi_priv.pwd_nvme->kobj, &tlmi_pwd_setting_ktype,
>> NULL, "%s", "NVMe");
>> - if (ret)
>> - goto fail_create_attr;
>> + if (ret) {
>> + kobject_put(&tlmi_priv.pwd_nvme->kobj);
>> + tlmi_priv.pwd_nvme = NULL;
>> + auth_ret = ret;
>> + }
>> + }
>> + /* If one of the auth entries fail, we'd best go and clean up */
>> + if (auth_ret) {
>> + ret = auth_ret;
>> + goto fail_create_attr;
>
> Why would you need to defer the bail-out path?
>
>> }
>> -
>> return ret;
>>
>> fail_create_attr:
>> + /* Release any kobject items */
>> tlmi_release_attr();
>
> tlmi_release_attr() calls kobject_put() without nullifying
> tlmi_priv.pwd_*, so ...
>
>> + kfree(tlmi_priv.pwd_admin);
>> + kfree(tlmi_priv.pwd_power);
>> + kfree(tlmi_priv.pwd_system);
>> + kfree(tlmi_priv.pwd_hdd);
>> + kfree(tlmi_priv.pwd_nvme);
>
> a bunch of double free.
>
Thanks - agreed on all the points. Will address in v2
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init
2026-12-04 13:28 ` Rong Zhang
@ 2026-12-04 15:14 ` Mark Pearson
0 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:14 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:28 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> When we read in current BIOS setting at init, cache it then to avoid
>> having to process it later, as it doesn't change.
>>
>> This does introduce a couple of changes in behaviour:
>>
>> - If the attribute value is changed we modify the cached value to show
>> what was set. Previously this would have read back the value - which
>> would have been wrong, so this should be an improvement.
>>
>> - Previously a malformed attribute (invalid name or value) would have
>> been registered, whereas now it is skipped. It is better not to show
>> invalid entries
>>
>> During code review it picked up that if attributes are cleared the
>> setting pointer could be leaked with a driver re-probe.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/think-lmi.c | 67 ++++++++++++++++---------
>> drivers/platform/x86/lenovo/think-lmi.h | 1 +
>> 2 files changed, 43 insertions(+), 25 deletions(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
>> index 63ea212b4bda..6580b1401f01 100644
>> --- a/drivers/platform/x86/lenovo/think-lmi.c
>> +++ b/drivers/platform/x86/lenovo/think-lmi.c
>> @@ -1047,25 +1047,11 @@ static ssize_t display_name_show(struct kobject *kobj, struct kobj_attribute *at
>> 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);
>> - char *item, *value;
>> - int ret;
>> -
>> - ret = tlmi_setting(setting->wdev, setting->index, &item);
>> - if (ret)
>> - return ret;
>>
>> - /* validate and split from `item,value` -> `value` */
>> - value = strpbrk(item, ",");
>> - if (!value || value == item || !strlen(value + 1))
>> - ret = -EINVAL;
>> - else {
>> - /* On Workstations remove the Options part after the value */
>> - strreplace(value, ';', '\0');
>> - ret = sysfs_emit(buf, "%s\n", value + 1);
>> - }
>> - kfree(item);
>> -
>> - return ret;
>> + guard(mutex)(&tlmi_mutex);
>> + if (!setting->current_value)
>> + return sysfs_emit(buf, "unknown\n");
>> + return sysfs_emit(buf, "%s\n", setting->current_value);
>> }
>>
>> static ssize_t possible_values_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>> @@ -1204,8 +1190,16 @@ static ssize_t current_value_store(struct kobject *kobj,
>> ret = tlmi_save_bios_settings("");
>> }
>> }
>> - if (!ret && !tlmi_priv.pending_changes) {
>> - tlmi_priv.pending_changes = true;
>> + if (!ret) {
>> + char *s;
>> +
>> + if (!tlmi_priv.pending_changes)
>
> Is the `if' doing anything? Overriding true with true is idempotent.
>
agreed
>> + tlmi_priv.pending_changes = true;
>> + /* Update setting so read back shows correctly */
>> + s = kstrdup(new_setting, GFP_KERNEL);
>> + kfree(setting->current_value);
>> + /* if kstrdup fails, show will handle null value */
>> + setting->current_value = s;
>
> Since new_setting is going to be freed later, i.e., no one else will use
> it, why not assign it to setting->current_value directly?
>
> Hint: adopt __free() and guard(), and then no_free_ptr() is here to help
> you.
>
Ack. I'm sure I tried this and then sashiko (run privately) complained about something...but I'll have a look at it again. I suspect I've made a meal of this.
>> /* let userland know it may need to check reboot pending again */
>> kobject_uevent(&tlmi_priv.class_dev->kobj, KOBJ_CHANGE);
>
> What's the intent here? Notify on every successful write or only on
> tlmi_priv.pending_changes flip?
>
Should be on a pending_changes flip...I need to revisit this section.
Thanks
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list
2026-12-04 13:30 ` Rong Zhang
@ 2026-12-04 15:21 ` Mark Pearson
2026-12-04 16:10 ` Rong Zhang
0 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:21 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:30 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> Use a linked list for storing attributes instead of a fixed array.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/think-lmi.c | 55 +++++++++++--------------
>> drivers/platform/x86/lenovo/think-lmi.h | 3 +-
>> 2 files changed, 25 insertions(+), 33 deletions(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
>> index 6580b1401f01..7a24985882ea 100644
>> --- a/drivers/platform/x86/lenovo/think-lmi.c
>> +++ b/drivers/platform/x86/lenovo/think-lmi.c
>> @@ -1249,6 +1249,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
>> {
>> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>>
>> + list_del(&setting->node);
>
> I guess you need a scoped_guard() or lockdep_assert_held() for it, but is
> it useful to keep the list in the first place? It seems that no one
> touches it once probe finishes.
>
Let me know if you mean something different than the below
The only reason for the list is because I use it in tlmi - and then I can keep the same structure for both drivers. It's a weak reason.
In tlmi I need it as there are settings, platform settings and functions - and a list works out quite nicely there, instead of maintaining three arrays. I thought I could use it here too, but it's not a requirement and admittedly not really beneficial. If I should just leave it unchanged I'm fine with that.
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
2026-12-04 13:41 ` Rong Zhang
@ 2026-12-04 15:27 ` Mark Pearson
0 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:27 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:41 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> Thinkpad, ThinkCenter and ThinkStation are implementing a new WMI API that
>> is common across all platforms.
>>
>> This adds the initial infrastructure for reading in the BIOS settings.
>>
>> The tlmi-config module provides the main interface, using the config GUID,
>> for changing settings.
>>
>> The tlmi-attr module reads in, and verifies, the BIOS attribute settings
>> that are available.
>>
>> Future patches will add the sysfs infrastructure needed.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/Makefile | 1 +
>> drivers/platform/x86/lenovo/think-lmi.h | 10 +
>> drivers/platform/x86/lenovo/tlmi-attr.c | 212 ++++++++++++++++++++++
>> drivers/platform/x86/lenovo/tlmi-config.c | 119 ++++++++++++
>> 4 files changed, 342 insertions(+)
>> create mode 100644 drivers/platform/x86/lenovo/tlmi-attr.c
>> create mode 100644 drivers/platform/x86/lenovo/tlmi-config.c
>>
>> diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
>> index 12816d8d5e24..d22b56553297 100644
>> --- a/drivers/platform/x86/lenovo/Makefile
>> +++ b/drivers/platform/x86/lenovo/Makefile
>> @@ -5,6 +5,7 @@
>> #
>> obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
>> obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
>> +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
>> obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>>
>> lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
>> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
>> index d0d8428ee440..82f3644b9089 100644
>> --- a/drivers/platform/x86/lenovo/think-lmi.h
>> +++ b/drivers/platform/x86/lenovo/think-lmi.h
>> @@ -12,6 +12,8 @@
>> #define TLMI_LANG_MAXLEN 4
>> #define TLMI_INDEX_MAX 32
>>
>> +#define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
>> +
>> /* Possible error values */
>> struct tlmi_err_codes {
>> const char *err_str;
>> @@ -106,6 +108,9 @@ struct tlmi_attr_setting {
>> char *display_name;
>> char *possible_values;
>> char *current_value;
>> + char *factory_default;
>> + unsigned char access_level;
>> + bool read_only;
>> };
>>
>> struct think_lmi {
>> @@ -128,6 +133,7 @@ struct think_lmi {
>> struct device *class_dev;
>> struct kset *attribute_kset;
>> struct kset *authentication_kset;
>> + struct wmi_device *config_wdev;
>>
>> struct tlmi_pwdcfg pwdcfg;
>> struct tlmi_pwd_setting *pwd_admin;
>> @@ -139,4 +145,8 @@ struct think_lmi {
>> const struct tlmi_cert_guids *cert_guid;
>> };
>>
>> +/* Used by tlmi to sync the different sub-drivers */
>> +struct component_match;
>> +void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
>> +
>> #endif /* !_THINK_LMI_H_ */
>> diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
>> new file mode 100644
>> index 000000000000..04c2ecf5053b
>> --- /dev/null
>> +++ b/drivers/platform/x86/lenovo/tlmi-attr.c
>> @@ -0,0 +1,212 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Lenovo TLMI attributes WMI interface driver.
>> + *
>> + * Read in the WMI configureable BIOS settings and their properties.
>> + *
>> + * This driver supports the "Common WMI" approach implemented on
>> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
>> + */
>> +
>> +#include <linux/acpi.h>
>> +#include <linux/cleanup.h>
>> +#include <linux/component.h>
>> +#include <linux/container_of.h>
>> +#include <linux/device.h>
>> +#include <linux/kdev_t.h>
>> +#include <linux/kobject.h>
>> +#include <linux/module.h>
>> +#include <linux/string_helpers.h>
>> +#include <linux/types.h>
>> +#include <linux/wmi.h>
>> +#include "think-lmi.h"
>> +
>> +static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
>> +{
>> + if (setting) {
>> + list_del(&setting->node);
>> + kfree(setting->name);
>> + kfree(setting->display_name);
>> + kfree(setting->possible_values);
>> + kfree(setting->current_value);
>> + kfree(setting->factory_default);
>> + kfree(setting);
>> + }
>> +}
>> +
>> +#define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
>> +
>> +static int tlmi_attr_sanitize(const union acpi_object *obj, bool *valid)
>> +{
>> + int i;
>> +
>> + if (obj->type != ACPI_TYPE_PACKAGE)
>> + return -EINVAL;
>> +
>> + if (obj->package.count < ATTRDATA_ENTRIES)
>> + return -EIO;
>> +
>> + /* First six entries should all be valid strings */
>> + for (i = 0; i < 6; i++) {
>> + if (obj->package.elements[i].type != ACPI_TYPE_STRING)
>> + return -EIO;
>> + if (!obj->package.elements[i].string.pointer[0]) {
>> + /* If first entry empty, this is just an empty slot */
>> + return i == 0 ? 0 : -EIO;
>> + }
>> + }
>> + /* Remaining two are integers */
>> + if (obj->package.elements[6].type != ACPI_TYPE_INTEGER)
>> + return -EIO;
>> + if (obj->package.elements[7].type != ACPI_TYPE_INTEGER)
>> + return -EIO;
>> +
>> + *valid = true;
>> + return 0;
>> +}
>> +
>> +static int tlmi_attr_create_setting(int item, struct think_lmi *td, struct wmi_device *wdev)
>> +{
>> + struct tlmi_attr_setting *setting;
>> + union acpi_object *obj __free(kfree) = NULL;
>> + bool valid = false;
>> + int ret;
>> +
>> + obj = wmidev_block_query(wdev, item);
>> + if (!obj)
>> + return 0; /* No valid entry here */
>
> Could you use the modern WMI API to align with the Windows behavior? See
> wmidev_query_block().
>
Yeah....slighty embarassed I didn't actually now it's pointed out. Sigh/
>> +
>> + /* Confirm we have a valid item */
>> + ret = tlmi_attr_sanitize(obj, &valid);
>> + if (!valid) {
>> + if (ret)
>> + pr_info("tlmi-attr: Incorrectly formatted entry %d\n", item);
>> + return 0; /* Skip this entry */
>> + }
>> +
>> + char *name __free(kfree) = kstrdup(obj->package.elements[0].string.pointer, GFP_KERNEL);
>> + if (!name)
>> + return -ENOMEM;
>> +
>> + char *current_value __free(kfree) = kstrdup(obj->package.elements[1].string.pointer,
>> + GFP_KERNEL);
>> + if (!current_value)
>> + return -ENOMEM;
>> +
>> + char *possible_values __free(kfree) = kstrdup(obj->package.elements[2].string.pointer,
>> + GFP_KERNEL);
>> + if (!possible_values)
>> + return -ENOMEM;
>> +
>> + char *factory_default __free(kfree) = kstrdup(obj->package.elements[3].string.pointer,
>> + GFP_KERNEL);
>> + if (!factory_default)
>> + return -ENOMEM;
>> +
>> + char *display_name __free(kfree) = kstrdup(obj->package.elements[5].string.pointer,
>> + GFP_KERNEL);
>> + if (!display_name)
>> + return -ENOMEM;
>> +
>> + setting = kzalloc_obj(*setting);
>> + if (!setting)
>> + return -ENOMEM;
>> +
>> + setting->index = item;
>> + setting->access_level = obj->package.elements[6].integer.value;
>> + setting->read_only = obj->package.elements[7].integer.value ? true : false;
>> + setting->name = no_free_ptr(name);
>> + setting->current_value = no_free_ptr(current_value);
>> + setting->possible_values = no_free_ptr(possible_values);
>> + setting->factory_default = no_free_ptr(factory_default);
>> + setting->display_name = no_free_ptr(display_name);
>> + setting->wdev = td->config_wdev; /* Used to set attributes */
>> +
>> + list_add(&setting->node, &td->settings);
>> + return 0;
>> +}
>> +
>> +static int tlmi_attr_component_bind(struct device *attr_dev, struct device *config_dev,
>> + void *d)
>> +{
>> + struct wmi_device *wdev = dev_get_drvdata(attr_dev);
>> + struct tlmi_attr_setting *attr, *na;
>> + struct think_lmi *td = d;
>> + int i, ret = 0;
>> +
>> + INIT_LIST_HEAD(&td->settings);
>> + /*
>> + * Try to find the number of valid settings of this machine
>> + * and use it to create sysfs attributes.
>> + */
>> + for (i = 0; i < TLMI_SETTINGS_COUNT - 1; ++i) {
>> + ret = tlmi_attr_create_setting(i, td, wdev);
>> + if (ret)
>> + break;
>> + }
>> + if (ret) { /* Clean up as unbind will not be called */
>> + list_for_each_entry_safe(attr, na, &td->settings, node)
>> + tlmi_attr_release_setting(attr);
>> + }
>
> If the list really useful? You can use `while (i--)' here.
It comes in useful with the platform and function settings later (in my opinion).
>
>> + return ret;
>> +}
>> +
>> +static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *config_dev,
>> + void *d)
>> +{
>> + struct tlmi_attr_setting *attr, *na;
>> + struct think_lmi *td = d;
>> +
>> + list_for_each_entry_safe(attr, na, &td->settings, node)
>> + tlmi_attr_release_setting(attr);
>
> All settings must have been created on bind() success, in which case you
> don't need the list on unbind() as well.
>
OK - will look at it. I think you're right but I was being extra careful here.
>> +}
>> +
>> +static const struct component_ops tlmi_attr_component_ops = {
>> + .bind = tlmi_attr_component_bind,
>> + .unbind = tlmi_attr_component_unbind,
>> +};
>> +
>> +static int tlmi_attr_probe(struct wmi_device *wdev, const void *context)
>> +{
>> + dev_set_drvdata(&wdev->dev, wdev);
>> + return component_add(&wdev->dev, &tlmi_attr_component_ops);
>> +}
>> +
>> +static void tlmi_attr_remove(struct wmi_device *wdev)
>> +{
>> + component_del(&wdev->dev, &tlmi_attr_component_ops);
>> +}
>> +
>> +static const struct wmi_device_id tlmi_attr_id_table[] = {
>> + { TLMI_ATTRIBUTE_GUID, NULL },
>> + {}
>> +};
>> +
>> +static struct wmi_driver tlmi_attr_driver = {
>> + .driver = {
>> + .name = "tlmi-attr",
>> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
>> + },
>> + .id_table = tlmi_attr_id_table,
>> + .probe = tlmi_attr_probe,
>> + .remove = tlmi_attr_remove,
>> + .no_singleton = true,
>> +};
>> +
>> +static int tlmi_attr_match(struct device *dev, void *type)
>> +{
>> + return (dev->driver == &tlmi_attr_driver.driver);
>> +}
>> +
>> +void tlmi_attr_match_add(struct device *master, struct component_match **matchptr)
>> +{
>> + component_match_add(master, matchptr, tlmi_attr_match, NULL);
>> +}
>> +EXPORT_SYMBOL_NS_GPL(tlmi_attr_match_add, "TLMI-ATTR");
>
> Use an underline instead of a hyphen. Meanwhile, could you name it
> "THINKPAD_LMI_*" to align with the Kconfig name and improve
> understandability?
>
Yep - not a problem. Will update
>> +
>> +module_wmi_driver(tlmi_attr_driver);
>> +
>> +MODULE_DEVICE_TABLE(wmi, tlmi_attr_id_table);
>> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
>> +MODULE_DESCRIPTION("TLMI Attributes WMI Driver");
>> +MODULE_LICENSE("GPL");
>> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
>> new file mode 100644
>> index 000000000000..9f57b0ba8dc5
>> --- /dev/null
>> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
>> @@ -0,0 +1,119 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Lenovo TLMI configuration WMI Data Block driver.
>> + *
>> + * Main controller for the tlmi-* suite of drivers.
>> + * Provides ability to set and save BIOS settings.
>> + *
>> + * This driver supports the "Common WMI" approach implemented on
>> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
>> + */
>> +
>> +#include <linux/component.h>
>> +#include <linux/device.h>
>> +#include <linux/dev_printk.h>
>> +#include <linux/err.h>
>> +#include <linux/firmware_attributes.h>
>> +#include <linux/module.h>
>> +#include <linux/mutex.h>
>> +#include <linux/mutex_types.h>
>> +#include <linux/stddef.h>
>> +#include <linux/types.h>
>> +#include <linux/wmi.h>
>> +#include "think-lmi.h"
>> +
>> +#define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
>> +
>> +/* Method IDS for configuration GUID */
>> +#define SET_ID 1
>> +#define SAVE_ID 2
>> +
>> +static int tlmi_config_bind(struct device *dev)
>> +{
>> + struct think_lmi *td = dev_get_drvdata(dev);
>> + int ret;
>> +
>> + /* Triggers the bind callbacks for registered sub-components */
>> + ret = component_bind_all(dev, td);
>> + return ret;
>> +}
>> +
>> +static void tlmi_config_unbind(struct device *dev)
>> +{
>> + struct think_lmi *td = dev_get_drvdata(dev);
>> +
>> + component_unbind_all(dev, td);
>> +}
>> +
>> +static const struct component_master_ops aggregate_ops = {
>> + .bind = tlmi_config_bind,
>> + .unbind = tlmi_config_unbind,
>> +};
>> +
>> +static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
>> +{
>> + struct component_match *match = NULL;
>> + guid_t tlmi_attr_guid;
>> + struct think_lmi *td;
>> + int ret;
>> +
>> + guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
>
> ret =
> if (ret)
>
>> +
>> + /* At minimum need to support BIOS settings */
>> + if (!wmidev_exists(&tlmi_attr_guid))
>> + return -EOPNOTSUPP;
>> +
>> + td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
>> + if (!td)
>> + return -ENOMEM;
>> +
>> + td->config_wdev = wdev;
>> + dev_set_drvdata(&wdev->dev, td);
>> +
>> + td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
>> + NULL, "%s", "tlmi");
>
> no_singleton?
>
Ah....yeah. Urgh....
> And why would you need to create it this early? Please postpone it to
> component bind.
>
I'd not considered that. I'll look to move it there.
>> + if (IS_ERR(td->class_dev))
>> + return PTR_ERR(td->class_dev);
>> + dev_set_drvdata(td->class_dev, td);
>> +
>> + /* Register the other components */
>> + tlmi_attr_match_add(&wdev->dev, &match);
>
> Check errors.
Fair point. Thanks
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
2026-12-04 13:44 ` Rong Zhang
@ 2026-12-04 15:41 ` Mark Pearson
2026-12-04 17:02 ` Rong Zhang
0 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:41 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:44 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> Implement the sysfs entries for the attribute settings, along with the
>> ability to modify and query them.
>>
>> Implement the save_settings and pending_reboot sysfs entries.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/think-lmi.h | 1 +
>> drivers/platform/x86/lenovo/tlmi-attr.c | 4 +-
>> drivers/platform/x86/lenovo/tlmi-config.c | 362 ++++++++++++++++++++++
>> 3 files changed, 366 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
>> index 82f3644b9089..07a235b3a886 100644
>> --- a/drivers/platform/x86/lenovo/think-lmi.h
>> +++ b/drivers/platform/x86/lenovo/think-lmi.h
>> @@ -148,5 +148,6 @@ struct think_lmi {
>> /* Used by tlmi to sync the different sub-drivers */
>> struct component_match;
>> void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
>> +void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
>>
>> #endif /* !_THINK_LMI_H_ */
>> diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
>> index 04c2ecf5053b..8818010a45cd 100644
>> --- a/drivers/platform/x86/lenovo/tlmi-attr.c
>> +++ b/drivers/platform/x86/lenovo/tlmi-attr.c
>> @@ -21,7 +21,7 @@
>> #include <linux/wmi.h>
>> #include "think-lmi.h"
>>
>> -static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
>> +void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
>
> This was introduced by the previous patch. Please avoid unnecessary back-
> and-forth changes.
>
Sure. The change is just because in this patch tlmi-config needs to use that function - hence the change, but not a problem
>> {
>> if (setting) {
>> list_del(&setting->node);
>> @@ -33,6 +33,7 @@ static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
>> kfree(setting);
>> }
>> }
>> +EXPORT_SYMBOL_NS_GPL(tlmi_attr_release_setting, "TLMI-ATTR");
>>
>> #define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
>>
>> @@ -157,6 +158,7 @@ static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *c
>> struct tlmi_attr_setting *attr, *na;
>> struct think_lmi *td = d;
>>
>> + /* This should not be needed - but make sure settings list is clear */
>> list_for_each_entry_safe(attr, na, &td->settings, node)
>> tlmi_attr_release_setting(attr);
>> }
>> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
>> index 9f57b0ba8dc5..ef5efae2e395 100644
>> --- a/drivers/platform/x86/lenovo/tlmi-config.c
>> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
>> @@ -18,6 +18,7 @@
>> #include <linux/mutex.h>
>> #include <linux/mutex_types.h>
>> #include <linux/stddef.h>
>> +#include <linux/string_helpers.h>
>> #include <linux/types.h>
>> #include <linux/wmi.h>
>> #include "think-lmi.h"
>> @@ -28,6 +29,359 @@
>> #define SET_ID 1
>> #define SAVE_ID 2
>>
>> +static DEFINE_MUTEX(tlmi_config_lock);
>> +
>> +/* ---- Helper functions---- */
>> +
>> +static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
>> +{
>> + struct wmi_string *wmistr = (struct wmi_string *)buffer;
>> + u16 len;
>> + int ret;
>> +
>> + if (!str || !buffer)
>> + return -EINVAL;
>> +
>> + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
>
> Use wmistr you introduced above.
>
> Passing buffer_len is incorrect, see also
> drivers/platform/wmi/tests/string_kunit.c for examples.
>
This function gave me so many headaches. Thanks for the pointers.
>> + if (ret < 0)
>> + return ret;
>> +
>> + len = le16_to_cpu(wmistr->length);
>> + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
>> + return len; /* minus extra null and + the length field */
>> +}
>> +
>> +/* Send request to BIOS and scan return buffer for error codes */
>> +static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
>> + struct wmi_buffer *wmibuf)
>> +{
>> + struct wmi_buffer wmibuf_return = {0, NULL};
>
> = {};
ack
>
>> + char errstr[32];
>> + int ret;
>> +
>> + ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
>> + sizeof(struct wmi_string));
>> + if (!ret && wmibuf_return.data) {
>> + /* extract error string */
>> + if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
>
> The buffer's length contains the wmi_string's length field, why not
> subtract it? And you didn't check the wmi_string's validity.
>
Not following this one I'm afraid - but I assume it's the same as what sashiko has highlighted? Let me know if you mean something different to sashiko.
>> + ret = -EINVAL;
>> + else
>> + ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
>> + sizeof(errstr));
>> + kfree(wmibuf_return.data);
>
> Why not:
>
> if (...)
> return -EINVAL;
>
> struct wmi_string *wmistr __free(kfree) = wmibuf_return.data;
>
> ret = wmi_string_to_utf8s();
>
Ack - that does look better
>> + if (ret < 0)
>> + return ret;
>> +
>> + if (!strcmp("Success", errstr))
>> + return 0;
>> + else if (!strcmp("Not Supported", errstr))
>> + return -EOPNOTSUPP;
>> + else if (!strcmp("Invalid Parameter", errstr))
>> + return -EINVAL;
>> + else if (!strcmp("Access Denied", errstr))
>> + return -EACCES;
>> + else if (!strcmp("System Busy", errstr))
>> + return -EBUSY;
>> + else if (!strcmp("System Locked", errstr))
>> + return -EACCES;
>> + dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
>> + return -EIO;
>
> -EPROTO?
>
Ack - that's nicer
>> + }
>> + return ret;
>> +}
>> +
>> +static ssize_t common_type_show(char *possible_values, char *buf)
>> +{
>> + if (possible_values) {
>> + /* Figure out what setting type is as BIOS does not return this */
>> + if (strchr(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 common_current_value_store(char *name, const char *buf, int wmi_id,
>
> `name' should be const char * if you are not intended to manipulate it.
>
>> + struct think_lmi *td)
>> +{
>> + char *new_setting __free(kfree) = NULL;
>> + char *wmidata __free(kfree) = NULL;
>
> Move them to where the resources are allocated.
>
>> + size_t namelen, valuelen;
>> + struct wmi_buffer wmibuf;
>> + char *start;
>> + int ix = 0;
>> +
>> + /* If a save has been done then a reboot is needed */
>> + if (td->reboot_required)
>> + return -EPERM;
>> +
>> + /* Strip out CR if one is present */
>
> \n is LF.
>
>> + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
>> + if (!new_setting)
>> + return -ENOMEM;
>
> I am not in favor of the idea of abusing kstrdup_and_replace(), because:
>
> - Only the trailing LF should be stripped
> - You don't take the advantage of the sysfs buffer size
>
> I'd suggest:
>
> if (size && buf[size - 1] == '\n')
> size -= 1;
> if (!size)
> return -EINVAL;
>
> char *new_setting __free(kfree) = kmemdup_nul(buf, size, GFP_KERNEL);
>
> If LF in between is not allowed, please return -EINVAL instead of
> silently clipping the string.
>
Funnily enough this bit is borrowed directly from think-lmi. It's probably not needed here as the FW teams are giving much cleaner strings now...but seemed sensible to keep it just in case.
Personally I prefer the original but I don't feel strongly about it.
>> +
>> + /* Calculate and alloc buffer for command string */
>> + namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
>> + valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
>> + wmibuf.length = namelen + valuelen;
>> + wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
>> + wmibuf.data = wmidata;
>> + if (!wmibuf.data)
>> + return -ENOMEM;
>> +
>> + /* build argument buffer from inputs */
>> + start = wmibuf.data;
>> + ix = tlmi_populate_string_buffer(start, namelen, name);
>> + if (ix < 0)
>> + return ix;
>> +
>> + start += ix;
>> + ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
>> + if (ix < 0)
>> + return ix;
>> +
>> + return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
>> +}
>> +
>> +/* ---- Attribute sysfs ---- */
>> +static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
>> +{
>> + return container_of(kobj, struct tlmi_attr_setting, kobj);
>> +}
>> +
>> +static ssize_t display_name_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->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);
>> +
>> + guard(mutex)(&tlmi_config_lock);
>> +
>> + if (!setting->current_value)
>> + return sysfs_emit(buf, "unknown\n");
>> + return sysfs_emit(buf, "%s\n", setting->current_value);
>> +}
>> +
>> +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 ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
>> + char *buf)
>> +{
>> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> +
>> + return common_type_show(setting->possible_values, buf);
>> +}
>> +
>> +static ssize_t current_value_store(struct kobject *kobj,
>> + struct kobj_attribute *attr,
>> + const char *buf, size_t count)
>> +{
>> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
>> + int ret;
>> +
>> + guard(mutex)(&tlmi_config_lock);
>> +
>> + ret = common_current_value_store(setting->name, buf, SET_ID, td);
>> + if (!ret) {
>> + char *s;
>> +
>> + td->save_required = true;
>> + /* Update setting so read back shows correctly */
>> + s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
>
> ??? Please don't repeat the same operation twice.
Yep - fair.
>
>> + kfree(setting->current_value);
>> + /* if kstrdup fails, we'll handle it in the show */
>> + setting->current_value = s;
>> + return count;
>> + }
>> + return ret;
>> +}
>> +
>> +static struct kobj_attribute attr_display_name = __ATTR_RO(display_name);
>> +
>> +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_display_name.attr,
>> + &attr_current_val.attr,
>> + &attr_possible_values.attr,
>> + &attr_type.attr,
>> + NULL
>> +};
>> +
>> +static const struct attribute_group tlmi_attr_group = {
>> + .attrs = tlmi_attrs,
>> +};
>> +__ATTRIBUTE_GROUPS(tlmi_attr);
>> +
>> +static void tlmi_attr_setting_release(struct kobject *kobj)
>> +{
>> + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
>> +
>> + tlmi_attr_release_setting(setting);
>> +}
>> +
>> +static const struct kobj_type tlmi_attr_setting_ktype = {
>> + .release = &tlmi_attr_setting_release,
>> + .sysfs_ops = &kobj_sysfs_ops,
>> + .default_groups = tlmi_attr_groups,
>> +};
>> +
>> +/* ---- sysfs entries --------------------------------------------------------- */
>> +static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
>> + char *buf)
>> +{
>> + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
>> +
>
> Why doesn't this need guard(mutex)(&tlmi_config_lock)?
It probably should
>
>> + return sysfs_emit(buf, "%d\n", td->pending_changes);
>> +}
>> +
>> +static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
>> +
>> +static ssize_t save_settings_show(struct kobject *kobj, struct kobj_attribute *attr,
>> + char *buf)
>> +{
>> + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
>> +
>
> Ditto?
ack
>
>> + return sysfs_emit(buf, "%d\n", td->save_required);
>> +}
>> +
>> +static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *attr,
>> + const char *buf, size_t count)
>> +{
>> + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
>> + char *wmidata __free(kfree) = NULL;
>> + struct wmi_buffer wmibuf;
>> + int ret = 0;
>> +
>> + /* save command triggered by writing 'save' */
>> + if (!sysfs_streq(buf, "save"))
>> + return -EINVAL;
>> +
>> + /* Use lock in case multiple WMI operations needed */
>> + guard(mutex)(&tlmi_config_lock);
>> +
>> + /* Check there is actually something to save */
>> + if (!td->save_required)
>> + return -ENOENT;
>
> Returning -ENOENT on a file could be confusing IMO.
>
> Though thinklmi is already doing so, sigh...
>
Yeah. I'm happy to change it to something else. Will look into that for v2.
Two wrongs don't make a right etc.
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information
2026-12-04 13:48 ` Rong Zhang
@ 2026-12-04 15:44 ` Mark Pearson
2026-12-04 17:14 ` Rong Zhang
0 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:44 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:48 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> Add authdata module for reading in the authorisation account
>> details from the BIOS.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/Makefile | 2 +-
>> drivers/platform/x86/lenovo/think-lmi.h | 13 ++
>> drivers/platform/x86/lenovo/tlmi-authdata.c | 135 ++++++++++++++++++++
>> drivers/platform/x86/lenovo/tlmi-config.c | 10 +-
>> 4 files changed, 156 insertions(+), 4 deletions(-)
>> create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
>>
>> diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
>> index d22b56553297..f1600b562273 100644
>> --- a/drivers/platform/x86/lenovo/Makefile
>> +++ b/drivers/platform/x86/lenovo/Makefile
>> @@ -5,7 +5,7 @@
>> #
>> obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
>> obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
>> -obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
>> +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
>> obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>>
>> lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
>> diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
>> index 07a235b3a886..75b21dcc2f42 100644
>> --- a/drivers/platform/x86/lenovo/think-lmi.h
>> +++ b/drivers/platform/x86/lenovo/think-lmi.h
>> @@ -13,6 +13,7 @@
>> #define TLMI_INDEX_MAX 32
>>
>> #define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
>> +#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
>>
>> /* Possible error values */
>> struct tlmi_err_codes {
>> @@ -75,9 +76,20 @@ struct tlmi_pwdcfg_ext {
>> uint32_t nvme_master_password;
>> };
>>
>> +/* fields specific to tlmi-authdata driver */
>> +struct tlmi_pwdcfg_authdata {
>> + bool strong_password;
>> + bool deploy_mode;
>> + bool sys_mgr_pwd_ctrl;
>> + bool power_on_pwd_ctrl;
>> + bool storage_pwd_ctrl;
>> + bool sys_mgr_setup_ctrl;
>> +};
>> +
>> struct tlmi_pwdcfg {
>> struct tlmi_pwdcfg_core core;
>> struct tlmi_pwdcfg_ext ext;
>> + struct tlmi_pwdcfg_authdata authdata;
>> };
>>
>> /* password setting details */
>> @@ -149,5 +161,6 @@ struct think_lmi {
>> struct component_match;
>> void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
>> void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
>> +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
>>
>> #endif /* !_THINK_LMI_H_ */
>> diff --git a/drivers/platform/x86/lenovo/tlmi-authdata.c b/drivers/platform/x86/lenovo/tlmi-authdata.c
>> new file mode 100644
>> index 000000000000..668d07029139
>> --- /dev/null
>> +++ b/drivers/platform/x86/lenovo/tlmi-authdata.c
>> @@ -0,0 +1,135 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Lenovo ThinkLMI authentication data WMI interface driver.
>> + *
>> + * Read in the WMI authentication settings and their properties.
>> + *
>> + * This driver supports the "Common WMI" approach implemented on
>> + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
>> + */
>> +
>> +#include <linux/cleanup.h>
>> +#include <linux/component.h>
>> +#include <linux/device.h>
>> +#include <linux/module.h>
>> +#include <linux/types.h>
>> +#include <linux/wmi.h>
>> +#include "think-lmi.h"
>> +
>> +#define AUTHDATA_ENTRIES 15 /*number of entries returned from BIOS */
>> +
>> +static int tlmi_authdata_sanitize(const union acpi_object *obj)
>> +{
>> + int i;
>> +
>> + /*Scan through query result and check it's sane*/
>> + if (obj->type != ACPI_TYPE_PACKAGE)
>> + return -EINVAL;
>> +
>> + if (obj->package.count < AUTHDATA_ENTRIES)
>> + return -EIO;
>> +
>> + for (i = 0; i < AUTHDATA_ENTRIES; i++) {
>> + /* Every entry is an integer which makes this easy */
>> + if (obj->package.elements[i].type != ACPI_TYPE_INTEGER)
>> + return -EIO;
>> + }
>> + return 0;
>> +}
>> +
>> +/* Get password settings from BIOS */
>> +static int tlmi_authdata_get(struct wmi_device *wdev, struct think_lmi *td)
>> +{
>> + const union acpi_object *obj __free(kfree) = NULL;
>> + int ret;
>> +
>> + obj = wmidev_block_query(wdev, 0);
>> + if (!obj)
>> + return -EIO;
>
> Use modern WMI APIs and move __free() declaration to wherever the
> resource is allocated.
>
ack
>> +
>> + ret = tlmi_authdata_sanitize(obj);
>> + if (ret)
>> + return ret;
>> +
>> + td->pwdcfg.core.password_state = obj->package.elements[0].integer.value;
>> + td->pwdcfg.core.min_length = obj->package.elements[1].integer.value;
>> + td->pwdcfg.core.max_length = obj->package.elements[2].integer.value;
>> + td->pwdcfg.authdata.strong_password = obj->package.elements[3].integer.value;
>> + td->pwdcfg.core.supported_encodings = obj->package.elements[4].integer.value;
>> + td->pwdcfg.core.supported_keyboard = obj->package.elements[5].integer.value;
>> + td->pwdcfg.ext.hdd_user_password = obj->package.elements[6].integer.value;
>> + td->pwdcfg.ext.hdd_master_password = obj->package.elements[7].integer.value;
>> + td->pwdcfg.ext.nvme_user_password = obj->package.elements[8].integer.value;
>> + td->pwdcfg.ext.nvme_master_password = obj->package.elements[9].integer.value;
>> + td->pwdcfg.authdata.deploy_mode = obj->package.elements[10].integer.value;
>> + td->pwdcfg.authdata.sys_mgr_pwd_ctrl = obj->package.elements[11].integer.value;
>> + td->pwdcfg.authdata.power_on_pwd_ctrl = obj->package.elements[12].integer.value;
>> + td->pwdcfg.authdata.storage_pwd_ctrl = obj->package.elements[13].integer.value;
>> + td->pwdcfg.authdata.sys_mgr_setup_ctrl = obj->package.elements[14].integer.value;
>> +
>> + if (WARN_ON(td->pwdcfg.core.max_length >= TLMI_PWD_BUFSIZE))
>> + td->pwdcfg.core.max_length = TLMI_PWD_BUFSIZE - 1;
>> + if (WARN_ON(td->pwdcfg.core.min_length > td->pwdcfg.core.max_length))
>> + td->pwdcfg.core.min_length = td->pwdcfg.core.max_length;
>
> Why would you need to WARN_ON() firmware stuff? Usually it's meant for
> kernel stuff.
>
I've seen warns for FW stuff lots of the time. It handy as when we do Linux enablement we try quite hard to make sure the kernel boot log is clean of errors and warnings.
My goal here is that if a platform BIOS is giving invalid values then I get a nice warning that I can go and beat up a FW team about. I'd like to leave this in.
>> +
>> + return 0;
>> +}
>> +
>> +static int tlmi_authdata_component_bind(struct device *authdata_dev, struct device *config_dev,
>> + void *d)
>> +{
>> + struct wmi_device *wdev = dev_get_drvdata(authdata_dev);
>> + struct think_lmi *td = d;
>> +
>> + return tlmi_authdata_get(wdev, td);
>> +}
>> +
>> +static const struct component_ops tlmi_authdata_component_ops = {
>> + .bind = tlmi_authdata_component_bind,
>> +};
>> +
>> +static int tlmi_authdata_probe(struct wmi_device *wdev, const void *context)
>> +{
>> + dev_set_drvdata(&wdev->dev, wdev);
>> +
>> + return component_add(&wdev->dev, &tlmi_authdata_component_ops);
>> +}
>> +
>> +static void tlmi_authdata_remove(struct wmi_device *wdev)
>> +{
>> + component_del(&wdev->dev, &tlmi_authdata_component_ops);
>> +}
>> +
>> +static const struct wmi_device_id tlmi_authdata_id_table[] = {
>> + { TLMI_AUTHENTICATION_DATA_GUID, NULL },
>> + {}
>> +};
>> +
>> +static struct wmi_driver tlmi_authdata_driver = {
>> + .driver = {
>> + .name = "tlmi-authdata",
>> + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
>> + },
>> + .id_table = tlmi_authdata_id_table,
>> + .probe = tlmi_authdata_probe,
>> + .remove = tlmi_authdata_remove,
>> + .no_singleton = true,
>> +};
>> +
>> +static int tlmi_authdata_match(struct device *dev, void *type)
>> +{
>> + return (dev->driver == &tlmi_authdata_driver.driver);
>> +}
>> +
>> +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr)
>> +{
>> + component_match_add(master, matchptr, tlmi_authdata_match, NULL);
>> +}
>> +EXPORT_SYMBOL_NS_GPL(tlmi_authdata_match_add, "TLMI-AUTHDATA");
>> +
>> +module_wmi_driver(tlmi_authdata_driver);
>> +
>> +MODULE_DEVICE_TABLE(wmi, tlmi_authdata_id_table);
>> +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
>> +MODULE_DESCRIPTION("ThinkLMI Authentication Data WMI Driver");
>> +MODULE_LICENSE("GPL");
>> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
>> index ef5efae2e395..ddbf0307f810 100644
>> --- a/drivers/platform/x86/lenovo/tlmi-config.c
>> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
>> @@ -415,14 +415,16 @@ static const struct component_master_ops aggregate_ops = {
>> static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
>> {
>> struct component_match *match = NULL;
>> - guid_t tlmi_attr_guid;
>> + guid_t tlmi_attr_guid, tlmi_authdata_guid;
>> struct think_lmi *td;
>> int ret;
>>
>> guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
>> + guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
>
> ret =
> if (ret)
>
>>
>> - /* At minimum need to support BIOS settings */
>> - if (!wmidev_exists(&tlmi_attr_guid))
>> + /* At minimum need to support BIOS and authentication settings */
>> + if (!wmidev_exists(&tlmi_attr_guid) ||
>> + !wmidev_exists(&tlmi_authdata_guid))
>> return -EOPNOTSUPP;
>>
>> td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
>> @@ -440,6 +442,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
>>
>> /* Register the other components */
>> tlmi_attr_match_add(&wdev->dev, &match);
>> + tlmi_authdata_match_add(&wdev->dev, &match);
>
> Check errors.
>
Ack
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
2026-12-04 13:49 ` Rong Zhang
@ 2026-12-04 15:50 ` Mark Pearson
2026-12-04 17:19 ` Rong Zhang
0 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 15:50 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 8:49 AM, Rong Zhang wrote:
> Hi Mark,
>
> On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> The tlmi_populate_string_buffer and tlmi_request are going to be
>> needed in the upcoming tlmi-auth module, as well as the current
>> tlmi-config module.
>>
>> As we can't have circular dependencies they need to move out of
>> tlmi-config.
>>
>> The wmi-helpers module already provides helper functions for the
>> Lenovo Legion platforms, and seems a logical place for these to
>> move too.
>>
>> Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> ---
>> drivers/platform/x86/lenovo/Kconfig | 1 +
>> drivers/platform/x86/lenovo/tlmi-config.c | 59 +-------------------
>> drivers/platform/x86/lenovo/wmi-helpers.c | 65 ++++++++++++++++++++++-
>> drivers/platform/x86/lenovo/wmi-helpers.h | 5 ++
>> 4 files changed, 72 insertions(+), 58 deletions(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
>> index 16569406c946..c59461cf5f4a 100644
>> --- a/drivers/platform/x86/lenovo/Kconfig
>> +++ b/drivers/platform/x86/lenovo/Kconfig
>> @@ -218,6 +218,7 @@ config THINKPAD_LMI
>> depends on ACPI_WMI
>> depends on DMI
>> select FW_ATTR_CLASS
>> + select LENOVO_WMI_HELPERS
>
> Ba aware of
> https://msgid.link/f8815e94ddc161495ca80b04d7e3388549edafeb.camel@rong.moe
> if you'd need to rebase on top of David's series.
>
Ack - I figured the review process was going to be a rough ride for this series. I'm sure I'll be rebasing a few times before we're done.
I actually wonder if I'll need to move this whole driver....
>> help
>> This driver allows changing BIOS settings on Lenovo machines whose
>> BIOS support the WMI interface.
>> diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
>> index ddbf0307f810..bb9c5f720c24 100644
>> --- a/drivers/platform/x86/lenovo/tlmi-config.c
>> +++ b/drivers/platform/x86/lenovo/tlmi-config.c
>> @@ -22,6 +22,7 @@
>> #include <linux/types.h>
>> #include <linux/wmi.h>
>> #include "think-lmi.h"
>> +#include "wmi-helpers.h"
>>
>> #define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
>>
>> @@ -33,63 +34,6 @@ static DEFINE_MUTEX(tlmi_config_lock);
>>
>> /* ---- Helper functions---- */
>>
>> -static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
>> -{
>> - struct wmi_string *wmistr = (struct wmi_string *)buffer;
>> - u16 len;
>> - int ret;
>> -
>> - if (!str || !buffer)
>> - return -EINVAL;
>> -
>> - ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
>> - if (ret < 0)
>> - return ret;
>> -
>> - len = le16_to_cpu(wmistr->length);
>> - wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
>> - return len; /* minus extra null and + the length field */
>> -}
>> -
>> -/* Send request to BIOS and scan return buffer for error codes */
>> -static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
>> - struct wmi_buffer *wmibuf)
>> -{
>> - struct wmi_buffer wmibuf_return = {0, NULL};
>> - char errstr[32];
>> - int ret;
>> -
>> - ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
>> - sizeof(struct wmi_string));
>> - if (!ret && wmibuf_return.data) {
>> - /* extract error string */
>> - if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
>> - ret = -EINVAL;
>> - else
>> - ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
>> - sizeof(errstr));
>> - kfree(wmibuf_return.data);
>> - if (ret < 0)
>> - return ret;
>> -
>> - if (!strcmp("Success", errstr))
>> - return 0;
>> - else if (!strcmp("Not Supported", errstr))
>> - return -EOPNOTSUPP;
>> - else if (!strcmp("Invalid Parameter", errstr))
>> - return -EINVAL;
>> - else if (!strcmp("Access Denied", errstr))
>> - return -EACCES;
>> - else if (!strcmp("System Busy", errstr))
>> - return -EBUSY;
>> - else if (!strcmp("System Locked", errstr))
>> - return -EACCES;
>> - dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
>> - return -EIO;
>> - }
>> - return ret;
>> -}
>> -
>
> What? Wasn't these just introduced before? Could you add them to the
> right place from the beginning?
>
Probably a bad call on my part - a little bit part of how I went about developing the driver and building up the patchset.
I'll move this up much earlier in the series and get rid of the move if that helps.
>> static ssize_t common_type_show(char *possible_values, char *buf)
>> {
>> if (possible_values) {
>> @@ -477,6 +421,7 @@ static struct wmi_driver tlmi_config_driver = {
>>
>> module_wmi_driver(tlmi_config_driver);
>>
>> +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
>> MODULE_IMPORT_NS("TLMI-ATTR");
>> MODULE_IMPORT_NS("TLMI-AUTHDATA");
>> MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
>> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
>> index 687caa226263..e735771bb8d7 100644
>> --- a/drivers/platform/x86/lenovo/wmi-helpers.c
>> +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
>> @@ -1,6 +1,6 @@
>> // SPDX-License-Identifier: GPL-2.0-or-later
>> /*
>> - * Lenovo Legion WMI helpers driver.
>> + * Lenovo Legion and TLMI WMI helpers driver.
>> *
>> * The Lenovo Legion WMI interface is broken up into multiple GUID interfaces
>> * that require cross-references between GUID's for some functionality. The
>> @@ -13,6 +13,10 @@
>> * drivers uses a common procedure to get data from the WMI interface,
>> * enumerated here.
>> *
>> + * TLMI interface uses multiple GUID interfaces for BIOS settings and
>> + * authentication settings. A common procedure is used to get data from the
>> + * WMI interface and check for return error strings.
>> + *
>> * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
>> */
>>
>> @@ -33,6 +37,65 @@
>> /* Thermal mode notifier chain. */
>> static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
>>
>> +ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
>
> Why not void *buffer?
>
>> +{
>> + struct wmi_string *wmistr = (struct wmi_string *)buffer;
>> + u16 len;
>> + int ret;
>> +
>> + if (!str || !buffer)
>> + return -EINVAL;
>> +
>> + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
>> + if (ret < 0)
>> + return ret;
>> +
>> + len = le16_to_cpu(wmistr->length);
>> + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
>> + return len; /* minus extra null and + the length field */
>> +}
>> +EXPORT_SYMBOL_NS_GPL(tlmi_populate_string_buffer, "LENOVO_WMI_HELPERS");
>
> I believe this helper can be named lwmi_* as it's not coupled with
> thinklmi...
>
Sure
>> +
>> +/* Send request to BIOS and scan return buffer for error codes */
>> +int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
>> + struct wmi_buffer *wmibuf)
>
> ...while this is coupled with thinklmi, so this can be named tlmi_*.
>
Thanks
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list
2026-12-04 15:21 ` Mark Pearson
@ 2026-12-04 16:10 ` Rong Zhang
0 siblings, 0 replies; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 16:10 UTC (permalink / raw)
To: Mark Pearson
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
Hi Mark,
On Fri, 2026-12-04 at 10:21 -0500, Mark Pearson wrote:
>
> On Fri, Dec 4, 2026, at 8:30 AM, Rong Zhang wrote:
> > Hi Mark,
> >
> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> > > Use a linked list for storing attributes instead of a fixed array.
> > >
> > > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> > > ---
> > > drivers/platform/x86/lenovo/think-lmi.c | 55 +++++++++++--------------
> > > drivers/platform/x86/lenovo/think-lmi.h | 3 +-
> > > 2 files changed, 25 insertions(+), 33 deletions(-)
> > >
> > > diff --git a/drivers/platform/x86/lenovo/think-lmi.c b/drivers/platform/x86/lenovo/think-lmi.c
> > > index 6580b1401f01..7a24985882ea 100644
> > > --- a/drivers/platform/x86/lenovo/think-lmi.c
> > > +++ b/drivers/platform/x86/lenovo/think-lmi.c
> > > @@ -1249,6 +1249,7 @@ static void tlmi_attr_setting_release(struct kobject *kobj)
> > > {
> > > struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> > >
> > > + list_del(&setting->node);
> >
> > I guess you need a scoped_guard() or lockdep_assert_held() for it, but is
> > it useful to keep the list in the first place? It seems that no one
> > touches it once probe finishes.
> >
>
> Let me know if you mean something different than the below
>
> The only reason for the list is because I use it in tlmi - and then I can keep the same structure for both drivers. It's a weak reason.
>
> In tlmi I need it as there are settings, platform settings and functions - and a list works out quite nicely there, instead of maintaining three arrays. I thought I could use it here too, but it's not a requirement and admittedly not really beneficial. If I should just leave it unchanged I'm fine with that.
IMO using a list to arrange the probe sequence is OK as long as it makes
things tidier, but touching it in the kobj's release callback could be
too tricky like what Sashiko has raised.
If you don't need the list at runtime (I assume this is the case as I
didn't notice any runtime path relying on it), removing a node from the
list is quite unnecessary. So I think you can simply drop the list_del()
and add a comment to the list head stating the intentional behavior.
Thanks,
Rong
>
> Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
2026-12-04 15:41 ` Mark Pearson
@ 2026-12-04 17:02 ` Rong Zhang
0 siblings, 0 replies; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 17:02 UTC (permalink / raw)
To: Mark Pearson
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
Hi Mark,
On Fri, 2026-12-04 at 10:41 -0500, Mark Pearson wrote:
>
> On Fri, Dec 4, 2026, at 8:44 AM, Rong Zhang wrote:
> > Hi Mark,
> >
> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> > > Implement the sysfs entries for the attribute settings, along with the
> > > ability to modify and query them.
> > >
> > > Implement the save_settings and pending_reboot sysfs entries.
> > >
> > > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> > > ---
> > > drivers/platform/x86/lenovo/think-lmi.h | 1 +
> > > drivers/platform/x86/lenovo/tlmi-attr.c | 4 +-
> > > drivers/platform/x86/lenovo/tlmi-config.c | 362 ++++++++++++++++++++++
> > > 3 files changed, 366 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> > > index 82f3644b9089..07a235b3a886 100644
> > > --- a/drivers/platform/x86/lenovo/think-lmi.h
> > > +++ b/drivers/platform/x86/lenovo/think-lmi.h
> > > @@ -148,5 +148,6 @@ struct think_lmi {
> > > /* Used by tlmi to sync the different sub-drivers */
> > > struct component_match;
> > > void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> > > +void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
> > >
> > > #endif /* !_THINK_LMI_H_ */
> > > diff --git a/drivers/platform/x86/lenovo/tlmi-attr.c b/drivers/platform/x86/lenovo/tlmi-attr.c
> > > index 04c2ecf5053b..8818010a45cd 100644
> > > --- a/drivers/platform/x86/lenovo/tlmi-attr.c
> > > +++ b/drivers/platform/x86/lenovo/tlmi-attr.c
> > > @@ -21,7 +21,7 @@
> > > #include <linux/wmi.h>
> > > #include "think-lmi.h"
> > >
> > > -static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> > > +void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> >
> > This was introduced by the previous patch. Please avoid unnecessary back-
> > and-forth changes.
> >
> Sure. The change is just because in this patch tlmi-config needs to use that function - hence the change, but not a problem
>
> > > {
> > > if (setting) {
> > > list_del(&setting->node);
> > > @@ -33,6 +33,7 @@ static void tlmi_attr_release_setting(struct tlmi_attr_setting *setting)
> > > kfree(setting);
> > > }
> > > }
> > > +EXPORT_SYMBOL_NS_GPL(tlmi_attr_release_setting, "TLMI-ATTR");
> > >
> > > #define ATTRDATA_ENTRIES 8 /*number of entries returned from BIOS */
> > >
> > > @@ -157,6 +158,7 @@ static void tlmi_attr_component_unbind(struct device *attr_dev, struct device *c
> > > struct tlmi_attr_setting *attr, *na;
> > > struct think_lmi *td = d;
> > >
> > > + /* This should not be needed - but make sure settings list is clear */
> > > list_for_each_entry_safe(attr, na, &td->settings, node)
> > > tlmi_attr_release_setting(attr);
> > > }
> > > diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> > > index 9f57b0ba8dc5..ef5efae2e395 100644
> > > --- a/drivers/platform/x86/lenovo/tlmi-config.c
> > > +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> > > @@ -18,6 +18,7 @@
> > > #include <linux/mutex.h>
> > > #include <linux/mutex_types.h>
> > > #include <linux/stddef.h>
> > > +#include <linux/string_helpers.h>
> > > #include <linux/types.h>
> > > #include <linux/wmi.h>
> > > #include "think-lmi.h"
> > > @@ -28,6 +29,359 @@
> > > #define SET_ID 1
> > > #define SAVE_ID 2
> > >
> > > +static DEFINE_MUTEX(tlmi_config_lock);
> > > +
> > > +/* ---- Helper functions---- */
> > > +
> > > +static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
> > > +{
> > > + struct wmi_string *wmistr = (struct wmi_string *)buffer;
> > > + u16 len;
> > > + int ret;
> > > +
> > > + if (!str || !buffer)
> > > + return -EINVAL;
> > > +
> > > + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
> >
> > Use wmistr you introduced above.
> >
> > Passing buffer_len is incorrect, see also
> > drivers/platform/wmi/tests/string_kunit.c for examples.
> >
> This function gave me so many headaches. Thanks for the pointers.
>
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + len = le16_to_cpu(wmistr->length);
> > > + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
> > > + return len; /* minus extra null and + the length field */
> > > +}
> > > +
> > > +/* Send request to BIOS and scan return buffer for error codes */
> > > +static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> > > + struct wmi_buffer *wmibuf)
> > > +{
> > > + struct wmi_buffer wmibuf_return = {0, NULL};
> >
> > = {};
>
> ack
>
> >
> > > + char errstr[32];
> > > + int ret;
> > > +
> > > + ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
> > > + sizeof(struct wmi_string));
> > > + if (!ret && wmibuf_return.data) {
> > > + /* extract error string */
> > > + if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
> >
> > The buffer's length contains the wmi_string's length field, why not
> > subtract it? And you didn't check the wmi_string's validity.
> >
> Not following this one I'm afraid - but I assume it's the same as what sashiko has highlighted? Let me know if you mean something different to sashiko.
Yeah, I meant the same.
>
> > > + ret = -EINVAL;
> > > + else
> > > + ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
> > > + sizeof(errstr));
> > > + kfree(wmibuf_return.data);
> >
> > Why not:
> >
> > if (...)
> > return -EINVAL;
> >
> > struct wmi_string *wmistr __free(kfree) = wmibuf_return.data;
> >
> > ret = wmi_string_to_utf8s();
> >
> Ack - that does look better
>
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + if (!strcmp("Success", errstr))
> > > + return 0;
> > > + else if (!strcmp("Not Supported", errstr))
> > > + return -EOPNOTSUPP;
> > > + else if (!strcmp("Invalid Parameter", errstr))
> > > + return -EINVAL;
> > > + else if (!strcmp("Access Denied", errstr))
> > > + return -EACCES;
> > > + else if (!strcmp("System Busy", errstr))
> > > + return -EBUSY;
> > > + else if (!strcmp("System Locked", errstr))
> > > + return -EACCES;
> > > + dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
> > > + return -EIO;
> >
> > -EPROTO?
> >
> Ack - that's nicer
>
> > > + }
> > > + return ret;
> > > +}
> > > +
> > > +static ssize_t common_type_show(char *possible_values, char *buf)
> > > +{
> > > + if (possible_values) {
> > > + /* Figure out what setting type is as BIOS does not return this */
> > > + if (strchr(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 common_current_value_store(char *name, const char *buf, int wmi_id,
> >
> > `name' should be const char * if you are not intended to manipulate it.
> >
> > > + struct think_lmi *td)
> > > +{
> > > + char *new_setting __free(kfree) = NULL;
> > > + char *wmidata __free(kfree) = NULL;
> >
> > Move them to where the resources are allocated.
> >
> > > + size_t namelen, valuelen;
> > > + struct wmi_buffer wmibuf;
> > > + char *start;
> > > + int ix = 0;
> > > +
> > > + /* If a save has been done then a reboot is needed */
> > > + if (td->reboot_required)
> > > + return -EPERM;
> > > +
> > > + /* Strip out CR if one is present */
> >
> > \n is LF.
> >
> > > + new_setting = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> > > + if (!new_setting)
> > > + return -ENOMEM;
> >
> > I am not in favor of the idea of abusing kstrdup_and_replace(), because:
> >
> > - Only the trailing LF should be stripped
> > - You don't take the advantage of the sysfs buffer size
> >
> > I'd suggest:
> >
> > if (size && buf[size - 1] == '\n')
> > size -= 1;
> > if (!size)
> > return -EINVAL;
> >
> > char *new_setting __free(kfree) = kmemdup_nul(buf, size, GFP_KERNEL);
> >
> > If LF in between is not allowed, please return -EINVAL instead of
> > silently clipping the string.
> >
>
> Funnily enough this bit is borrowed directly from think-lmi. It's probably not needed here as the FW teams are giving much cleaner strings now...but seemed sensible to keep it just in case.
"the FW teams are giving much cleaner strings"
But the string here is given by userspace, isn't it?
>
> Personally I prefer the original but I don't feel strongly about it.
Basically the issue is about the inconsistency of the comment ("Strip out
CR if one is present") and the behavior. "Strip" usually means removing
leading and/or trailing ones, not ones in between, but the behavior here
is simply cutting away anything after the first LF. The behavior leads to
a counterintuitive ABI without any documentation.
Moreover, the behavior mismatches most sysfs attributes, where only the
last trailing LF are allowed to be stripped by default, in order to
properly handle the default behavior of POSIX echo, i.e., `echo whatever
>/sys/attribute'.
By cutting away anything after the first LF, the string written to
firmware could differ from the user's intent (though the intent could be
a mistake). If you want to prevent LF from reaching the firmware, it'd
better to tell userspace about their mistake, instead of making decisions
on their behalf.
OTOH, if you don't want to change the ABI, please mention the behavior in
the documentation. Though I believe it should be harmless to change it as
no one should really relying on the current behavior instead of the de
facto sysfs standard.
I also believe that the temporary buffer can be eliminated as long as
tlmi_populate_string_buffer() accepts an additional parameter to describe
the string's length instead of relying on strlen(), in which case:
/* Determine the string's length in the chosen ABI's manner. */
length = ...
valuelen = struct_size_t(struct wmi_string, chars, length + 1);
...
ix = tlmi_populate_string_buffer(start, valuelen, buf, length);
That being said, since you'll anyway need a copy of the string in
current_value_store(), it's also OK to allocate a buffer and finish the
strip work there.
Thanks,
Rong
>
> > > +
> > > + /* Calculate and alloc buffer for command string */
> > > + namelen = struct_size_t(struct wmi_string, chars, strlen(name) + 1);
> > > + valuelen = struct_size_t(struct wmi_string, chars, strlen(new_setting) + 1);
> > > + wmibuf.length = namelen + valuelen;
> > > + wmidata = kzalloc(wmibuf.length, GFP_KERNEL);
> > > + wmibuf.data = wmidata;
> > > + if (!wmibuf.data)
> > > + return -ENOMEM;
> > > +
> > > + /* build argument buffer from inputs */
> > > + start = wmibuf.data;
> > > + ix = tlmi_populate_string_buffer(start, namelen, name);
> > > + if (ix < 0)
> > > + return ix;
> > > +
> > > + start += ix;
> > > + ix = tlmi_populate_string_buffer(start, valuelen, new_setting);
> > > + if (ix < 0)
> > > + return ix;
> > > +
> > > + return tlmi_request(td->config_wdev, 0, wmi_id, &wmibuf);
> > > +}
> > > +
> > > +/* ---- Attribute sysfs ---- */
> > > +static inline struct tlmi_attr_setting *to_tlmi_attr_setting(struct kobject *kobj)
> > > +{
> > > + return container_of(kobj, struct tlmi_attr_setting, kobj);
> > > +}
> > > +
> > > +static ssize_t display_name_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->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);
> > > +
> > > + guard(mutex)(&tlmi_config_lock);
> > > +
> > > + if (!setting->current_value)
> > > + return sysfs_emit(buf, "unknown\n");
> > > + return sysfs_emit(buf, "%s\n", setting->current_value);
> > > +}
> > > +
> > > +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 ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr,
> > > + char *buf)
> > > +{
> > > + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> > > +
> > > + return common_type_show(setting->possible_values, buf);
> > > +}
> > > +
> > > +static ssize_t current_value_store(struct kobject *kobj,
> > > + struct kobj_attribute *attr,
> > > + const char *buf, size_t count)
> > > +{
> > > + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> > > + struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
> > > + int ret;
> > > +
> > > + guard(mutex)(&tlmi_config_lock);
> > > +
> > > + ret = common_current_value_store(setting->name, buf, SET_ID, td);
> > > + if (!ret) {
> > > + char *s;
> > > +
> > > + td->save_required = true;
> > > + /* Update setting so read back shows correctly */
> > > + s = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
> >
> > ??? Please don't repeat the same operation twice.
>
> Yep - fair.
> >
> > > + kfree(setting->current_value);
> > > + /* if kstrdup fails, we'll handle it in the show */
> > > + setting->current_value = s;
> > > + return count;
> > > + }
> > > + return ret;
> > > +}
> > > +
> > > +static struct kobj_attribute attr_display_name = __ATTR_RO(display_name);
> > > +
> > > +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_display_name.attr,
> > > + &attr_current_val.attr,
> > > + &attr_possible_values.attr,
> > > + &attr_type.attr,
> > > + NULL
> > > +};
> > > +
> > > +static const struct attribute_group tlmi_attr_group = {
> > > + .attrs = tlmi_attrs,
> > > +};
> > > +__ATTRIBUTE_GROUPS(tlmi_attr);
> > > +
> > > +static void tlmi_attr_setting_release(struct kobject *kobj)
> > > +{
> > > + struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> > > +
> > > + tlmi_attr_release_setting(setting);
> > > +}
> > > +
> > > +static const struct kobj_type tlmi_attr_setting_ktype = {
> > > + .release = &tlmi_attr_setting_release,
> > > + .sysfs_ops = &kobj_sysfs_ops,
> > > + .default_groups = tlmi_attr_groups,
> > > +};
> > > +
> > > +/* ---- sysfs entries --------------------------------------------------------- */
> > > +static ssize_t pending_reboot_show(struct kobject *kobj, struct kobj_attribute *attr,
> > > + char *buf)
> > > +{
> > > + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> > > +
> >
> > Why doesn't this need guard(mutex)(&tlmi_config_lock)?
>
> It probably should
> >
> > > + return sysfs_emit(buf, "%d\n", td->pending_changes);
> > > +}
> > > +
> > > +static struct kobj_attribute pending_reboot = __ATTR_RO(pending_reboot);
> > > +
> > > +static ssize_t save_settings_show(struct kobject *kobj, struct kobj_attribute *attr,
> > > + char *buf)
> > > +{
> > > + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> > > +
> >
> > Ditto?
>
> ack
>
> >
> > > + return sysfs_emit(buf, "%d\n", td->save_required);
> > > +}
> > > +
> > > +static ssize_t save_settings_store(struct kobject *kobj, struct kobj_attribute *attr,
> > > + const char *buf, size_t count)
> > > +{
> > > + struct think_lmi *td = dev_get_drvdata(kobj_to_dev(kobj->parent));
> > > + char *wmidata __free(kfree) = NULL;
> > > + struct wmi_buffer wmibuf;
> > > + int ret = 0;
> > > +
> > > + /* save command triggered by writing 'save' */
> > > + if (!sysfs_streq(buf, "save"))
> > > + return -EINVAL;
> > > +
> > > + /* Use lock in case multiple WMI operations needed */
> > > + guard(mutex)(&tlmi_config_lock);
> > > +
> > > + /* Check there is actually something to save */
> > > + if (!td->save_required)
> > > + return -ENOENT;
> >
> > Returning -ENOENT on a file could be confusing IMO.
> >
> > Though thinklmi is already doing so, sigh...
> >
> Yeah. I'm happy to change it to something else. Will look into that for v2.
> Two wrongs don't make a right etc.
>
> Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information
2026-12-04 15:44 ` Mark Pearson
@ 2026-12-04 17:14 ` Rong Zhang
2026-12-04 17:26 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 17:14 UTC (permalink / raw)
To: Mark Pearson
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
Hi Mark,
On Fri, 2026-12-04 at 10:44 -0500, Mark Pearson wrote:
>
> On Fri, Dec 4, 2026, at 8:48 AM, Rong Zhang wrote:
> > Hi Mark,
> >
> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> > > Add authdata module for reading in the authorisation account
> > > details from the BIOS.
> > >
> > > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> > > ---
> > > drivers/platform/x86/lenovo/Makefile | 2 +-
> > > drivers/platform/x86/lenovo/think-lmi.h | 13 ++
> > > drivers/platform/x86/lenovo/tlmi-authdata.c | 135 ++++++++++++++++++++
> > > drivers/platform/x86/lenovo/tlmi-config.c | 10 +-
> > > 4 files changed, 156 insertions(+), 4 deletions(-)
> > > create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
> > >
> > > diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
> > > index d22b56553297..f1600b562273 100644
> > > --- a/drivers/platform/x86/lenovo/Makefile
> > > +++ b/drivers/platform/x86/lenovo/Makefile
> > > @@ -5,7 +5,7 @@
> > > #
> > > obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
> > > obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
> > > -obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
> > > +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
> > > obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
> > >
> > > lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
> > > diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
> > > index 07a235b3a886..75b21dcc2f42 100644
> > > --- a/drivers/platform/x86/lenovo/think-lmi.h
> > > +++ b/drivers/platform/x86/lenovo/think-lmi.h
> > > @@ -13,6 +13,7 @@
> > > #define TLMI_INDEX_MAX 32
> > >
> > > #define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
> > > +#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
> > >
> > > /* Possible error values */
> > > struct tlmi_err_codes {
> > > @@ -75,9 +76,20 @@ struct tlmi_pwdcfg_ext {
> > > uint32_t nvme_master_password;
> > > };
> > >
> > > +/* fields specific to tlmi-authdata driver */
> > > +struct tlmi_pwdcfg_authdata {
> > > + bool strong_password;
> > > + bool deploy_mode;
> > > + bool sys_mgr_pwd_ctrl;
> > > + bool power_on_pwd_ctrl;
> > > + bool storage_pwd_ctrl;
> > > + bool sys_mgr_setup_ctrl;
> > > +};
> > > +
> > > struct tlmi_pwdcfg {
> > > struct tlmi_pwdcfg_core core;
> > > struct tlmi_pwdcfg_ext ext;
> > > + struct tlmi_pwdcfg_authdata authdata;
> > > };
> > >
> > > /* password setting details */
> > > @@ -149,5 +161,6 @@ struct think_lmi {
> > > struct component_match;
> > > void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
> > > void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
> > > +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
> > >
> > > #endif /* !_THINK_LMI_H_ */
> > > diff --git a/drivers/platform/x86/lenovo/tlmi-authdata.c b/drivers/platform/x86/lenovo/tlmi-authdata.c
> > > new file mode 100644
> > > index 000000000000..668d07029139
> > > --- /dev/null
> > > +++ b/drivers/platform/x86/lenovo/tlmi-authdata.c
> > > @@ -0,0 +1,135 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > +/*
> > > + * Lenovo ThinkLMI authentication data WMI interface driver.
> > > + *
> > > + * Read in the WMI authentication settings and their properties.
> > > + *
> > > + * This driver supports the "Common WMI" approach implemented on
> > > + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
> > > + */
> > > +
> > > +#include <linux/cleanup.h>
> > > +#include <linux/component.h>
> > > +#include <linux/device.h>
> > > +#include <linux/module.h>
> > > +#include <linux/types.h>
> > > +#include <linux/wmi.h>
> > > +#include "think-lmi.h"
> > > +
> > > +#define AUTHDATA_ENTRIES 15 /*number of entries returned from BIOS */
> > > +
> > > +static int tlmi_authdata_sanitize(const union acpi_object *obj)
> > > +{
> > > + int i;
> > > +
> > > + /*Scan through query result and check it's sane*/
> > > + if (obj->type != ACPI_TYPE_PACKAGE)
> > > + return -EINVAL;
> > > +
> > > + if (obj->package.count < AUTHDATA_ENTRIES)
> > > + return -EIO;
> > > +
> > > + for (i = 0; i < AUTHDATA_ENTRIES; i++) {
> > > + /* Every entry is an integer which makes this easy */
> > > + if (obj->package.elements[i].type != ACPI_TYPE_INTEGER)
> > > + return -EIO;
> > > + }
> > > + return 0;
> > > +}
> > > +
> > > +/* Get password settings from BIOS */
> > > +static int tlmi_authdata_get(struct wmi_device *wdev, struct think_lmi *td)
> > > +{
> > > + const union acpi_object *obj __free(kfree) = NULL;
> > > + int ret;
> > > +
> > > + obj = wmidev_block_query(wdev, 0);
> > > + if (!obj)
> > > + return -EIO;
> >
> > Use modern WMI APIs and move __free() declaration to wherever the
> > resource is allocated.
> >
> ack
>
> > > +
> > > + ret = tlmi_authdata_sanitize(obj);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + td->pwdcfg.core.password_state = obj->package.elements[0].integer.value;
> > > + td->pwdcfg.core.min_length = obj->package.elements[1].integer.value;
> > > + td->pwdcfg.core.max_length = obj->package.elements[2].integer.value;
> > > + td->pwdcfg.authdata.strong_password = obj->package.elements[3].integer.value;
> > > + td->pwdcfg.core.supported_encodings = obj->package.elements[4].integer.value;
> > > + td->pwdcfg.core.supported_keyboard = obj->package.elements[5].integer.value;
> > > + td->pwdcfg.ext.hdd_user_password = obj->package.elements[6].integer.value;
> > > + td->pwdcfg.ext.hdd_master_password = obj->package.elements[7].integer.value;
> > > + td->pwdcfg.ext.nvme_user_password = obj->package.elements[8].integer.value;
> > > + td->pwdcfg.ext.nvme_master_password = obj->package.elements[9].integer.value;
> > > + td->pwdcfg.authdata.deploy_mode = obj->package.elements[10].integer.value;
> > > + td->pwdcfg.authdata.sys_mgr_pwd_ctrl = obj->package.elements[11].integer.value;
> > > + td->pwdcfg.authdata.power_on_pwd_ctrl = obj->package.elements[12].integer.value;
> > > + td->pwdcfg.authdata.storage_pwd_ctrl = obj->package.elements[13].integer.value;
> > > + td->pwdcfg.authdata.sys_mgr_setup_ctrl = obj->package.elements[14].integer.value;
> > > +
> > > + if (WARN_ON(td->pwdcfg.core.max_length >= TLMI_PWD_BUFSIZE))
> > > + td->pwdcfg.core.max_length = TLMI_PWD_BUFSIZE - 1;
> > > + if (WARN_ON(td->pwdcfg.core.min_length > td->pwdcfg.core.max_length))
> > > + td->pwdcfg.core.min_length = td->pwdcfg.core.max_length;
> >
> > Why would you need to WARN_ON() firmware stuff? Usually it's meant for
> > kernel stuff.
> >
> I've seen warns for FW stuff lots of the time. It handy as when we do Linux enablement we try quite hard to make sure the kernel boot log is clean of errors and warnings.
> My goal here is that if a platform BIOS is giving invalid values then I get a nice warning that I can go and beat up a FW team about. I'd like to leave this in.
WARN_ON() is basically tagging something as "really wrong and shouldn't
happen", so the next step is usually to bail out ASAP. OTOH, the fallback
paths following WARN_ON() are also indicating the situations as "not that
wrong and may happen".
It's quite inconsistent to have both.
>
> > > +
> > > + return 0;
And the function still succeeds after WARN_ON().
So, for consistency, I'd suggest either demote the WARN_ON() to
dev_warn(), or remove the fallback paths and bail out immediately.
Thanks,
Rong
> > > +}
> > > +
> > > +static int tlmi_authdata_component_bind(struct device *authdata_dev, struct device *config_dev,
> > > + void *d)
> > > +{
> > > + struct wmi_device *wdev = dev_get_drvdata(authdata_dev);
> > > + struct think_lmi *td = d;
> > > +
> > > + return tlmi_authdata_get(wdev, td);
> > > +}
> > > +
> > > +static const struct component_ops tlmi_authdata_component_ops = {
> > > + .bind = tlmi_authdata_component_bind,
> > > +};
> > > +
> > > +static int tlmi_authdata_probe(struct wmi_device *wdev, const void *context)
> > > +{
> > > + dev_set_drvdata(&wdev->dev, wdev);
> > > +
> > > + return component_add(&wdev->dev, &tlmi_authdata_component_ops);
> > > +}
> > > +
> > > +static void tlmi_authdata_remove(struct wmi_device *wdev)
> > > +{
> > > + component_del(&wdev->dev, &tlmi_authdata_component_ops);
> > > +}
> > > +
> > > +static const struct wmi_device_id tlmi_authdata_id_table[] = {
> > > + { TLMI_AUTHENTICATION_DATA_GUID, NULL },
> > > + {}
> > > +};
> > > +
> > > +static struct wmi_driver tlmi_authdata_driver = {
> > > + .driver = {
> > > + .name = "tlmi-authdata",
> > > + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
> > > + },
> > > + .id_table = tlmi_authdata_id_table,
> > > + .probe = tlmi_authdata_probe,
> > > + .remove = tlmi_authdata_remove,
> > > + .no_singleton = true,
> > > +};
> > > +
> > > +static int tlmi_authdata_match(struct device *dev, void *type)
> > > +{
> > > + return (dev->driver == &tlmi_authdata_driver.driver);
> > > +}
> > > +
> > > +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr)
> > > +{
> > > + component_match_add(master, matchptr, tlmi_authdata_match, NULL);
> > > +}
> > > +EXPORT_SYMBOL_NS_GPL(tlmi_authdata_match_add, "TLMI-AUTHDATA");
> > > +
> > > +module_wmi_driver(tlmi_authdata_driver);
> > > +
> > > +MODULE_DEVICE_TABLE(wmi, tlmi_authdata_id_table);
> > > +MODULE_AUTHOR("Mark Pearson <mpearson-lenovo@squebb.ca>");
> > > +MODULE_DESCRIPTION("ThinkLMI Authentication Data WMI Driver");
> > > +MODULE_LICENSE("GPL");
> > > diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> > > index ef5efae2e395..ddbf0307f810 100644
> > > --- a/drivers/platform/x86/lenovo/tlmi-config.c
> > > +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> > > @@ -415,14 +415,16 @@ static const struct component_master_ops aggregate_ops = {
> > > static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> > > {
> > > struct component_match *match = NULL;
> > > - guid_t tlmi_attr_guid;
> > > + guid_t tlmi_attr_guid, tlmi_authdata_guid;
> > > struct think_lmi *td;
> > > int ret;
> > >
> > > guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
> > > + guid_parse(TLMI_AUTHENTICATION_DATA_GUID, &tlmi_authdata_guid);
> >
> > ret =
> > if (ret)
> >
> > >
> > > - /* At minimum need to support BIOS settings */
> > > - if (!wmidev_exists(&tlmi_attr_guid))
> > > + /* At minimum need to support BIOS and authentication settings */
> > > + if (!wmidev_exists(&tlmi_attr_guid) ||
> > > + !wmidev_exists(&tlmi_authdata_guid))
> > > return -EOPNOTSUPP;
> > >
> > > td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
> > > @@ -440,6 +442,7 @@ static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
> > >
> > > /* Register the other components */
> > > tlmi_attr_match_add(&wdev->dev, &match);
> > > + tlmi_authdata_match_add(&wdev->dev, &match);
> >
> > Check errors.
> >
> Ack
>
> Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
2026-12-04 15:50 ` Mark Pearson
@ 2026-12-04 17:19 ` Rong Zhang
2026-12-04 17:27 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 17:19 UTC (permalink / raw)
To: Mark Pearson
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
Hi Mark,
On Fri, 2026-12-04 at 10:50 -0500, Mark Pearson wrote:
>
> On Fri, Dec 4, 2026, at 8:49 AM, Rong Zhang wrote:
> > Hi Mark,
> >
> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> > > The tlmi_populate_string_buffer and tlmi_request are going to be
> > > needed in the upcoming tlmi-auth module, as well as the current
> > > tlmi-config module.
> > >
> > > As we can't have circular dependencies they need to move out of
> > > tlmi-config.
> > >
> > > The wmi-helpers module already provides helper functions for the
> > > Lenovo Legion platforms, and seems a logical place for these to
> > > move too.
> > >
> > > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> > > ---
> > > drivers/platform/x86/lenovo/Kconfig | 1 +
> > > drivers/platform/x86/lenovo/tlmi-config.c | 59 +-------------------
> > > drivers/platform/x86/lenovo/wmi-helpers.c | 65 ++++++++++++++++++++++-
> > > drivers/platform/x86/lenovo/wmi-helpers.h | 5 ++
> > > 4 files changed, 72 insertions(+), 58 deletions(-)
> > >
> > > diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
> > > index 16569406c946..c59461cf5f4a 100644
> > > --- a/drivers/platform/x86/lenovo/Kconfig
> > > +++ b/drivers/platform/x86/lenovo/Kconfig
> > > @@ -218,6 +218,7 @@ config THINKPAD_LMI
> > > depends on ACPI_WMI
> > > depends on DMI
> > > select FW_ATTR_CLASS
> > > + select LENOVO_WMI_HELPERS
> >
> > Ba aware of
> > https://msgid.link/f8815e94ddc161495ca80b04d7e3388549edafeb.camel@rong.moe
> > if you'd need to rebase on top of David's series.
> >
> Ack - I figured the review process was going to be a rough ride for this series. I'm sure I'll be rebasing a few times before we're done.
> I actually wonder if I'll need to move this whole driver....
It's up to Lenovo's production plan.
If any ARM64 devices will use the thinklmi interface in the future, I'd
suggest that we should move it. Otherwise we should leave them as they
as.
Thanks,
Rong
>
> > > help
> > > This driver allows changing BIOS settings on Lenovo machines whose
> > > BIOS support the WMI interface.
> > > diff --git a/drivers/platform/x86/lenovo/tlmi-config.c b/drivers/platform/x86/lenovo/tlmi-config.c
> > > index ddbf0307f810..bb9c5f720c24 100644
> > > --- a/drivers/platform/x86/lenovo/tlmi-config.c
> > > +++ b/drivers/platform/x86/lenovo/tlmi-config.c
> > > @@ -22,6 +22,7 @@
> > > #include <linux/types.h>
> > > #include <linux/wmi.h>
> > > #include "think-lmi.h"
> > > +#include "wmi-helpers.h"
> > >
> > > #define TLMI_CONFIG_GUID "816E5C9E-3E99-4385-AA5A-7353E14B781B"
> > >
> > > @@ -33,63 +34,6 @@ static DEFINE_MUTEX(tlmi_config_lock);
> > >
> > > /* ---- Helper functions---- */
> > >
> > > -static ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
> > > -{
> > > - struct wmi_string *wmistr = (struct wmi_string *)buffer;
> > > - u16 len;
> > > - int ret;
> > > -
> > > - if (!str || !buffer)
> > > - return -EINVAL;
> > > -
> > > - ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
> > > - if (ret < 0)
> > > - return ret;
> > > -
> > > - len = le16_to_cpu(wmistr->length);
> > > - wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
> > > - return len; /* minus extra null and + the length field */
> > > -}
> > > -
> > > -/* Send request to BIOS and scan return buffer for error codes */
> > > -static int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> > > - struct wmi_buffer *wmibuf)
> > > -{
> > > - struct wmi_buffer wmibuf_return = {0, NULL};
> > > - char errstr[32];
> > > - int ret;
> > > -
> > > - ret = wmidev_invoke_method(wdev, instance, method_id, wmibuf, &wmibuf_return,
> > > - sizeof(struct wmi_string));
> > > - if (!ret && wmibuf_return.data) {
> > > - /* extract error string */
> > > - if (wmibuf_return.length < 2 || wmibuf_return.length > sizeof(errstr) * 2)
> > > - ret = -EINVAL;
> > > - else
> > > - ret = wmi_string_to_utf8s((struct wmi_string *)wmibuf_return.data, errstr,
> > > - sizeof(errstr));
> > > - kfree(wmibuf_return.data);
> > > - if (ret < 0)
> > > - return ret;
> > > -
> > > - if (!strcmp("Success", errstr))
> > > - return 0;
> > > - else if (!strcmp("Not Supported", errstr))
> > > - return -EOPNOTSUPP;
> > > - else if (!strcmp("Invalid Parameter", errstr))
> > > - return -EINVAL;
> > > - else if (!strcmp("Access Denied", errstr))
> > > - return -EACCES;
> > > - else if (!strcmp("System Busy", errstr))
> > > - return -EBUSY;
> > > - else if (!strcmp("System Locked", errstr))
> > > - return -EACCES;
> > > - dev_warn(&wdev->dev, "Unknown error condition %s\n", errstr);
> > > - return -EIO;
> > > - }
> > > - return ret;
> > > -}
> > > -
> >
> > What? Wasn't these just introduced before? Could you add them to the
> > right place from the beginning?
> >
> Probably a bad call on my part - a little bit part of how I went about developing the driver and building up the patchset.
> I'll move this up much earlier in the series and get rid of the move if that helps.
>
> > > static ssize_t common_type_show(char *possible_values, char *buf)
> > > {
> > > if (possible_values) {
> > > @@ -477,6 +421,7 @@ static struct wmi_driver tlmi_config_driver = {
> > >
> > > module_wmi_driver(tlmi_config_driver);
> > >
> > > +MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
> > > MODULE_IMPORT_NS("TLMI-ATTR");
> > > MODULE_IMPORT_NS("TLMI-AUTHDATA");
> > > MODULE_DEVICE_TABLE(wmi, tlmi_config_id_table);
> > > diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
> > > index 687caa226263..e735771bb8d7 100644
> > > --- a/drivers/platform/x86/lenovo/wmi-helpers.c
> > > +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
> > > @@ -1,6 +1,6 @@
> > > // SPDX-License-Identifier: GPL-2.0-or-later
> > > /*
> > > - * Lenovo Legion WMI helpers driver.
> > > + * Lenovo Legion and TLMI WMI helpers driver.
> > > *
> > > * The Lenovo Legion WMI interface is broken up into multiple GUID interfaces
> > > * that require cross-references between GUID's for some functionality. The
> > > @@ -13,6 +13,10 @@
> > > * drivers uses a common procedure to get data from the WMI interface,
> > > * enumerated here.
> > > *
> > > + * TLMI interface uses multiple GUID interfaces for BIOS settings and
> > > + * authentication settings. A common procedure is used to get data from the
> > > + * WMI interface and check for return error strings.
> > > + *
> > > * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com>
> > > */
> > >
> > > @@ -33,6 +37,65 @@
> > > /* Thermal mode notifier chain. */
> > > static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
> > >
> > > +ssize_t tlmi_populate_string_buffer(char *buffer, size_t buffer_len, const char *str)
> >
> > Why not void *buffer?
> >
> > > +{
> > > + struct wmi_string *wmistr = (struct wmi_string *)buffer;
> > > + u16 len;
> > > + int ret;
> > > +
> > > + if (!str || !buffer)
> > > + return -EINVAL;
> > > +
> > > + ret = wmi_string_from_utf8s((struct wmi_string *)buffer, buffer_len, str, strlen(str));
> > > + if (ret < 0)
> > > + return ret;
> > > +
> > > + len = le16_to_cpu(wmistr->length);
> > > + wmistr->length = cpu_to_le16(len - 2); /* Remove the extra null added */
> > > + return len; /* minus extra null and + the length field */
> > > +}
> > > +EXPORT_SYMBOL_NS_GPL(tlmi_populate_string_buffer, "LENOVO_WMI_HELPERS");
> >
> > I believe this helper can be named lwmi_* as it's not coupled with
> > thinklmi...
> >
> Sure
>
> > > +
> > > +/* Send request to BIOS and scan return buffer for error codes */
> > > +int tlmi_request(struct wmi_device *wdev, u8 instance, u32 method_id,
> > > + struct wmi_buffer *wmibuf)
> >
> > ...while this is coupled with thinklmi, so this can be named tlmi_*.
> >
> Thanks
> Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information
2026-12-04 17:14 ` Rong Zhang
@ 2026-12-04 17:26 ` Mark Pearson
0 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 17:26 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 12:14 PM, Rong Zhang wrote:
> Hi Mark,
>
> On Fri, 2026-12-04 at 10:44 -0500, Mark Pearson wrote:
>>
>> On Fri, Dec 4, 2026, at 8:48 AM, Rong Zhang wrote:
>> > Hi Mark,
>> >
>> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> > > Add authdata module for reading in the authorisation account
>> > > details from the BIOS.
>> > >
>> > > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> > > ---
>> > > drivers/platform/x86/lenovo/Makefile | 2 +-
>> > > drivers/platform/x86/lenovo/think-lmi.h | 13 ++
>> > > drivers/platform/x86/lenovo/tlmi-authdata.c | 135 ++++++++++++++++++++
>> > > drivers/platform/x86/lenovo/tlmi-config.c | 10 +-
>> > > 4 files changed, 156 insertions(+), 4 deletions(-)
>> > > create mode 100644 drivers/platform/x86/lenovo/tlmi-authdata.c
>> > >
>> > > diff --git a/drivers/platform/x86/lenovo/Makefile b/drivers/platform/x86/lenovo/Makefile
>> > > index d22b56553297..f1600b562273 100644
>> > > --- a/drivers/platform/x86/lenovo/Makefile
>> > > +++ b/drivers/platform/x86/lenovo/Makefile
>> > > @@ -5,7 +5,7 @@
>> > > #
>> > > obj-$(CONFIG_IDEAPAD_LAPTOP) += ideapad-laptop.o
>> > > obj-$(CONFIG_THINKPAD_LMI) += think-lmi.o
>> > > -obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o
>> > > +obj-$(CONFIG_THINKPAD_LMI) += tlmi-config.o tlmi-attr.o tlmi-authdata.o
>> > > obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
>> > >
>> > > lenovo-target-$(CONFIG_LENOVO_WMI_HOTKEY_UTILITIES) += wmi-hotkey-utilities.o
>> > > diff --git a/drivers/platform/x86/lenovo/think-lmi.h b/drivers/platform/x86/lenovo/think-lmi.h
>> > > index 07a235b3a886..75b21dcc2f42 100644
>> > > --- a/drivers/platform/x86/lenovo/think-lmi.h
>> > > +++ b/drivers/platform/x86/lenovo/think-lmi.h
>> > > @@ -13,6 +13,7 @@
>> > > #define TLMI_INDEX_MAX 32
>> > >
>> > > #define TLMI_ATTRIBUTE_GUID "4B79FBA6-FFD4-41B6-8EA8-E81CDA0F5FC3"
>> > > +#define TLMI_AUTHENTICATION_DATA_GUID "1178acfd-78a1-46d8-a8eb-5f7cb74a3b4e"
>> > >
>> > > /* Possible error values */
>> > > struct tlmi_err_codes {
>> > > @@ -75,9 +76,20 @@ struct tlmi_pwdcfg_ext {
>> > > uint32_t nvme_master_password;
>> > > };
>> > >
>> > > +/* fields specific to tlmi-authdata driver */
>> > > +struct tlmi_pwdcfg_authdata {
>> > > + bool strong_password;
>> > > + bool deploy_mode;
>> > > + bool sys_mgr_pwd_ctrl;
>> > > + bool power_on_pwd_ctrl;
>> > > + bool storage_pwd_ctrl;
>> > > + bool sys_mgr_setup_ctrl;
>> > > +};
>> > > +
>> > > struct tlmi_pwdcfg {
>> > > struct tlmi_pwdcfg_core core;
>> > > struct tlmi_pwdcfg_ext ext;
>> > > + struct tlmi_pwdcfg_authdata authdata;
>> > > };
>> > >
>> > > /* password setting details */
>> > > @@ -149,5 +161,6 @@ struct think_lmi {
>> > > struct component_match;
>> > > void tlmi_attr_match_add(struct device *master, struct component_match **matchptr);
>> > > void tlmi_attr_release_setting(struct tlmi_attr_setting *setting);
>> > > +void tlmi_authdata_match_add(struct device *master, struct component_match **matchptr);
>> > >
>> > > #endif /* !_THINK_LMI_H_ */
>> > > diff --git a/drivers/platform/x86/lenovo/tlmi-authdata.c b/drivers/platform/x86/lenovo/tlmi-authdata.c
>> > > new file mode 100644
>> > > index 000000000000..668d07029139
>> > > --- /dev/null
>> > > +++ b/drivers/platform/x86/lenovo/tlmi-authdata.c
>> > > @@ -0,0 +1,135 @@
>> > > +// SPDX-License-Identifier: GPL-2.0-or-later
>> > > +/*
>> > > + * Lenovo ThinkLMI authentication data WMI interface driver.
>> > > + *
>> > > + * Read in the WMI authentication settings and their properties.
>> > > + *
>> > > + * This driver supports the "Common WMI" approach implemented on
>> > > + * Thinkpad, ThinkStation & ThinkCenter from 2027 onwards.
>> > > + */
>> > > +
>> > > +#include <linux/cleanup.h>
>> > > +#include <linux/component.h>
>> > > +#include <linux/device.h>
>> > > +#include <linux/module.h>
>> > > +#include <linux/types.h>
>> > > +#include <linux/wmi.h>
>> > > +#include "think-lmi.h"
>> > > +
>> > > +#define AUTHDATA_ENTRIES 15 /*number of entries returned from BIOS */
>> > > +
>> > > +static int tlmi_authdata_sanitize(const union acpi_object *obj)
>> > > +{
>> > > + int i;
>> > > +
>> > > + /*Scan through query result and check it's sane*/
>> > > + if (obj->type != ACPI_TYPE_PACKAGE)
>> > > + return -EINVAL;
>> > > +
>> > > + if (obj->package.count < AUTHDATA_ENTRIES)
>> > > + return -EIO;
>> > > +
>> > > + for (i = 0; i < AUTHDATA_ENTRIES; i++) {
>> > > + /* Every entry is an integer which makes this easy */
>> > > + if (obj->package.elements[i].type != ACPI_TYPE_INTEGER)
>> > > + return -EIO;
>> > > + }
>> > > + return 0;
>> > > +}
>> > > +
>> > > +/* Get password settings from BIOS */
>> > > +static int tlmi_authdata_get(struct wmi_device *wdev, struct think_lmi *td)
>> > > +{
>> > > + const union acpi_object *obj __free(kfree) = NULL;
>> > > + int ret;
>> > > +
>> > > + obj = wmidev_block_query(wdev, 0);
>> > > + if (!obj)
>> > > + return -EIO;
>> >
>> > Use modern WMI APIs and move __free() declaration to wherever the
>> > resource is allocated.
>> >
>> ack
>>
>> > > +
>> > > + ret = tlmi_authdata_sanitize(obj);
>> > > + if (ret)
>> > > + return ret;
>> > > +
>> > > + td->pwdcfg.core.password_state = obj->package.elements[0].integer.value;
>> > > + td->pwdcfg.core.min_length = obj->package.elements[1].integer.value;
>> > > + td->pwdcfg.core.max_length = obj->package.elements[2].integer.value;
>> > > + td->pwdcfg.authdata.strong_password = obj->package.elements[3].integer.value;
>> > > + td->pwdcfg.core.supported_encodings = obj->package.elements[4].integer.value;
>> > > + td->pwdcfg.core.supported_keyboard = obj->package.elements[5].integer.value;
>> > > + td->pwdcfg.ext.hdd_user_password = obj->package.elements[6].integer.value;
>> > > + td->pwdcfg.ext.hdd_master_password = obj->package.elements[7].integer.value;
>> > > + td->pwdcfg.ext.nvme_user_password = obj->package.elements[8].integer.value;
>> > > + td->pwdcfg.ext.nvme_master_password = obj->package.elements[9].integer.value;
>> > > + td->pwdcfg.authdata.deploy_mode = obj->package.elements[10].integer.value;
>> > > + td->pwdcfg.authdata.sys_mgr_pwd_ctrl = obj->package.elements[11].integer.value;
>> > > + td->pwdcfg.authdata.power_on_pwd_ctrl = obj->package.elements[12].integer.value;
>> > > + td->pwdcfg.authdata.storage_pwd_ctrl = obj->package.elements[13].integer.value;
>> > > + td->pwdcfg.authdata.sys_mgr_setup_ctrl = obj->package.elements[14].integer.value;
>> > > +
>> > > + if (WARN_ON(td->pwdcfg.core.max_length >= TLMI_PWD_BUFSIZE))
>> > > + td->pwdcfg.core.max_length = TLMI_PWD_BUFSIZE - 1;
>> > > + if (WARN_ON(td->pwdcfg.core.min_length > td->pwdcfg.core.max_length))
>> > > + td->pwdcfg.core.min_length = td->pwdcfg.core.max_length;
>> >
>> > Why would you need to WARN_ON() firmware stuff? Usually it's meant for
>> > kernel stuff.
>> >
>> I've seen warns for FW stuff lots of the time. It handy as when we do Linux enablement we try quite hard to make sure the kernel boot log is clean of errors and warnings.
>> My goal here is that if a platform BIOS is giving invalid values then I get a nice warning that I can go and beat up a FW team about. I'd like to leave this in.
>
> WARN_ON() is basically tagging something as "really wrong and shouldn't
> happen", so the next step is usually to bail out ASAP. OTOH, the fallback
> paths following WARN_ON() are also indicating the situations as "not that
> wrong and may happen".
>
> It's quite inconsistent to have both.
>
>>
>> > > +
>> > > + return 0;
>
> And the function still succeeds after WARN_ON().
>
> So, for consistency, I'd suggest either demote the WARN_ON() to
> dev_warn(), or remove the fallback paths and bail out immediately.
>
fair enough - I can do that.
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
2026-12-04 17:19 ` Rong Zhang
@ 2026-12-04 17:27 ` Mark Pearson
0 siblings, 0 replies; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 17:27 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 12:19 PM, Rong Zhang wrote:
> Hi Mark,
>
> On Fri, 2026-12-04 at 10:50 -0500, Mark Pearson wrote:
>>
>> On Fri, Dec 4, 2026, at 8:49 AM, Rong Zhang wrote:
>> > Hi Mark,
>> >
>> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> > > The tlmi_populate_string_buffer and tlmi_request are going to be
>> > > needed in the upcoming tlmi-auth module, as well as the current
>> > > tlmi-config module.
>> > >
>> > > As we can't have circular dependencies they need to move out of
>> > > tlmi-config.
>> > >
>> > > The wmi-helpers module already provides helper functions for the
>> > > Lenovo Legion platforms, and seems a logical place for these to
>> > > move too.
>> > >
>> > > Signed-off-by: Mark Pearson <mpearson-lenovo@squebb.ca>
>> > > ---
>> > > drivers/platform/x86/lenovo/Kconfig | 1 +
>> > > drivers/platform/x86/lenovo/tlmi-config.c | 59 +-------------------
>> > > drivers/platform/x86/lenovo/wmi-helpers.c | 65 ++++++++++++++++++++++-
>> > > drivers/platform/x86/lenovo/wmi-helpers.h | 5 ++
>> > > 4 files changed, 72 insertions(+), 58 deletions(-)
>> > >
>> > > diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
>> > > index 16569406c946..c59461cf5f4a 100644
>> > > --- a/drivers/platform/x86/lenovo/Kconfig
>> > > +++ b/drivers/platform/x86/lenovo/Kconfig
>> > > @@ -218,6 +218,7 @@ config THINKPAD_LMI
>> > > depends on ACPI_WMI
>> > > depends on DMI
>> > > select FW_ATTR_CLASS
>> > > + select LENOVO_WMI_HELPERS
>> >
>> > Ba aware of
>> > https://msgid.link/f8815e94ddc161495ca80b04d7e3388549edafeb.camel@rong.moe
>> > if you'd need to rebase on top of David's series.
>> >
>> Ack - I figured the review process was going to be a rough ride for this series. I'm sure I'll be rebasing a few times before we're done.
>> I actually wonder if I'll need to move this whole driver....
>
> It's up to Lenovo's production plan.
>
> If any ARM64 devices will use the thinklmi interface in the future, I'd
> suggest that we should move it. Otherwise we should leave them as they
> as.
>
It's likely....
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 00/13] New Lenovo common WMI driver - tlmi
2026-12-04 14:42 ` Mark Pearson
@ 2026-12-04 17:49 ` Rong Zhang
2026-12-04 18:22 ` Mark Pearson
0 siblings, 1 reply; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 17:49 UTC (permalink / raw)
To: Mark Pearson
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
Hi Mark,
On Fri, 2026-12-04 at 09:42 -0500, Mark Pearson wrote:
> On Fri, Dec 4, 2026, at 8:19 AM, Rong Zhang wrote:
> > Hi Mark,
> >
> > Thanks for working on this.
> >
> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> > > This series introduces support for a new Lenovo 'common WMI'
> > > implementation.
> > >
> > > The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
> > > WMI methods for interfacing with the BIOS settings. This implementation
> > > will be available for 2027 platforms and is intended to be common across
> > > the business units.
> > >
> > > The new driver is called tlmi and can run alongside the existing
> > > think-lmi driver. Initially the BIOS's will support both interfaces.
> > >
> > > The first 5 patches in the series update the existing think-lmi driver
> > > with changes that means it can share structures with the new tlmi
> > > driver. They also introduce fixes for issues I found when implementing
> > > tlmi.
> > > The remaining patches introduce the new tlmi functionality. I've tried
> > > to break them up into reviewable chunks.
> > >
> > > The tlmi driver for now offers the same functionality as think-lmi -
> > > with support for modifying BIOS settings and authentication options.
> > > It also introduces 'platform' settings and 'function' settings.
> > >
> > > During implementation I needed some functionality to be common between
> > > modules. Using the wmi-helpers module seemed a good place for this, but
> > > please let me know if it's not suitable.
> > >
> > > Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
> > > Thinkstation P5 G2.
> > >
> > > Much of this implementation builds on the recommendations from Armin,
> > > Derek and Ilpo from the original RFC. Many thanks for the guidance.
> > >
> > > Mark Pearson (13):
> > > platform/x86: lenovo: think-lmi: Convert name arrays to pointers
> > > platform/x86: lenovo: think-lmi: Clean up attributes if not added to
> > > list
> > > platform/x86: lenovo: think-lmi: cache current value at init
> > > platform/x86: lenovo: think-lmi: store attributes as linked list
> > > platform/x86: lenovo: tlmi: New tlmi driver for common WMI
> > > implementation
> > > platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
> > > platform/x86: lenovo: tlmi: Retrieve auth information
> > > platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
> > > platform/x86: lenovo: tlmi: Add authentication sysfs entries
> > > platform/x86: lenovo: tlmi: Add platform attribute support
> > > platform/x86: lenovo: tlmi: Add function attributes support
> > > platform/x86: lenovo: tlmi: Add method identifier
> > > docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
> >
> > Sashiko found quite a lot of issues in the series, so I am not going to
> > seriously review this series yet, in case you'd need to change the design
> > a lot in the next revision.
> >
>
> Yeah....that's going to keep me busy. They didn't show up in my inbox so I had to go looking for them.
>
> I'd been running sashiko with a few tokens I managed to get through work and thought I had it at the stage where it was pretty clean (and I'd run out of tokens). Looks like some new things which is interesting.
I've been doing so, too. I always make stupid mistakes so my Sashiko
instance helps me get rid most of them before submitting.
My suggestion is to keep Sashiko up to date and choose an appropriate
model. What model did you use?
If you are using DeepSeek V4.1 Flash 1017, do not set effort to max.
Sashiko's prompts make it prone to overthink, and such overthink has a
potential to cause it to focus on minor issues rather than critical ones,
as well as making it very expensive :-/
If you are using a /chat/completions endpoint, please set
send_reasoning_content = true, or else the model will lose its mind
(literally, i.e., losing its chain of thought).
Note that some providers' /chat/completions endpoints return CoT in
another field called "reasoning", which is unsupported by
send_reasoning_content. In this case consider switching to api =
"responses".
Thanks,
Rong
>
> > That being said, I will glance at each patch and see if I have some
> > additional suggestions on the design.
> >
>
> Thanks - appreciate it - especially if I'm doing things incorrectly from a design perspective.
> This whole feature turned out to be more of a beast than I expected.
>
> Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 00/13] New Lenovo common WMI driver - tlmi
2026-12-04 17:49 ` Rong Zhang
@ 2026-12-04 18:22 ` Mark Pearson
2026-12-04 20:04 ` Rong Zhang
0 siblings, 1 reply; 44+ messages in thread
From: Mark Pearson @ 2026-12-04 18:22 UTC (permalink / raw)
To: Rong Zhang
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
On Fri, Dec 4, 2026, at 12:49 PM, Rong Zhang wrote:
> Hi Mark,
>
> On Fri, 2026-12-04 at 09:42 -0500, Mark Pearson wrote:
>> On Fri, Dec 4, 2026, at 8:19 AM, Rong Zhang wrote:
>> > Hi Mark,
>> >
>> > Thanks for working on this.
>> >
>> > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
>> > > This series introduces support for a new Lenovo 'common WMI'
>> > > implementation.
>> > >
>> > > The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
>> > > WMI methods for interfacing with the BIOS settings. This implementation
>> > > will be available for 2027 platforms and is intended to be common across
>> > > the business units.
>> > >
>> > > The new driver is called tlmi and can run alongside the existing
>> > > think-lmi driver. Initially the BIOS's will support both interfaces.
>> > >
>> > > The first 5 patches in the series update the existing think-lmi driver
>> > > with changes that means it can share structures with the new tlmi
>> > > driver. They also introduce fixes for issues I found when implementing
>> > > tlmi.
>> > > The remaining patches introduce the new tlmi functionality. I've tried
>> > > to break them up into reviewable chunks.
>> > >
>> > > The tlmi driver for now offers the same functionality as think-lmi -
>> > > with support for modifying BIOS settings and authentication options.
>> > > It also introduces 'platform' settings and 'function' settings.
>> > >
>> > > During implementation I needed some functionality to be common between
>> > > modules. Using the wmi-helpers module seemed a good place for this, but
>> > > please let me know if it's not suitable.
>> > >
>> > > Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
>> > > Thinkstation P5 G2.
>> > >
>> > > Much of this implementation builds on the recommendations from Armin,
>> > > Derek and Ilpo from the original RFC. Many thanks for the guidance.
>> > >
>> > > Mark Pearson (13):
>> > > platform/x86: lenovo: think-lmi: Convert name arrays to pointers
>> > > platform/x86: lenovo: think-lmi: Clean up attributes if not added to
>> > > list
>> > > platform/x86: lenovo: think-lmi: cache current value at init
>> > > platform/x86: lenovo: think-lmi: store attributes as linked list
>> > > platform/x86: lenovo: tlmi: New tlmi driver for common WMI
>> > > implementation
>> > > platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
>> > > platform/x86: lenovo: tlmi: Retrieve auth information
>> > > platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
>> > > platform/x86: lenovo: tlmi: Add authentication sysfs entries
>> > > platform/x86: lenovo: tlmi: Add platform attribute support
>> > > platform/x86: lenovo: tlmi: Add function attributes support
>> > > platform/x86: lenovo: tlmi: Add method identifier
>> > > docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
>> >
>> > Sashiko found quite a lot of issues in the series, so I am not going to
>> > seriously review this series yet, in case you'd need to change the design
>> > a lot in the next revision.
>> >
>>
>> Yeah....that's going to keep me busy. They didn't show up in my inbox so I had to go looking for them.
>>
>> I'd been running sashiko with a few tokens I managed to get through work and thought I had it at the stage where it was pretty clean (and I'd run out of tokens). Looks like some new things which is interesting.
>
> I've been doing so, too. I always make stupid mistakes so my Sashiko
> instance helps me get rid most of them before submitting.
>
> My suggestion is to keep Sashiko up to date and choose an appropriate
> model. What model did you use?
>
> If you are using DeepSeek V4.1 Flash 1017, do not set effort to max.
> Sashiko's prompts make it prone to overthink, and such overthink has a
> potential to cause it to focus on minor issues rather than critical ones,
> as well as making it very expensive :-/
>
> If you are using a /chat/completions endpoint, please set
> send_reasoning_content = true, or else the model will lose its mind
> (literally, i.e., losing its chain of thought).
>
> Note that some providers' /chat/completions endpoints return CoT in
> another field called "reasoning", which is unsupported by
> send_reasoning_content. In this case consider switching to api =
> "responses".
>
I haven't spent a lot time playing with it - I have been using it via copilot-cli (how Lenovo gives us a few tokens a month) and there I've been using claude-sonnet-4.5.
Overall it's been quite helpful for ironing out a lot of things I've missed or done wrong. My main issue is that I don't get a lot of tokens a month so I don't iterate much. I can burn thru all my allocation reviewing this 13 patch series (someone else can do the maths...but yeah, it's not a lot). Maybe I should pay for some myself but I've not gotten to that stage yet.
I haven't really gone and tried any other models. On my todo list is to see what I can do locally (I'm fortunate enough to have access to some really quite nice HW....perks of the job) - but just haven't got to it. Maybe over the holidays, but realistically more likely next year.
I'm totally OK if any reviewers ignore my patch series until I've dealt with Sashiko too, FWIW.
Thanks for the tips. I did read the Sashiko guide (and a few blogs) but it's quite tricky to figure out what is effective whilst not expensive etc. I'm not the biggest AI enthusiast (I lean slightly the other way) - but I do recognise how it helps me write better code
Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 00/13] New Lenovo common WMI driver - tlmi
2026-12-04 18:22 ` Mark Pearson
@ 2026-12-04 20:04 ` Rong Zhang
0 siblings, 0 replies; 44+ messages in thread
From: Rong Zhang @ 2026-12-04 20:04 UTC (permalink / raw)
To: Mark Pearson
Cc: Derek J . Clark, Hans de Goede, Ilpo Järvinen,
platform-driver-x86@vger.kernel.org, linux-kernel
Hi Mark,
On Fri, 2026-12-04 at 13:22 -0500, Mark Pearson wrote:
> On Fri, Dec 4, 2026, at 12:49 PM, Rong Zhang wrote:
> > Hi Mark,
> >
> > On Fri, 2026-12-04 at 09:42 -0500, Mark Pearson wrote:
> > > On Fri, Dec 4, 2026, at 8:19 AM, Rong Zhang wrote:
> > > > Hi Mark,
> > > >
> > > > Thanks for working on this.
> > > >
> > > > On Thu, 2026-12-03 at 21:20 -0500, Mark Pearson wrote:
> > > > > This series introduces support for a new Lenovo 'common WMI'
> > > > > implementation.
> > > > >
> > > > > The Thinkpad, Thinkstation and ThinkCenter FW teams have implemented new
> > > > > WMI methods for interfacing with the BIOS settings. This implementation
> > > > > will be available for 2027 platforms and is intended to be common across
> > > > > the business units.
> > > > >
> > > > > The new driver is called tlmi and can run alongside the existing
> > > > > think-lmi driver. Initially the BIOS's will support both interfaces.
> > > > >
> > > > > The first 5 patches in the series update the existing think-lmi driver
> > > > > with changes that means it can share structures with the new tlmi
> > > > > driver. They also introduce fixes for issues I found when implementing
> > > > > tlmi.
> > > > > The remaining patches introduce the new tlmi functionality. I've tried
> > > > > to break them up into reviewable chunks.
> > > > >
> > > > > The tlmi driver for now offers the same functionality as think-lmi -
> > > > > with support for modifying BIOS settings and authentication options.
> > > > > It also introduces 'platform' settings and 'function' settings.
> > > > >
> > > > > During implementation I needed some functionality to be common between
> > > > > modules. Using the wmi-helpers module seemed a good place for this, but
> > > > > please let me know if it's not suitable.
> > > > >
> > > > > Testing has been done on the X1 Carbon G14, ThinkCenter X Tower and
> > > > > Thinkstation P5 G2.
> > > > >
> > > > > Much of this implementation builds on the recommendations from Armin,
> > > > > Derek and Ilpo from the original RFC. Many thanks for the guidance.
> > > > >
> > > > > Mark Pearson (13):
> > > > > platform/x86: lenovo: think-lmi: Convert name arrays to pointers
> > > > > platform/x86: lenovo: think-lmi: Clean up attributes if not added to
> > > > > list
> > > > > platform/x86: lenovo: think-lmi: cache current value at init
> > > > > platform/x86: lenovo: think-lmi: store attributes as linked list
> > > > > platform/x86: lenovo: tlmi: New tlmi driver for common WMI
> > > > > implementation
> > > > > platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries
> > > > > platform/x86: lenovo: tlmi: Retrieve auth information
> > > > > platform/x86: lenovo: Move TLMI helper functions into wmi-helpers
> > > > > platform/x86: lenovo: tlmi: Add authentication sysfs entries
> > > > > platform/x86: lenovo: tlmi: Add platform attribute support
> > > > > platform/x86: lenovo: tlmi: Add function attributes support
> > > > > platform/x86: lenovo: tlmi: Add method identifier
> > > > > docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections
> > > >
> > > > Sashiko found quite a lot of issues in the series, so I am not going to
> > > > seriously review this series yet, in case you'd need to change the design
> > > > a lot in the next revision.
> > > >
> > >
> > > Yeah....that's going to keep me busy. They didn't show up in my inbox so I had to go looking for them.
> > >
> > > I'd been running sashiko with a few tokens I managed to get through work and thought I had it at the stage where it was pretty clean (and I'd run out of tokens). Looks like some new things which is interesting.
> >
> > I've been doing so, too. I always make stupid mistakes so my Sashiko
> > instance helps me get rid most of them before submitting.
> >
> > My suggestion is to keep Sashiko up to date and choose an appropriate
> > model. What model did you use?
> >
> > If you are using DeepSeek V4.1 Flash 1017, do not set effort to max.
> > Sashiko's prompts make it prone to overthink, and such overthink has a
> > potential to cause it to focus on minor issues rather than critical ones,
> > as well as making it very expensive :-/
> >
> > If you are using a /chat/completions endpoint, please set
> > send_reasoning_content = true, or else the model will lose its mind
> > (literally, i.e., losing its chain of thought).
> >
> > Note that some providers' /chat/completions endpoints return CoT in
> > another field called "reasoning", which is unsupported by
> > send_reasoning_content. In this case consider switching to api =
> > "responses".
> >
> I haven't spent a lot time playing with it - I have been using it via copilot-cli (how Lenovo gives us a few tokens a month) and there I've been using claude-sonnet-4.5.
AFAIK the model is quite outdated.
Also, Sashiko's CLI providers generally perform poorly, as models can't
use their special tokens for tool calls (i.e., how they were trained to
call tools), but have to read/generate JSONs for tool call from/to the
input/output (i.e., how they were trained to chat with humans). I believe
that's why you Sashiko instance didn't work well.
I'd suggest using an API provider of Sashiko for much better quality.
>
> Overall it's been quite helpful for ironing out a lot of things I've missed or done wrong. My main issue is that I don't get a lot of tokens a month so I don't iterate much. I can burn thru all my allocation reviewing this 13 patch series (someone else can do the maths...but yeah, it's not a lot). Maybe I should pay for some myself but I've not gotten to that stage yet.
>
> I haven't really gone and tried any other models. On my todo list is to see what I can do locally (I'm fortunate enough to have access to some really quite nice HW....perks of the job) - but just haven't got to it. Maybe over the holidays, but realistically more likely next year.
I used to run Qwen3.8-Flash-Next locally to service my Sashiko instance
and it exceeded my expectations except for the speed (my HW isn't that
powerful after all). There should be better open-weight models available
since then.
>
> I'm totally OK if any reviewers ignore my patch series until I've dealt with Sashiko too, FWIW.
>
> Thanks for the tips. I did read the Sashiko guide (and a few blogs) but it's quite tricky to figure out what is effective whilst not expensive etc.
>
Based on my experience, Sashiko doesn't need a super powerful model. A
less powerful but more efficient model is enough to find out outstanding
issues. After all, Sashiko is not a coding agent and does not require
superior coding skills.
After fixing the outstanding issues (it turns out I always make such
mistakes, lol) found by my local instance I will happily submit my
patches and leave undiscovered subtle issues to sashiko.dev.
> I'm not the biggest AI enthusiast (I lean slightly the other way) - but I do recognise how it helps me write better code
Me neither. Most patches of mine were written by myself, as hacking the
kernel is very joyful to me, while sharing the joy with a coding agent
makes me less happy.
I tried agentic coding several times but coding agents usually couldn't
figure out a better design than mine. My workflow is to (re)design while
programming until I find a satisfying design (at which point the coding
work is also almost done), but LLMs prefer to design things first (with a
bad taste) and trap themselves into their faulty design!
I had a happy chat time :-),
Rong
>
> Mark
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
2026-12-04 13:41 ` Rong Zhang
@ 2026-12-05 9:54 ` kernel test robot
2026-12-05 9:55 ` kernel test robot
2 siblings, 0 replies; 44+ messages in thread
From: kernel test robot @ 2026-12-05 9:54 UTC (permalink / raw)
To: Mark Pearson
Cc: llvm, oe-kbuild-all, derekjohn.clark, i, hansg, ilpo.jarvinen,
platform-driver-x86, linux-kernel
Hi Mark,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.4-rc5 next-20261203]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mark-Pearson/platform-x86-lenovo-think-lmi-Convert-name-arrays-to-pointers/20261203-212010
base: linus/master
patch link: https://lore.kernel.org/r/20261204022032.3074618-6-mpearson-lenovo%40squebb.ca
patch subject: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
config: i386-randconfig-1006-20261204 (https://download.01.org/0day-ci/archive/20261204/20261204204204.q82KETVp-lkp@intel.com/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261204/20261204204204.q82KETVp-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261204204204.q82KETVp-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/platform/x86/lenovo/tlmi-config.c:73:66: error: call to undeclared function 'MKDEV'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
73 | td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
| ^
1 error generated.
vim +/MKDEV +73 drivers/platform/x86/lenovo/tlmi-config.c
52
53 static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
54 {
55 struct component_match *match = NULL;
56 guid_t tlmi_attr_guid;
57 struct think_lmi *td;
58 int ret;
59
60 guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
61
62 /* At minimum need to support BIOS settings */
63 if (!wmidev_exists(&tlmi_attr_guid))
64 return -EOPNOTSUPP;
65
66 td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
67 if (!td)
68 return -ENOMEM;
69
70 td->config_wdev = wdev;
71 dev_set_drvdata(&wdev->dev, td);
72
> 73 td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
74 NULL, "%s", "tlmi");
75 if (IS_ERR(td->class_dev))
76 return PTR_ERR(td->class_dev);
77 dev_set_drvdata(td->class_dev, td);
78
79 /* Register the other components */
80 tlmi_attr_match_add(&wdev->dev, &match);
81
82 ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
83 if (ret)
84 device_unregister(td->class_dev);
85
86 return ret;
87 }
88
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
2026-12-04 13:52 ` Rong Zhang
@ 2026-12-05 9:55 ` kernel test robot
1 sibling, 0 replies; 44+ messages in thread
From: kernel test robot @ 2026-12-05 9:55 UTC (permalink / raw)
To: Mark Pearson
Cc: llvm, oe-kbuild-all, derekjohn.clark, i, hansg, ilpo.jarvinen,
platform-driver-x86, linux-kernel
Hi Mark,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.4-rc5 next-20261203]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mark-Pearson/platform-x86-lenovo-think-lmi-Convert-name-arrays-to-pointers/20261203-212010
base: linus/master
patch link: https://lore.kernel.org/r/20261204022032.3074618-10-mpearson-lenovo%40squebb.ca
patch subject: [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries
config: i386-randconfig-1006-20261204 (https://download.01.org/0day-ci/archive/20261205/20261205003244.J2YIJH3E-lkp@intel.com/config)
compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261205/20261205003244.J2YIJH3E-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261205003244.J2YIJH3E-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/platform/x86/lenovo/tlmi-auth.c:144:7: error: call to undeclared function 'capable'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
144 | if (!capable(CAP_SYS_ADMIN))
| ^
>> drivers/platform/x86/lenovo/tlmi-auth.c:144:15: error: use of undeclared identifier 'CAP_SYS_ADMIN'
144 | if (!capable(CAP_SYS_ADMIN))
| ^~~~~~~~~~~~~
drivers/platform/x86/lenovo/tlmi-auth.c:409:7: error: call to undeclared function 'capable'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
409 | if (!capable(CAP_SYS_ADMIN))
| ^
drivers/platform/x86/lenovo/tlmi-auth.c:409:15: error: use of undeclared identifier 'CAP_SYS_ADMIN'
409 | if (!capable(CAP_SYS_ADMIN))
| ^~~~~~~~~~~~~
drivers/platform/x86/lenovo/tlmi-auth.c:476:7: error: call to undeclared function 'capable'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
476 | if (!capable(CAP_SYS_ADMIN))
| ^
drivers/platform/x86/lenovo/tlmi-auth.c:476:15: error: use of undeclared identifier 'CAP_SYS_ADMIN'
476 | if (!capable(CAP_SYS_ADMIN))
| ^~~~~~~~~~~~~
drivers/platform/x86/lenovo/tlmi-auth.c:585:7: error: call to undeclared function 'capable'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
585 | if (!capable(CAP_SYS_ADMIN))
| ^
drivers/platform/x86/lenovo/tlmi-auth.c:585:15: error: use of undeclared identifier 'CAP_SYS_ADMIN'
585 | if (!capable(CAP_SYS_ADMIN))
| ^~~~~~~~~~~~~
drivers/platform/x86/lenovo/tlmi-auth.c:612:7: error: call to undeclared function 'capable'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
612 | if (!capable(CAP_SYS_ADMIN))
| ^
drivers/platform/x86/lenovo/tlmi-auth.c:612:15: error: use of undeclared identifier 'CAP_SYS_ADMIN'
612 | if (!capable(CAP_SYS_ADMIN))
| ^~~~~~~~~~~~~
10 errors generated.
vim +/capable +144 drivers/platform/x86/lenovo/tlmi-auth.c
130
131 static ssize_t new_password_store(struct kobject *kobj,
132 struct kobj_attribute *attr,
133 const char *buf, size_t count)
134 {
135 struct tlmi_pwd_setting *setting = to_tlmi_pwd_setting(kobj);
136 struct think_lmi *td = dev_get_drvdata(&setting->wdev->dev);
137 enum pwd_type_v2 pwd_type;
138 size_t pwdlen, cur_pwdlen;
139 struct wmi_buffer wmibuf;
140 char *start;
141 int ix = 0;
142 int ret;
143
> 144 if (!capable(CAP_SYS_ADMIN))
145 return -EPERM;
146
147 guard(mutex)(&td->tlmi_auth_lock);
148
149 /* Authorisation needs to be done first */
150 ret = tlmi_auth_authenticate_user(td);
151 /* Ignore most errors. We might be in deployment mode */
152 if (ret == -ENOMEM)
153 return ret;
154
155 /* Strip out CR if one is present, setting password won't work if it is present */
156 char *new_pwd __free(kfree_sensitive) = kstrdup_and_replace(buf, '\n', '\0', GFP_KERNEL);
157 if (!new_pwd)
158 return -ENOMEM;
159
160 pwdlen = strlen(new_pwd);
161 /* pwdlen == 0 is allowed to clear the password */
162 if (pwdlen && (pwdlen < setting->minlen || pwdlen > setting->maxlen))
163 return -EINVAL;
164
165 cur_pwdlen = struct_size_t(struct wmi_string, chars, strlen(setting->password) + 1);
166 pwdlen = struct_size_t(struct wmi_string, chars, strlen(new_pwd) + 1);
167 wmibuf.length = 2 + cur_pwdlen + pwdlen;
168 char *wmidata __free(kfree_sensitive) = kzalloc(wmibuf.length, GFP_KERNEL);
169 if (!wmidata)
170 return -ENOMEM;
171 wmibuf.data = wmidata;
172
173 if (setting == td->pwd_admin) {
174 pwd_type = SVP;
175 } else if (setting == td->pwd_power) {
176 pwd_type = POP;
177 } else if (setting == td->pwd_system) {
178 pwd_type = SMP;
179 } else if (setting == td->pwd_hdd) {
180 if (setting->level == TLMI_LEVEL_MASTER)
181 pwd_type = MASTERHDD;
182 else
183 pwd_type = HDD;
184 pwd_type += setting->index - 1;
185 } else if (setting == td->pwd_nvme) {
186 if (setting->level == TLMI_LEVEL_MASTER)
187 pwd_type = MASTERNVME;
188 else
189 pwd_type = NVME;
190 pwd_type += setting->index - 1;
191 } else {
192 return -EOPNOTSUPP;
193 }
194
195 start = wmibuf.data;
196 start[0] = pwd_type;
197 start += 2;
198
199 ix = tlmi_populate_string_buffer(start, cur_pwdlen, setting->password);
200 if (ix < 0)
201 return ix;
202 start += ix;
203 ix = tlmi_populate_string_buffer(start, pwdlen, new_pwd);
204 if (ix < 0)
205 return ix;
206
207 ret = tlmi_request(td->auth_wdev, 0, SET_PASSWORD, &wmibuf);
208 return ret ?: count;
209 }
210
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
2026-12-04 13:41 ` Rong Zhang
2026-12-05 9:54 ` kernel test robot
@ 2026-12-05 9:55 ` kernel test robot
2 siblings, 0 replies; 44+ messages in thread
From: kernel test robot @ 2026-12-05 9:55 UTC (permalink / raw)
To: Mark Pearson
Cc: oe-kbuild-all, derekjohn.clark, i, hansg, ilpo.jarvinen,
platform-driver-x86, linux-kernel
Hi Mark,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.4-rc5 next-20261203]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mark-Pearson/platform-x86-lenovo-think-lmi-Convert-name-arrays-to-pointers/20261203-212010
base: linus/master
patch link: https://lore.kernel.org/r/20261204022032.3074618-6-mpearson-lenovo%40squebb.ca
patch subject: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261205/20261205012559.FBN3JiSI-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261205/20261205012559.FBN3JiSI-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261205012559.FBN3JiSI-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/platform/x86/lenovo/tlmi-config.c: In function 'tlmi_config_probe':
>> drivers/platform/x86/lenovo/tlmi-config.c:73:73: error: implicit declaration of function 'MKDEV' [-Wimplicit-function-declaration]
73 | td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
| ^~~~~
vim +/MKDEV +73 drivers/platform/x86/lenovo/tlmi-config.c
52
53 static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
54 {
55 struct component_match *match = NULL;
56 guid_t tlmi_attr_guid;
57 struct think_lmi *td;
58 int ret;
59
60 guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
61
62 /* At minimum need to support BIOS settings */
63 if (!wmidev_exists(&tlmi_attr_guid))
64 return -EOPNOTSUPP;
65
66 td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
67 if (!td)
68 return -ENOMEM;
69
70 td->config_wdev = wdev;
71 dev_set_drvdata(&wdev->dev, td);
72
> 73 td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
74 NULL, "%s", "tlmi");
75 if (IS_ERR(td->class_dev))
76 return PTR_ERR(td->class_dev);
77 dev_set_drvdata(td->class_dev, td);
78
79 /* Register the other components */
80 tlmi_attr_match_add(&wdev->dev, &match);
81
82 ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
83 if (ret)
84 device_unregister(td->class_dev);
85
86 return ret;
87 }
88
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 44+ messages in thread
* Re: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
@ 2026-12-05 9:55 kernel test robot
0 siblings, 0 replies; 44+ messages in thread
From: kernel test robot @ 2026-12-05 9:55 UTC (permalink / raw)
To: oe-kbuild; +Cc: lkp
::::::
:::::: Manual check reason: "too many reports for this commit"
::::::
BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261204022032.3074618-6-mpearson-lenovo@squebb.ca>
References: <20261204022032.3074618-6-mpearson-lenovo@squebb.ca>
TO: Mark Pearson <mpearson-lenovo@squebb.ca>
TO: mpearson-lenovo@squebb.ca
CC: derekjohn.clark@gmail.com
CC: i@rong.moe
CC: hansg@kernel.org
CC: ilpo.jarvinen@linux.intel.com
CC: platform-driver-x86@vger.kernel.org
CC: linux-kernel@vger.kernel.org
Hi Mark,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.4-rc5 next-20261203]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mark-Pearson/platform-x86-lenovo-think-lmi-Convert-name-arrays-to-pointers/20261203-212010
base: linus/master
patch link: https://lore.kernel.org/r/20261204022032.3074618-6-mpearson-lenovo%40squebb.ca
patch subject: [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation
:::::: branch date: 13 hours ago
:::::: commit date: 13 hours ago
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261205/20261205013343.OMNtwiK9-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261205/20261205013343.OMNtwiK9-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/20261205013343.OMNtwiK9-lkp@intel.com/
All errors (new ones prefixed by >>):
drivers/platform/x86/lenovo/tlmi-config.c: In function 'tlmi_config_probe':
>> drivers/platform/x86/lenovo/tlmi-config.c:73:73: error: implicit declaration of function 'MKDEV' [-Wimplicit-function-declaration]
73 | td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
| ^~~~~
vim +/MKDEV +73 drivers/platform/x86/lenovo/tlmi-config.c
25b27328a38db62 Mark Pearson 2026-12-03 52
25b27328a38db62 Mark Pearson 2026-12-03 53 static int tlmi_config_probe(struct wmi_device *wdev, const void *context)
25b27328a38db62 Mark Pearson 2026-12-03 54 {
25b27328a38db62 Mark Pearson 2026-12-03 55 struct component_match *match = NULL;
25b27328a38db62 Mark Pearson 2026-12-03 56 guid_t tlmi_attr_guid;
25b27328a38db62 Mark Pearson 2026-12-03 57 struct think_lmi *td;
25b27328a38db62 Mark Pearson 2026-12-03 58 int ret;
25b27328a38db62 Mark Pearson 2026-12-03 59
25b27328a38db62 Mark Pearson 2026-12-03 60 guid_parse(TLMI_ATTRIBUTE_GUID, &tlmi_attr_guid);
25b27328a38db62 Mark Pearson 2026-12-03 61
25b27328a38db62 Mark Pearson 2026-12-03 62 /* At minimum need to support BIOS settings */
25b27328a38db62 Mark Pearson 2026-12-03 63 if (!wmidev_exists(&tlmi_attr_guid))
25b27328a38db62 Mark Pearson 2026-12-03 64 return -EOPNOTSUPP;
25b27328a38db62 Mark Pearson 2026-12-03 65
25b27328a38db62 Mark Pearson 2026-12-03 66 td = devm_kzalloc(&wdev->dev, sizeof(struct think_lmi), GFP_KERNEL);
25b27328a38db62 Mark Pearson 2026-12-03 67 if (!td)
25b27328a38db62 Mark Pearson 2026-12-03 68 return -ENOMEM;
25b27328a38db62 Mark Pearson 2026-12-03 69
25b27328a38db62 Mark Pearson 2026-12-03 70 td->config_wdev = wdev;
25b27328a38db62 Mark Pearson 2026-12-03 71 dev_set_drvdata(&wdev->dev, td);
25b27328a38db62 Mark Pearson 2026-12-03 72
25b27328a38db62 Mark Pearson 2026-12-03 @73 td->class_dev = device_create(&firmware_attributes_class, NULL, MKDEV(0, 0),
25b27328a38db62 Mark Pearson 2026-12-03 74 NULL, "%s", "tlmi");
25b27328a38db62 Mark Pearson 2026-12-03 75 if (IS_ERR(td->class_dev))
25b27328a38db62 Mark Pearson 2026-12-03 76 return PTR_ERR(td->class_dev);
25b27328a38db62 Mark Pearson 2026-12-03 77 dev_set_drvdata(td->class_dev, td);
25b27328a38db62 Mark Pearson 2026-12-03 78
25b27328a38db62 Mark Pearson 2026-12-03 79 /* Register the other components */
25b27328a38db62 Mark Pearson 2026-12-03 80 tlmi_attr_match_add(&wdev->dev, &match);
25b27328a38db62 Mark Pearson 2026-12-03 81
25b27328a38db62 Mark Pearson 2026-12-03 82 ret = component_master_add_with_match(&wdev->dev, &aggregate_ops, match);
25b27328a38db62 Mark Pearson 2026-12-03 83 if (ret)
25b27328a38db62 Mark Pearson 2026-12-03 84 device_unregister(td->class_dev);
25b27328a38db62 Mark Pearson 2026-12-03 85
25b27328a38db62 Mark Pearson 2026-12-03 86 return ret;
25b27328a38db62 Mark Pearson 2026-12-03 87 }
25b27328a38db62 Mark Pearson 2026-12-03 88
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 44+ messages in thread
end of thread, other threads:[~2026-12-05 9:56 UTC | newest]
Thread overview: 44+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 2:20 [PATCH 00/13] New Lenovo common WMI driver - tlmi Mark Pearson
2026-12-04 2:20 ` [PATCH 01/13] platform/x86: lenovo: think-lmi: Convert name arrays to pointers Mark Pearson
2026-12-04 2:20 ` [PATCH 02/13] platform/x86: lenovo: think-lmi: Clean up attributes if not added to list Mark Pearson
2026-12-04 13:20 ` Rong Zhang
2026-12-04 15:09 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init Mark Pearson
2026-12-04 13:28 ` Rong Zhang
2026-12-04 15:14 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 04/13] platform/x86: lenovo: think-lmi: store attributes as linked list Mark Pearson
2026-12-04 13:30 ` Rong Zhang
2026-12-04 15:21 ` Mark Pearson
2026-12-04 16:10 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation Mark Pearson
2026-12-04 13:41 ` Rong Zhang
2026-12-04 15:27 ` Mark Pearson
2026-12-05 9:54 ` kernel test robot
2026-12-05 9:55 ` kernel test robot
2026-12-04 2:20 ` [PATCH 06/13] platform/x86: lenovo: tlmi: Add BIOS attributes sysfs entries Mark Pearson
2026-12-04 13:44 ` Rong Zhang
2026-12-04 15:41 ` Mark Pearson
2026-12-04 17:02 ` Rong Zhang
2026-12-04 2:20 ` [PATCH 07/13] platform/x86: lenovo: tlmi: Retrieve auth information Mark Pearson
2026-12-04 13:48 ` Rong Zhang
2026-12-04 15:44 ` Mark Pearson
2026-12-04 17:14 ` Rong Zhang
2026-12-04 17:26 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 08/13] platform/x86: lenovo: Move TLMI helper functions into wmi-helpers Mark Pearson
2026-12-04 13:49 ` Rong Zhang
2026-12-04 15:50 ` Mark Pearson
2026-12-04 17:19 ` Rong Zhang
2026-12-04 17:27 ` Mark Pearson
2026-12-04 2:20 ` [PATCH 09/13] platform/x86: lenovo: tlmi: Add authentication sysfs entries Mark Pearson
2026-12-04 13:52 ` Rong Zhang
2026-12-05 9:55 ` kernel test robot
2026-12-04 2:20 ` [PATCH 10/13] platform/x86: lenovo: tlmi: Add platform attribute support Mark Pearson
2026-12-04 2:20 ` [PATCH 11/13] platform/x86: lenovo: tlmi: Add function attributes support Mark Pearson
2026-12-04 2:20 ` [PATCH 12/13] platform/x86: lenovo: tlmi: Add method identifier Mark Pearson
2026-12-04 2:20 ` [PATCH 13/13] docs: ABI: sysfs-class-firmware-attributes: Update Lenovo sections Mark Pearson
2026-12-04 13:19 ` [PATCH 00/13] New Lenovo common WMI driver - tlmi Rong Zhang
2026-12-04 14:42 ` Mark Pearson
2026-12-04 17:49 ` Rong Zhang
2026-12-04 18:22 ` Mark Pearson
2026-12-04 20:04 ` Rong Zhang
-- strict thread matches above, loose matches on Subject: below --
2026-12-05 9:55 [PATCH 05/13] platform/x86: lenovo: tlmi: New tlmi driver for common WMI implementation kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.