[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VduowRmxOw4CM0CivTE=W4oSVgj0H2gz1yP931Ki2=2Dw@mail.gmail.com>
Date: Tue, 19 May 2020 11:19:36 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Reinette Chatre <reinette.chatre@...el.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Fenghua Yu <fenghua.yu@...el.com>,
Borislav Petkov <bp@...en8.de>,
Tony Luck <tony.luck@...el.com>, kuo-lang.tseng@...el.com,
ravi.v.shankar@...el.com, Ingo Molnar <mingo@...hat.com>,
Babu Moger <babu.moger@....com>,
"H. Peter Anvin" <hpa@...or.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: Re: [PATCH V5 4/4] x86/resctrl: Use appropriate API for strings
terminated by newline
On Tue, May 19, 2020 at 2:50 AM Reinette Chatre
<reinette.chatre@...el.com> wrote:
>
> The user input to files in the resctrl filesystem are expected to be
> terminated with a newline. Testing the user input includes a test for
> the presence of a newline and then replacing the newline with NUL
> byte followed by comparison using strcmp().
>
> sysfs_streq() exists to test if strings are equal, treating both NUL and
> newline-then-NUL as equivalent string terminations. Even more,
> sysfs_match_string() exists to match a given string in an array using
> sysfs_streq().
>
> Replace existing strcmp() comparisons of strings that are terminated
> with a newline with more appropriate sysfs_streq() via the
> sysfs_match_string() API that can perform the match across the different
> mode strings that are already maintained in an array.
...
> Changes since V4:
> - Remove "mode" local variable from rdtgroup_mode_write(). This variable
> was previously used to create shorter lines with the original strcmp()
> code that was removed in patch 4/4.
> - Andy pointed out that the repeated assignment to rdtgrp->mode could be
> replaced by a single assignment after all the checks. This was initially
> rejected because it would let the "RDT_MODE_PSEUDO_LOCKED" assignment
> slip through. Even so, Andy's feedback revealed that the new changes
> unintentionally let a user's attempt at setting the mode to pseudo-locked
> be silently ignored where it previously reported an error. Restore original
> user space behavior by returning success when user attempts to change any
> mode when it is already the current mode (including pseudo-locked) and
> returning failure when user attempts to set the mode to pseudo-locked.
> After this change it is possible to follow Andy's original suggestion
> of using a single assignment. (Andy)
Glad we can do it!
...
> + ret = sysfs_match_string(rdt_mode_str, buf);
> + if (ret < 0) {
> + rdt_last_cmd_puts("Unknown or unsupported mode\n");
> + ret = -EINVAL;
This is redundant.
> + goto out;
> + }
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists