From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Hans de Goede" <hdegoede@redhat.com>
Cc: "markgross@kernel.org" <markgross@kernel.org>,
"platform-driver-x86@vger.kernel.org"
<platform-driver-x86@vger.kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] platform/x86: think-lmi: Add bulk save feature
Date: Tue, 05 Sep 2023 07:24:33 -0400 [thread overview]
Message-ID: <8ca1d0f1-4064-4804-aa0a-d8633e0e6361@app.fastmail.com> (raw)
In-Reply-To: <59d1b822-e8e1-9373-1942-0f376abb02b8@redhat.com>
Thanks Hans,
On Tue, Sep 5, 2023, at 7:17 AM, Hans de Goede wrote:
> Hi Mark,
>
> On 8/29/23 15:15, Mark Pearson wrote:
<snip>
>> +
>> + /* Check if user is trying to change the save mode */
>> + if (!strncmp(buf, "bulk", 4) || !strncmp(buf, "single", 6)) {
>> + tlmi_priv.save_mode = strncmp(buf, "bulk", 4) ? TLMI_SAVE_SINGLE : TLMI_SAVE_BULK;
>> + return count;
>> + }
>> + if (strncmp(buf, "save", 4))
>> + return -EINVAL;
>
> Things look good up to this point, but I'm not happy
> with the string parsing here. Using strncmp to avoid
> a possible '\n' means that writing
> "bulk extra special with onions" will also match "bulk".
>
> Instead I suggest the following (better names
> for the enum are welcome):
>
> enum { save_single, save_bulk, save_save };
>
> const char * const save_strings[] = {
> [save_single] = "single",
> [save_bulk] = "bulk",
> [save_save] = "save",
> };
>
> int ret = 0;
> int cmd;
>
> cmd = sysfs_match_string(save_strings, buf);
> if (cmd < 0)
> return cmd;
>
> mutex_lock(&tlmi_mutex);
>
> switch (cmd) {
> case save_single:
> tlmi_priv.save_mode = TLMI_SAVE_SINGLE;
> goto out;
> case save_bulk:
> tlmi_priv.save_mode = TLMI_SAVE_BULK;
> goto out;
> case save_save:
> break; /* Continue with saving settings */
> }
>
> /* The user is triggering a save - if supported */
> if (!tlmi_priv.can_set_bios_settings ||
> tlmi_priv.save_mode == TLMI_SAVE_SINGLE)
> return -EOPNOTSUPP;
>
> ...
>
> This lets sysfs_match_string() do the string parsing work
> for us, getting rid of having to do this ourselves.
>
Agreed - this is much better. Thanks for the suggestion and I'll make the change.
> Notice I have also moved the mutex_lock() up, so that
> it is also done for updating the save_mode since we
> don't want that the change halfway through a possibly
> racing current_value_store() call.
>
Ack
Mark
prev parent reply other threads:[~2023-09-05 16:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 13:15 Mark Pearson
2023-09-05 11:17 ` Hans de Goede
2023-09-05 11:24 ` Mark Pearson [this message]
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=8ca1d0f1-4064-4804-aa0a-d8633e0e6361@app.fastmail.com \
--to=mpearson-lenovo@squebb.ca \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markgross@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®