Messages in this thread |  | | Date | Thu, 2 Apr 2020 22:35:00 +0300 | From | Andy Shevchenko <> | Subject | Re: [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
|  |