Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2840863ybk; Mon, 18 May 2020 09:10:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2AA297hbt5kY1KXHdGkaEiQ+xqLlmxLjgmw1Y6jYf/C9Tu1M258h9HXSOazio378xm2t2 X-Received: by 2002:a17:906:3e96:: with SMTP id a22mr16112999ejj.232.1589818217061; Mon, 18 May 2020 09:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589818217; cv=none; d=google.com; s=arc-20160816; b=a/9/9NBmMhFIFcGxSYeVm9rXxDfVOR+4r6Qvie9dfU3AKCfS6RalK0BRVD/74RxUWA dWzFSpvjqpvkzOxo0qylt6C169S6or53H239ApQzWPlLmsXXEx+m/9ELfeTYoWBdytah ZjlU/m27iZNPEjEhi+zGMAFiwhpDFI5SBjHXhDEaJjhVhwx+Q7KOkDH6bawM8xVcq80v 4+M9o4RAprUyThMz1it+i+ntFiKNTT4lpXySQMvuYtVzRGWhk52XfYR23m2HpgERtiXP Zkhc/p9uZPGR1MTDLA5SXLR/yzGZMOJTKATRTJhJNW9I1Q+l1U8tY6o8pDLvTDtVeVmE tpEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=VUEJCpKiwQmZW4IQ8G9EEp33yx65E5v/H3qDeyVa2wI=; b=m/o6kVgosUW1Y+mG4HKstAm/ppuf4W366KMiw919ndj299UlNloPDkQo0HzV9la8Cl /l4p8krETNJlaZZFtKK2mo7To2ePds3uI7p3U9l6yUhgzV+BquF2WIzMwEV1w4GWmjWG JZXOyOOzjkIIUk911rTjJG84slFWyfE1k7imkK7Aa09xydBJjZ0/ijwJC3wvkv9ajCo9 5EuAHJVnCFft/Sd0ao0gu3DKVD2s3LwMP0rEFVmkmirSJ4ag/A0Uf2fXWDBw78YO0vpu 5TBA1ISJ41yjskyOO70dm8qK8pZoi4cwWbfD0eO9jOxgSkaCEePEK/YBi0qBmzYxRdSg 98+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si6632830edz.401.2020.05.18.09.09.52; Mon, 18 May 2020 09:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728043AbgERQGE (ORCPT + 99 others); Mon, 18 May 2020 12:06:04 -0400 Received: from mga14.intel.com ([192.55.52.115]:45856 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbgERQGE (ORCPT ); Mon, 18 May 2020 12:06:04 -0400 IronPort-SDR: Qmbtw2F8zNZipQY9deifv2fvr/GHaJHWjEfubbHmsOqKnt2S46OAlbwDadhju4oFzabZfRfrcF qcIobJ6jClXg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 09:06:03 -0700 IronPort-SDR: w50aPhiGKgfyEp2ixKa+Ql5GA/p/3PIzAErG1Sfc3HLpOw1HrIe3LRA73fAIsyhI68Ja/TYrXO hjR03SIr9B0A== X-IronPort-AV: E=Sophos;i="5.73,407,1583222400"; d="scan'208";a="465630075" Received: from rchatre-mobl.amr.corp.intel.com (HELO [10.254.66.2]) ([10.254.66.2]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 09:06:02 -0700 Subject: Re: [PATCH V4 4/4] x86/resctrl: Use appropriate API for strings terminated by newline To: Andy Shevchenko Cc: tglx@linutronix.de, fenghua.yu@intel.com, bp@alien8.de, tony.luck@intel.com, kuo-lang.tseng@intel.com, ravi.v.shankar@intel.com, mingo@redhat.com, babu.moger@amd.com, hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org References: <0c04b58148f181ba182b9a487465e4853e4eadbb.1589652468.git.reinette.chatre@intel.com> <20200518115026.GA1634618@smile.fi.intel.com> From: Reinette Chatre Message-ID: <060e3cf6-8fcb-6b43-01ef-63ef0a5ff64a@intel.com> Date: Mon, 18 May 2020 09:06:00 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200518115026.GA1634618@smile.fi.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On 5/18/2020 4:50 AM, Andy Shevchenko wrote: > On Sat, May 16, 2020 at 11:28:41AM -0700, Reinette Chatre 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. > > Sorry for late comment, but just have noticed... No problem. I do appreciate your feedback because it helps me to improve the code. > >> if (mode == RDT_MODE_PSEUDO_LOCKED) { >> @@ -1445,14 +1450,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, >> goto out; >> } >> >> - if (!strcmp(buf, "shareable")) { >> + if (user_m == RDT_MODE_SHAREABLE) { >> if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) { >> ret = rdtgroup_locksetup_exit(rdtgrp); >> if (ret) >> goto out; >> } > >> rdtgrp->mode = RDT_MODE_SHAREABLE; > > ...can we simple move this and similar (in other branches) to... > > >> - } else { >> - rdt_last_cmd_puts("Unknown or unsupported mode\n"); >> - ret = -EINVAL; >> } > > ...here as > > rdtgrp->mode = user_m; Will do. It also looks like the only reason for the "mode" local variable was to make those earlier "strcmp" lines shorter. With those long lines removed in this patch this local variable is no longer needed and I will remove it also. Reinette