Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2851141ybk; Mon, 18 May 2020 09:25:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygR98adnCsqLKo5NjN2AhfY1YYWSdiJHzOWQ4omTUnh9NKKtMqDIWosGl2wTsAdLxDMhlJ X-Received: by 2002:a05:6402:8c1:: with SMTP id d1mr13918820edz.265.1589819119230; Mon, 18 May 2020 09:25:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589819119; cv=none; d=google.com; s=arc-20160816; b=Tc39PSySDVDew/5xuY2+gRjP6iF2VUHURjUOjJGyKOWAQzjB/1+sHJvX1QEkPTxezw sVfHlB1QNNSGytHrKLG7bWRsmGG2turlALv7RIBijotdQOV8nXbmSNNlgU4nW3buPbhm lxDnZSrPJ1pAvpFOSC4cnieAX15oH5aQUqHK+Ecl1LHoWaLrgIC4HL3Zeq6VtGkzkePa sKhfBBwaSL4oGfHcKIbpEsDiCBPpnRVa6vxFSZ95evft3hedLJaKRkxq8Bctw1pPHaBt ALtXgRN92cFq2cpOVp/XFeh9xAPnldb+KhdTu0usmZ+GRiM//nUGqlmX05RrPFq4WpBO 2JaQ== 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:references:cc:to:from:subject:ironport-sdr:ironport-sdr; bh=ekzokN7JGEAM/Gcfef3cZHEhOzhVeIU5DuU2dbq1YS8=; b=e4ahWSUpKgQPUDSRWgBuaxoctVWAq+WDboTRBwEiYEcFwtlBYMvZXGeKz2i8etXB2N MbRvIoYaF68xIoT1ER80Mx8YXuStX0VKYf5bE2HjGgNewMJJtjgoSbu4PsPED90w0f/R K1uE8GnTzMTtDDsny8WPapPcdlEl1iQMNvd4AhEjuWqaj2R/gVsaMq9ilVjVz2dRpR6E bbXCSq0u4Mw2xVVVqGeU+1mFZZi0Kd94cJr7xnvwa4NvaUTPjOHEIOtWKPGO3GOKcyLr KSIWMB0RRE5ZZPWfXTQOz9UAgUkPxPeGITA9VOHi12/ljUj7nXOYEwQLYeJLzzTHdBEX DCig== 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 w5si6987460ejq.420.2020.05.18.09.24.55; Mon, 18 May 2020 09:25:19 -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 S1728231AbgERQXL (ORCPT + 99 others); Mon, 18 May 2020 12:23:11 -0400 Received: from mga14.intel.com ([192.55.52.115]:47722 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728142AbgERQXK (ORCPT ); Mon, 18 May 2020 12:23:10 -0400 IronPort-SDR: Z7W4YlQBFFE4DI79XummCPSBFDz25o8YBcas1kV5zYVG5gJqRe3eTfslXAkLqs/M/TIMKFaWgl BjW3KQPrXMdw== 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:23:10 -0700 IronPort-SDR: NcCLSKibfjL3S9MPhvc0m+BrCJaY87EWQf6pTcv0us8UHxzBDVV07HGxGFSr9VFjl9XSlhyoyP YDHnGXXjQOGg== X-IronPort-AV: E=Sophos;i="5.73,407,1583222400"; d="scan'208";a="465635598" 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:23:09 -0700 Subject: Re: [PATCH V4 4/4] x86/resctrl: Use appropriate API for strings terminated by newline From: Reinette Chatre 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> <060e3cf6-8fcb-6b43-01ef-63ef0a5ff64a@intel.com> Message-ID: <962118f4-3b02-2d6c-fd4d-2540d1a03e89@intel.com> Date: Mon, 18 May 2020 09:23:08 -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: <060e3cf6-8fcb-6b43-01ef-63ef0a5ff64a@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 9:06 AM, Reinette Chatre wrote: > 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. Actually ... now that I take a closer look, this would let an invalid mode change (RDT_MODE_PSEUDO_LOCKED) slip through so I plan to keep this code as is. > 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. I will still do this. Reinette