Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1376866rdb; Sun, 7 Jan 2024 17:31:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi7BpDT6I+XwTGqjGxg9Wqp7dzUrhdlB2sy9ntDHkL1d6KNii+N7sGNM3dVcIKiPlzwjqE X-Received: by 2002:a17:906:da85:b0:a26:f1e7:2b6d with SMTP id xh5-20020a170906da8500b00a26f1e72b6dmr1414803ejb.50.1704677514652; Sun, 07 Jan 2024 17:31:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704677514; cv=none; d=google.com; s=arc-20160816; b=eSIhdT+tp6ZCWuOMob0l35DweXd1kn8wiIucnI2Elbif6LyHO6QDENLEnHnOmlKRJF /DmJFYlqlKynt6iwor0mOHmCiqK6ElHaqAW6eZiL5ibaf7kmZ04rjDtvhmb3OYQMWazV WsyBDynVaGlswePveOwNuEqFRKZxDjp/0e9n5GA4p+dJapWYOL4BhcJOvEM5HsiHBQa4 M0jTcD3GyT2cyciktrBtho98tjaTt8Y9imCwDTd+VEGgC7kjJIPUOxUcPZKbeaDYjBsb Y4oGY5j8DAUbIKvb30STVjOr1bGYH/sIdwqT6aPBPecu5MkbFpUGq4T8Cmb5My4GrUVg d5gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:subject:cc:to:from :date; bh=gOwMano/b4CP+jsqV1C96ANkRhwdYauZcz+jylXJBNw=; fh=RoeTY7nyqCOYHzaNdWxSPwta4OVZeG+PIDpxLKB7r2E=; b=CMc+g2s6FKc2KOLYfa46yaWzyEXGhCOBjxTbcxAUyAso7EfzkvUqD132xInny3Ocz5 JVtc1W3irhgH9ZNZqF1Y1xexAnkE9F2HWpWuBg1gTCVxomneLrXknkccIyT4DXD3z4PW LH8Rr7gs4zzzCIt2dftARopLylNXMW2UZ2g9zbRlhF8WWoxaDhJSWtcehVsm/anUKhCn Q6E6mfg9qvF0dbrx0Nrle/wVoFVa8gb5u0/9z6VwdoNqC6T1LJBeg8GlxUKsMieaCLVL u5vTiQzhx0FEPvqReu0f+RjQmuPlcuP+I+lLG4NEO+LyoTgXyKGtTWDXp0JgkS4joShM u6pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19040-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qx22-20020a170906fcd600b00a27b3cfb05asi2665303ejb.386.2024.01.07.17.31.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 17:31:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19040-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19040-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5DE8A1F2171C for ; Mon, 8 Jan 2024 01:31:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55787EBE; Mon, 8 Jan 2024 01:31:47 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB800800; Mon, 8 Jan 2024 01:31:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 787EAC433C8; Mon, 8 Jan 2024 01:31:45 +0000 (UTC) Date: Sun, 7 Jan 2024 20:32:58 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mathieu Desnoyers , Andy Shevchenko , Tom Zanussi Subject: [PATCH] tracing histograms: Simplify parse_actions() function Message-ID: <20240107203258.37e26d2b@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit From: "Steven Rostedt (Google)" The parse_actions() function uses 'len = str_has_prefix()' to test which action is in the string being parsed. But then it goes and repeats the logic for each different action. This logic can be simplified and duplicate code can be removed as 'len' contains the length of the found prefix which should be used for all actions. Link: https://lore.kernel.org/all/20240107112044.6702cb66@gandalf.local.home/ Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_hist.c | 49 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 5ecf3c8bde20..6ece1308d36a 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -4805,36 +4805,35 @@ static int parse_actions(struct hist_trigger_data *hist_data) int len; for (i = 0; i < hist_data->attrs->n_actions; i++) { + enum handler_id hid = 0; + char *action_str; + str = hist_data->attrs->action_str[i]; - if ((len = str_has_prefix(str, "onmatch("))) { - char *action_str = str + len; + if ((len = str_has_prefix(str, "onmatch("))) + hid = HANDLER_ONMATCH; + else if ((len = str_has_prefix(str, "onmax("))) + hid = HANDLER_ONMAX; + else if ((len = str_has_prefix(str, "onchange("))) + hid = HANDLER_ONCHANGE; - data = onmatch_parse(tr, action_str); - if (IS_ERR(data)) { - ret = PTR_ERR(data); - break; - } - } else if ((len = str_has_prefix(str, "onmax("))) { - char *action_str = str + len; + action_str = str + len; - data = track_data_parse(hist_data, action_str, - HANDLER_ONMAX); - if (IS_ERR(data)) { - ret = PTR_ERR(data); - break; - } - } else if ((len = str_has_prefix(str, "onchange("))) { - char *action_str = str + len; + switch (hid) { + case HANDLER_ONMATCH: + data = onmatch_parse(tr, action_str); + break; + case HANDLER_ONMAX: + case HANDLER_ONCHANGE: + data = track_data_parse(hist_data, action_str, hid); + break; + default: + data = ERR_PTR(-EINVAL); + break; + } - data = track_data_parse(hist_data, action_str, - HANDLER_ONCHANGE); - if (IS_ERR(data)) { - ret = PTR_ERR(data); - break; - } - } else { - ret = -EINVAL; + if (IS_ERR(data)) { + ret = PTR_ERR(data); break; } -- 2.42.0