[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <69c27b14-5943-eab1-407c-209d8d484bc1@linux.intel.com>
Date: Mon, 29 Dec 2025 19:32:26 +0200 (EET)
From: Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>
To: Benjamin Philip <benjamin.philip495@...il.com>
cc: Mark Pearson <mpearson-lenovo@...ebb.ca>,
"platform-driver-x86@...r.kernel.org" <platform-driver-x86@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
"Derek J . Clark" <derekjohn.clark@...il.com>,
Hans de Goede <hansg@...nel.org>
Subject: Re: [PATCH 4/5] platform/x86: think-lmi: fix column limit overflow
On Mon, 29 Dec 2025, Benjamin Philip wrote:
> Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com> writes:
> > On Wed, 24 Dec 2025, Benjamin Philip wrote:
> >> "Mark Pearson" <mpearson-lenovo@...ebb.ca> writes:
> >> > On Tue, Dec 23, 2025, at 2:24 PM, Benjamin Philip wrote:
> >> >> This commit handles some column limit overflows (that occur after fixing
> >> >> their alignment), i.e. the following check:
> >> >>
> >> >> CHECK: line length of ... exceeds 100 columns
> >> >>
> >> >> by defining a constant opt, and replacing the offending
> >> >> expression with opt.
> >> >>
> >> >> Signed-off-by: Benjamin Philip <benjamin.philip495@...il.com>
> >> >> ---
> >> >> drivers/platform/x86/lenovo/think-lmi.c | 31 +++++++++++++++----------
> >> >> 1 file changed, 19 insertions(+), 12 deletions(-)
> >> >>
> >> >> diff --git a/drivers/platform/x86/lenovo/think-lmi.c
> >> >> b/drivers/platform/x86/lenovo/think-lmi.c
> >> >> index 1ada4d800383..07ba0d84720a 100644
> >> >> --- a/drivers/platform/x86/lenovo/think-lmi.c
> >> >> +++ b/drivers/platform/x86/lenovo/think-lmi.c
> >> >> @@ -1083,12 +1083,13 @@ static ssize_t type_show(struct kobject *kobj,
> >> >> struct kobj_attribute *attr,
> >> >> }
> >> >>
> >> >> static ssize_t current_value_store(struct kobject *kobj,
> >> >> - struct kobj_attribute *attr,
> >> >> - const char *buf, size_t count)
> >> >> + struct kobj_attribute *attr, const char *buf,
> >> >> + size_t count)
> >> >> {
> >> >> struct tlmi_attr_setting *setting = to_tlmi_attr_setting(kobj);
> >> >> char *set_str = NULL, *new_setting = NULL;
> >> >> char *auth_str = NULL;
> >> >> + const char *opt;
> >> >> int ret;
> >> >>
> >> >> if (!tlmi_priv.can_set_bios_settings)
> >> >> @@ -1163,10 +1164,11 @@ static ssize_t current_value_store(struct kobject *kobj,
> >> >> ret = tlmi_save_bios_settings("");
> >> >> } else { /* old non-opcode based authentication method (deprecated) */
> >> >> if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0]) {
> >> >> + opt = encoding_options[tlmi_priv.pwd_admin->encoding];
> >> >> auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
> >> >> - tlmi_priv.pwd_admin->password,
> >> >> - encoding_options[tlmi_priv.pwd_admin->encoding],
> >> >> - tlmi_priv.pwd_admin->kbdlang);
> >> >> + tlmi_priv.pwd_admin->password,
> >> >> + opt,
> >> >> + tlmi_priv.pwd_admin->kbdlang);
> >> >> if (!auth_str) {
> >> >> ret = -ENOMEM;
> >> >> goto out;
> >> >> @@ -1299,6 +1301,7 @@ static ssize_t save_settings_store(struct
> >> >> kobject *kobj, struct kobj_attribute *
> >> >> const char *buf, size_t count)
> >> >> {
> >> >> char *auth_str = NULL;
> >> >> + const char *opt;
> >> >> int ret = 0;
> >> >> int cmd;
> >> >>
> >> >> @@ -1347,9 +1350,10 @@ static ssize_t save_settings_store(struct
> >> >> kobject *kobj, struct kobj_attribute *
> >> >> ret = tlmi_save_bios_settings("");
> >> >> } else { /* old non-opcode based authentication method (deprecated) */
> >> >> if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0]) {
> >> >> + opt = encoding_options[tlmi_priv.pwd_admin->encoding];
> >> >> auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
> >> >> tlmi_priv.pwd_admin->password,
> >> >> - encoding_options[tlmi_priv.pwd_admin->encoding],
> >> >> + opt,
> >> >> tlmi_priv.pwd_admin->kbdlang);
> >> >> if (!auth_str) {
> >> >> ret = -ENOMEM;
> >> >> @@ -1381,11 +1385,13 @@ static ssize_t save_settings_store(struct
> >> >> kobject *kobj, struct kobj_attribute *
> >> >> static struct kobj_attribute save_settings = __ATTR_RW(save_settings);
> >> >>
> >> >> /* ---- Debug
> >> >> interface---------------------------------------------------------
> >> >> */
> >> >> -static ssize_t debug_cmd_store(struct kobject *kobj, struct
> >> >> kobj_attribute *attr,
> >> >> - const char *buf, size_t count)
> >> >> +static ssize_t debug_cmd_store(struct kobject *kobj,
> >> >> + struct kobj_attribute *attr, const char *buf,
> >> >> + size_t count)
> >> >> {
> >> >> char *set_str = NULL, *new_setting = NULL;
> >> >> char *auth_str = NULL;
> >> >> + const char *opt;
> >> >> int ret;
> >> >>
> >> >> if (!tlmi_priv.can_debug_cmd)
> >> >> @@ -1397,10 +1403,11 @@ static ssize_t debug_cmd_store(struct kobject
> >> >> *kobj, struct kobj_attribute *attr
> >> >> return -ENOMEM;
> >> >>
> >> >> if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0]) {
> >> >> + opt = encoding_options[tlmi_priv.pwd_admin->encoding];
> >> >> auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;",
> >> >> - tlmi_priv.pwd_admin->password,
> >> >> - encoding_options[tlmi_priv.pwd_admin->encoding],
> >> >> - tlmi_priv.pwd_admin->kbdlang);
> >> >> + tlmi_priv.pwd_admin->password,
> >> >> + opt,
> >> >> + tlmi_priv.pwd_admin->kbdlang);
> >> >> if (!auth_str) {
> >> >> ret = -ENOMEM;
> >> >> goto out;
> >> >> @@ -1775,7 +1782,7 @@ static int tlmi_analyze(struct wmi_device *wdev)
> >> >> ffs(tlmi_priv.pwdcfg.ext.hdd_user_password) - 1;
> >> >> }
> >> >> if (tlmi_priv.pwdcfg.ext.nvme_user_password ||
> >> >> - tlmi_priv.pwdcfg.ext.nvme_master_password) {
> >> >> + tlmi_priv.pwdcfg.ext.nvme_master_password) {
> >> >> tlmi_priv.pwd_nvme->pwd_enabled = true;
> >> >> if (tlmi_priv.pwdcfg.ext.nvme_master_password)
> >> >> tlmi_priv.pwd_nvme->index =
> >> >> --
> >> >> 2.52.0
> >> >
> >> > I'll defer to the pdx86 reviewers for this set of changes.
> >> >
> >> > This seems to me to make things more complicated than needed, purely
> >> > to address a 100 column limit. I personally don't like the change.
> >> >
> >> > Nothing wrong with the code, and if more experienced maintainers prefer it, I'm happy to defer to them. Otherwise it seems to me noise for the sake of noise I'm afraid
> >> >
> >> > Mark
> >>
> >> An alternative could be to set this a constant pwd_admin to
> >> tlmi_priv.pwd_admin. There are 13 other references to
> >> tlmi_priv.pwd_admin in one function alone, so maybe it might be a more
> >> meaningful improvement?
> >
> > Hi,
> >
> > The general theme in this driver seems to be that tlmi_priv.pwd_admin
> > usually causes long lines so introducing a local variable for it in such
> > functions would certainly help.
> >
> > This probably came to be when pwd_admin was migrated over into tlmi_priv
> > which certainly was correct place for it, but case with the cost of adding
> > into the line lengths.
> >
>
> In this case, would you prefer that a local variable for pwd_admin be
> introduced instead of variables for values in the long lines?
Mark who's the maintainer seems to be against it, so I don't want to step
too strongly on his lot in this. It's merely my opinion how we normally
handle cases like this (I probably didn't express that clearly enough).
That being said, I think there are very good reasons for the 100 limit
but it also varies how imporant the bit that is very right columnwise is
(and function parameters that don't contain odd logic in them are quite
low on that list, only little above container_of() boilerplate).
> >> Then again, the question arises why we aren't following the same pattern
> >> for all the other heavily used fields under tlmi_priv. Adding more
> >> constants seems to be wrong way forward.
> >
> > Locally it might make sense on case by case basis, to me it looks
> > business as usual to store things into function local vars to control
> > deref line lengths.
> >
> >> Another option would be to move repeated functionality into other
> >> functions (all the column limit violations seem to be identical and
> >> involve encoding_options and kasprintf in the same way), but a refactor
> >> of this nature seemed *way* beyond the scope of a simple code syle clean
> >> up.
> >>
> >> Thus, assigning the required value to a small constant seemed to be the
> >> best immediate solution. I can see why you feel it adds complexity.
> >> Typically in a dynamic language (or even in a declare-as-you-need code
> >> style in C) this is a trivial change, whereas in a top-of-block style
> >> this does seem to add some cruft.
> >>
> >> Perhaps we should drop this patch for now? Nevertheless, I think the
> >> column limit violations, long functions, and repeated lines are a sign
> >> that some refactoring is in order.
> >>
> >> Thoughts?
> >
> > As a general note on these changes, I'm wondering if you're planning on
> > doing these checkpatch cleanups for a large number of drivers beyond those
> > you've already submitted (which you likely won't be able to test for
> > real)?
> >
> > I'm asking this because "fixing" in-tree checkpatch errors/warnings is
> > generally not considered something one should be doing without other work
> > on the particular drivers (which normally implies proper testing beyond
> > compiling). Checkpatch has its uses, but this is not one of them.
> >
> > --
> > i.
>
> As of right now, I planned to send a checkpatch cleanup for
> thinkpad-acpi at something point, but nothing more than that. I
> understand why any fixes imply proper testing. In the case of this
> patchset I can definitely test the changes, since the machine I created
> these patches uses this driver.
>
> I would have thought that checkpatch "fixes" would have some value alone
> (although minimal). I'm guessing you do not encourage coccinelle, sparse
> or kasan "fixes" without prior work as well?
I do run sparse almost daily here and it's warnings are much more valuable
over checkpatch's (excluding the recent addition of "error: bad constant
expression" madness thanks to Kees (IIRC) which I now have to filter away
~forever)!
I'm also under impression that kasan also points out problems which are
not pure stylistics preferences.
However, when we start to remove extra parenthesis because checkpatch has
some rule that doesn't like using parenthesis to group logic, and somebody
has to spend cycles to review those patches, I think we've reached a point
of negative returns. It's surprisingly hard to visually check such patch
for correct nesting, so there's a real risk as well with it.
I'm not entirely convinced by all checkpatch rules to begin with, one
needs to take its output with a grain of salt.
> I'm sorry if these cleanups have been just noise and a misuse of
> checkpatch. My intention with these patches was to get a feel for the
> development process, the code base and the tooling before moving
> towards any "real" contributions.
It's just finding a logic issue has way more value than pure syntax
changes. Perhaps checkpatch doesn't teach much about tools needed for
"real" contributions ;-) (I can see some value in learning to deal with
the patch submission and feedback process though).
And if you really intend to work with these drivers beyond cleanup you're
now submitting to, I certainly find it less disruptive than doing it on a
large-scale to random things.
--
i.
Powered by blists - more mailing lists