Re: [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init
From: Mark Pearson
Date: Fri Dec 04 2026 - 10:14:59 EST
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@xxxxxxxxx>
>> ---
>> 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