Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3317398ybk; Tue, 19 May 2020 01:21:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWHIzF6v/LMH7c4S/4XuI3r/Z6sK9dIoIgGV6p9leq4WSOCuh4QA+Ao/gL2C14my8Aa8wh X-Received: by 2002:a17:906:935a:: with SMTP id p26mr18576822ejw.103.1589876508479; Tue, 19 May 2020 01:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589876508; cv=none; d=google.com; s=arc-20160816; b=YxVUOHyT4cb5x669cgJOH1nr9Z5A65nbxJbaY8ZCe1H3IUDMhwTLmfWubDzM8Tkwk5 IzlcsYHAb9RdlUh+fw/Fz+oORsNezv7Ss4GigYc65Q71lKMv+HNU/4xWi16bwBEjaj13 /3YDDCTgUxlmVjh6E777+cgjJKEaX2r0TvN6Ihy1qTVGTme/h4PNf293JZY2fs8/azKE tnJI+6/ACBZvKXrdVmzssFIA5nQrMAfyysFzZD8HQHgkvCskK65vt3ZCwByVrX3nYREL zRIpN15w9zpBZndkO9QG2ihqsWfzIGPx/Ltp7QVIybmU324p9D6/QZLAdDsSAX+f3xMW iojg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nMgJTFIHLdVTsEOwo89+14p5As96jTIsFfJ3y0gKgXM=; b=1FvG/LKDSAHuKeUpvQCENVSlYO97BtJC2YBieapjTYNlAaJC7MbwSEOv5rjgeY0GmZ cEj4knCBbXyzgdVr1k4PkFXXYDtpQFNBvpfWRbMamrMDiJyVc33Tn8U/7IK/dL76gQOV lcu+Od72DpsEl7EKnVsO50A/VRLTVfDglyanKroAJ5lGIJQTn2SgSKVHC0rpCTopm9Z5 18M4iRy+2NumhYjT5eX3ooG+vg/47Q997GQnmTAtFrHwWT5GBOFL5sl4JM/+H+zA0AAt d+1sMmz9lIHfr8qX2I/H14qY3Q0kGzX5RVUxWKAVddHt5Upzmi/j6h7BumpZZoUDV3wR BQuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PHtluWYj; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bo6si7236018edb.586.2020.05.19.01.21.25; Tue, 19 May 2020 01:21:48 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PHtluWYj; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726535AbgESITy (ORCPT + 99 others); Tue, 19 May 2020 04:19:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbgESITx (ORCPT ); Tue, 19 May 2020 04:19:53 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7046C061A0C for ; Tue, 19 May 2020 01:19:53 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id b190so6177565pfg.6 for ; Tue, 19 May 2020 01:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nMgJTFIHLdVTsEOwo89+14p5As96jTIsFfJ3y0gKgXM=; b=PHtluWYj7cObY1dboEnE/sM1UD+QChDpcrn5Uy4M4dWGQtnLEQgICKMSBRUWpcjabz RuU3mYh5Db8Prk1n5DVi5+m0yguYYfpLiM8CV5blEvCswdl9KWSvUV41/WhgH3Bu3yWK fSBypWWXvs7fIqTLQjDjm5ayh/Cq06E5PXxsowx5qSWQZqYR0pzsZmsmt7tJqmJe/BVo ww2/c9IStx+jgh0NovzKVvXeI4kMqAd1EAOXfFed3/Y0vNs2UeRKvbN/PtpJcYgcoR6g pDiAsS+vWEdOj9vElWXQ1Py+BGiUzmPpi2j/S0xehyqruNU0BSpGOaY9vNusBTzSbqMz 5bIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nMgJTFIHLdVTsEOwo89+14p5As96jTIsFfJ3y0gKgXM=; b=JhTCzlzzl0Lgcck9xbmSResRRfOHYLHXnUZVEQTuiGh/gHf0Qb/7wusMUJwHtledRw L/vSpca/gFSppVkQL9m+8bACLpJqwyGeH3GIE16IsMnla17XfLtivZijeZHnrAdrjR1F TqSn/dE3IrTtyP3e6M7CMj22GoRDuTCNAeEMZZf+q+6wc/AKLnjcBml4JFx0nNrUlHrX /89EOql/EvJjwgfVqo7qQ3zHczTbhcua+t7bwYRiwjfZMLwBeGLI/Q8IQfquGyG4BJLs vL6liiGFrsoYg/J5nft43PXdM55+Yb0RJZzeneF5W2EYM9sNbLqKJnlhvSuKowy/HLcE 4n4A== X-Gm-Message-State: AOAM533lLPMuGsmPjfhbvJzD/F8hAAuwJCLySkVItDtvZQ3M/kh34Oxu hzraAG7IQKXuhPjhl6r7ykDpw0VBIVfCNZfSkj/Drqn0jyo= X-Received: by 2002:a63:1d4:: with SMTP id 203mr17977325pgb.74.1589876393074; Tue, 19 May 2020 01:19:53 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Shevchenko Date: Tue, 19 May 2020 11:19:36 +0300 Message-ID: Subject: Re: [PATCH V5 4/4] x86/resctrl: Use appropriate API for strings terminated by newline To: Reinette Chatre Cc: Thomas Gleixner , Fenghua Yu , Borislav Petkov , Tony Luck , kuo-lang.tseng@intel.com, ravi.v.shankar@intel.com, Ingo Molnar , Babu Moger , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Linux Kernel Mailing List , Andy Shevchenko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 19, 2020 at 2:50 AM 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. ... > Changes since V4: > - Remove "mode" local variable from rdtgroup_mode_write(). This variable > was previously used to create shorter lines with the original strcmp() > code that was removed in patch 4/4. > - Andy pointed out that the repeated assignment to rdtgrp->mode could be > replaced by a single assignment after all the checks. This was initially > rejected because it would let the "RDT_MODE_PSEUDO_LOCKED" assignment > slip through. Even so, Andy's feedback revealed that the new changes > unintentionally let a user's attempt at setting the mode to pseudo-locked > be silently ignored where it previously reported an error. Restore original > user space behavior by returning success when user attempts to change any > mode when it is already the current mode (including pseudo-locked) and > returning failure when user attempts to set the mode to pseudo-locked. > After this change it is possible to follow Andy's original suggestion > of using a single assignment. (Andy) Glad we can do it! ... > + ret = sysfs_match_string(rdt_mode_str, buf); > + if (ret < 0) { > + rdt_last_cmd_puts("Unknown or unsupported mode\n"); > + ret = -EINVAL; This is redundant. > + goto out; > + } -- With Best Regards, Andy Shevchenko