lkml.org 
[lkml]   [2020]   [Apr]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 2/2] x86/resctrl: Use appropriate API for strings terminated by newline
On Thu, Apr 02, 2020 at 04:06:25PM +0300, Andy Shevchenko wrote:
> On Wed, Apr 01, 2020 at 11:30:48AM -0700, Reinette Chatre wrote:

...

> > int ret = 0;
> > + int user_m;

...and forgot to mention this...

int user_m;
int ret;

> > /* Valid input requires a trailing newline */
> > if (nbytes == 0 || buf[nbytes - 1] != '\n')
> > return -EINVAL;
> > - buf[nbytes - 1] = '\0';
>
> The above test is not needed and comment now is misleading.
> WRT nbytes I believe that kernel fs code checks for that.
>
> > rdtgrp = rdtgroup_kn_lock_live(of->kn);
> > if (!rdtgrp) {
> > @@ -1428,11 +1428,15 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
> >
> > mode = rdtgrp->mode;
> >
> > - if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||
> > - (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
> > - (!strcmp(buf, "pseudo-locksetup") &&
> > - mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
> > - (!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
> > + user_m = sysfs_match_string(rdt_mode_str, buf);
> > + if (user_m < 0) {
> > + rdt_last_cmd_puts("Unknown or unsupported mode\n");
> > + ret = user_m;
> > + goto out;
> > + }
>
> You can do it the way
>
> ret = sysfs_match_string(...);
> if (ret < 0) {
> ...
> }
> user_m = ret;

...and this changes

ret = 0;

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2020-04-02 21:35    [W:0.142 / U:0.452 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site