Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1369125pxb; Fri, 21 Jan 2022 16:44:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZKfALsqVWQ1ZoypZMVkO8BgMhwx6obcBEilma3SsLRW8J8KqcIIWGM9D7odOwiDMj/m2x X-Received: by 2002:a17:902:be15:b0:149:a608:7098 with SMTP id r21-20020a170902be1500b00149a6087098mr5806733pls.63.1642812281095; Fri, 21 Jan 2022 16:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642812281; cv=none; d=google.com; s=arc-20160816; b=B9V9Q+86kEcvFO39abwBDwH6BW/yG/qAuc3fMvXgx68hmVml93s9icaQUNyCETxgb6 EIga/nrZIWwsNMsBUUZsZdPrFeCSt8sZCbnGv0ygpemIpMxw4e9w8stwqx/DoiD1kC1C 8HjAPAxbItbGgK0VMn0oc1Sc0UjQydauL9sQMyu3dHDqta2VnuGuGSGG/JMhgncGqqcb 0pmv8BUYIhkVxkcYSyohUl8l5fWyrvbDhaQfsizZV5pymTr51iuDirUVJkEG4dqIf6bu g37Dp1m1SBxeWZfHBkY2pAHeprs3XwAl1NKyexF4azYy0Q2Hg3YUKdSAx1liZDcxkUls 7ToA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=d/47DffcE+c3jCAlwDovIS7aShnFPAcgmE0Cy5Af+sM=; b=LJamwcay29k/TW3OR7/vmNebK1/Q4GSehJS0L4lfo2fzUAC2Q2e3vEkXTS58C2idvL ZrC1vF915kQkWnnzZTlrhPWX91EOFdonT9x3xykyOVhfejoH69uodXXIP7UZwlSeLd7Q FlDoYcPoqbF1r58itYgLFCoffEG3vWUX+9HfRrRb4n4qNh0UvM+CjjQis6UQy9PiI7Dk sru4tax2W1vqP6V5AO8uxz6iTpeHhzD5Dmr3310l7yHb2E1WXo8fYSiDguJAONHLy8oA OL7UfA31Dh4F5a6xOGgjQqeiyK1HeeIlnKUzJAZyqO4eqc6NiQSqvPHwOL4o3C9mPth0 1UYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GfzXzlpc; 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 w7si7856153plg.323.2022.01.21.16.44.29; Fri, 21 Jan 2022 16:44:41 -0800 (PST) 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=20210112 header.b=GfzXzlpc; 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 S1349858AbiAUJ47 (ORCPT + 99 others); Fri, 21 Jan 2022 04:56:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349787AbiAUJ46 (ORCPT ); Fri, 21 Jan 2022 04:56:58 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51386C061574 for ; Fri, 21 Jan 2022 01:56:58 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id w12-20020a17090a528c00b001b276aa3aabso13299005pjh.0 for ; Fri, 21 Jan 2022 01:56:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d/47DffcE+c3jCAlwDovIS7aShnFPAcgmE0Cy5Af+sM=; b=GfzXzlpcW7AKcVRUxF87xbg2Ci6kIiXy4dlvZd1G5MefdT5pGLTz7lXZ1xY/Dv1avS XMRSrMTG4dxH4oB02PFc2sXQGWXqXVLznCIy3js4Wm07gitZNpDLe8nsTy6sbSQgjOJ7 O8rf2wKVksUoPHlIpGaiUz0AcFXgDFNI3rChgrgBpeA4RxtD/OLlNUFkitdrWUPeZDsc F3M+OTZgIy/aaFgSuJDhVZgfCcGUKI5UiC+ofwLE7VZ4uVlZO76VWLO1N19ai4UN1AxI cdwQnKj56rsymd4k3xTxkvUg0yKIFPt61Frat6ofUdOunI/3ddfqZOHZY/Ufb5+s4qou FlkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=d/47DffcE+c3jCAlwDovIS7aShnFPAcgmE0Cy5Af+sM=; b=NuMZVbtWKnbnTbkBU43cejvaRkA0SzDVmqd3MHddZaU9a0xuqTDH5VEo/iZvrSHVuo 3Et1vwHzTVWsswI1R+cHeGYvurXccD7h/+nZ/1WAgp4fPg2e2rUTW4r89bMZ7wA3kwSj AqlX8/fuiHPCyQIEjq3BsbMakmt3/PoyzFq6S/dhSOhrqeKD7NsEBs5636RsY9FhON0S f9YV2WXHghDGMNkjZlgUB1Pe43Mo+faKy/tKAJ1/YBYaeksL5klj0nQcfqDhcn3tn8Ad cH2nadrnMyoNDMO0guowqSxtP6MMmLsJRMKCO+5arBVSForMinlaB+2SHsAC3/aiUbV8 Uyjw== X-Gm-Message-State: AOAM5325LatBdwRpUzm8iwmGcRA/1R+SLqlmw4SGvKX0eMZaibmArCMP bNtAs2u358YaeaiCAAKOn18= X-Received: by 2002:a17:902:da8c:b0:14a:909b:c911 with SMTP id j12-20020a170902da8c00b0014a909bc911mr3224302plx.103.1642759017887; Fri, 21 Jan 2022 01:56:57 -0800 (PST) Received: from vultr.guest ([141.164.42.249]) by smtp.gmail.com with ESMTPSA id c2sm4623661pgj.63.2022.01.21.01.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 01:56:57 -0800 (PST) From: Yuntao Wang To: Steven Rostedt , Ingo Molnar Cc: linux-kernel@vger.kernel.org, Yuntao Wang Subject: [PATCH] tracing: Use strim() to remove whitespace instead of doing it manually Date: Fri, 21 Jan 2022 09:56:23 +0000 Message-Id: <20220121095623.1826679-1-ytcoode@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tracing_set_trace_write() function just removes the trailing whitespace from the user supplied tracer name, but the leading whitespace should also be removed. In addition, if the user supplied tracer name contains only a few whitespace characters, the first one will not be removed using the current method, which results it a single whitespace character left in the buf. To fix all of these issues, we use strim() to correctly remove both the leading and trailing whitespace. Signed-off-by: Yuntao Wang --- kernel/trace/trace.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index a569a0cb81ee..a6e77db764cf 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6433,7 +6433,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf, { struct trace_array *tr = filp->private_data; char buf[MAX_TRACER_SIZE+1]; - int i; + char *name; size_t ret; int err; @@ -6447,11 +6447,9 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf, buf[cnt] = 0; - /* strip ending whitespace. */ - for (i = cnt - 1; i > 0 && isspace(buf[i]); i--) - buf[i] = 0; + name = strim(buf); - err = tracing_set_tracer(tr, buf); + err = tracing_set_tracer(tr, name); if (err) return err; -- 2.35.0.rc2