Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2655977ybk; Mon, 18 May 2020 04:52:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxLCyl+bOsinFRsodWgVuWaT4KuTi/pAQpf1v54NBo2Jzz95D8dgx/vrpfbczN53zARqio X-Received: by 2002:a17:906:57d6:: with SMTP id u22mr14130509ejr.49.1589802747596; Mon, 18 May 2020 04:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589802747; cv=none; d=google.com; s=arc-20160816; b=WPzvhhX1PXhLOQwcg/AyTiXLEkO8PXNVoC+kjGWnfALR9t5HKOQGr3aBxU72Bj+ipY SsnYnuEcke8mFdV/ZlrYB0NZA6lzObBvvBsBCrUIhJLXBgsh4S5GUIlzgKD3CoR6SBCV cFDjvwCA/Y4GVH7APaR+Tp5QIolA1pk7iGy+wN2dQqItvYtsf0ysDHCJVCqdcPRU5brn NuiJ8Lkmg7/4+9xJy4bm6cp/rlzx7foRRgvLc1sYKJJWz6ltFPD3AU65GjztxrVfR1zS rVhtzg+gBvTplovNXaLFH90yISIgkQXV3fAp2fpB/ijoVPJgGWliFtRxH3/uGBuqkJH2 fsdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=ditsUPxzvDmQcI8XqxWM0aMmcBRx91KtYJ7+bexsBoI=; b=J+CxHheR6KRvHNJY8ldhLhU9OrN6f2Fc0z6JIApl+25ZLDNiL30DquBPm7GZdbOTlS cUD1lxjIGx6428h0xZRl86DvtKSBvQyAfISCEbb1XyVkcVd3IxonguZ7jE7QtOLG0iYI wW91wtATrTXB3TxKeIz+PSLB/HUfqMQN57iOop2CHDmt2zJHx/xknMA0xnsJpTsNVK0D I36+MdEqVE8QXah6vy3TUuFEDhTQ1k1T/EQqs6gktOslmU1v1sT0LevBcmlgAnJ+QTEt uRQQWbcPB0FSJ1cCvoyw4v0b3IP60THnzjWfZoapXg/IHqy20zuqVe1a/63hMldHf3gx ndJw== 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 x13si5643774ede.221.2020.05.18.04.52.04; Mon, 18 May 2020 04:52:27 -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 S1727803AbgERLu1 (ORCPT + 99 others); Mon, 18 May 2020 07:50:27 -0400 Received: from mga18.intel.com ([134.134.136.126]:56847 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726413AbgERLu1 (ORCPT ); Mon, 18 May 2020 07:50:27 -0400 IronPort-SDR: Vh9h9idzE6eWoqdabY/KOynM68kUAfda29wy/x6E6MXvWy8uHBcTMWPDsQGpOMH+XTt6/u/aU4 oUVlafE2ofPQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2020 04:50:27 -0700 IronPort-SDR: Q8YgNhXeK5Zw+scoukr6PZp9MnDceel08RkPENGwlOzSx0S9bP8VGxY59TeeSjva+G2QzLh5e5 wcKz5ClPSA5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,407,1583222400"; d="scan'208";a="281945665" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga002.jf.intel.com with ESMTP; 18 May 2020 04:50:24 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jaeHq-007PoR-Tp; Mon, 18 May 2020 14:50:26 +0300 Date: Mon, 18 May 2020 14:50:26 +0300 From: Andy Shevchenko To: Reinette Chatre 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 Subject: Re: [PATCH V4 4/4] x86/resctrl: Use appropriate API for strings terminated by newline Message-ID: <20200518115026.GA1634618@smile.fi.intel.com> References: <0c04b58148f181ba182b9a487465e4853e4eadbb.1589652468.git.reinette.chatre@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c04b58148f181ba182b9a487465e4853e4eadbb.1589652468.git.reinette.chatre@intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... > 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; ? > out: Note, I didn't check all branches carefully. -- With Best Regards, Andy Shevchenko