mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Rong Zhang" <i@rong.moe>
Cc: "Derek J . Clark" <derekjohn.clark@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"platform-driver-x86@vger.kernel.org"
	<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 10:14:32 -0500	[thread overview]
Message-ID: <838fb650-2eb7-4c51-be0b-6a7148766402@app.fastmail.com> (raw)
In-Reply-To: <e72ebb9d2acdc44a63249ad2588a097d69cf69c2.camel@rong.moe>

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

  reply	other threads:[~2026-12-04 15:14 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
2026-12-04 15:14     ` Mark Pearson [this message]
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=838fb650-2eb7-4c51-be0b-6a7148766402@app.fastmail.com \
    --to=mpearson-lenovo@squebb.ca \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=i@rong.moe \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --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®