From: Rong Zhang <i@rong.moe>
To: Mark Pearson <mpearson-lenovo@squebb.ca>
Cc: derekjohn.clark@gmail.com, hansg@kernel.org,
ilpo.jarvinen@linux.intel.com,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 03/13] platform/x86: lenovo: think-lmi: cache current value at init
Date: Fri, 04 Dec 2026 21:28:20 +0800 [thread overview]
Message-ID: <e72ebb9d2acdc44a63249ad2588a097d69cf69c2.camel@rong.moe> (raw)
In-Reply-To: <20261204022032.3074618-4-mpearson-lenovo@squebb.ca>
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 {
next prev parent reply other threads:[~2026-12-04 13:33 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e72ebb9d2acdc44a63249ad2588a097d69cf69c2.camel@rong.moe \
--to=i@rong.moe \
--cc=derekjohn.clark@gmail.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®