Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1574826pxu; Thu, 17 Dec 2020 13:17:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhpvSxLoYgD3rRlQLZ3f3kEHvg5N+nCCx6sU1IXzyR0nrQYtducTcLjS3lzRjfrB5AFus8 X-Received: by 2002:a17:906:1151:: with SMTP id i17mr978709eja.250.1608239861453; Thu, 17 Dec 2020 13:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608239861; cv=none; d=google.com; s=arc-20160816; b=ttSrr6UlMvCpXWvQtbHMX5yaLiqc8wJqeMPfJa5ctO7U5Zx6tqakOylPvNnpIxSMFk AEtxsa3QkrygU8fpVYL1aoD1YHWu6PFOnv/TMIU9B4IQ85sufl0kCX1D+3NLDDoQjCSF nJzMzAhtxZrNZanH8aoTads2BPneIC/3oGWHxeIKNQRtgeEJ1WUjuhceAPbfQ+lGWxhQ J+lhW2IQ/Jhn23tt9Ft6IE5s4jdN+kowA19JTOjEtnIuvoqLgFjf3O26K3/ubhmU4ivA +RrIs1eeWPUxGvRn6ZEfLvovm9wu+xG7RMsXGGFP3SmWlwqRG7f6x5QwJv5W4JBxLs2l FvRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:references:in-reply-to :message-id:date:subject:cc:to:from; bh=DRHgaIwH12mWGeJBC3PRa6tYwkl+tXTd+fUQyPNqLDc=; b=pYChnSTZYddLkcK+GoTl9OEbobeA68kpQYuJ5oSgWTihwXay/WX396WDpKnUl10g44 PmmOkgQ6BznxAZaQRgesxUlRVLIupnLOcyUYszmSMUjkV1fhtE5TRU0wNIaRyzMh6V6B 7hluQuIZU/Q17Rj71t5EmduNK9CwFkuh8xAwWs2GZXXkDyouFM3q4v/tiAYzdfct16wr RD7pEpLbkoeA7CxdyNc0OsU9mkfUPx9lbdWd01pfdQ4LYDxxS3/sBtUPIMO/ITrga72g 5QHKz1UlcybuXtirCesa0Wq6Ah2AAm3cT6YU8DKyV+kauu3jFyt9VtoA0KvcZmDiqhZp GxRw== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si3470877ejr.206.2020.12.17.13.17.18; Thu, 17 Dec 2020 13:17: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; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731811AbgLQVPT (ORCPT + 99 others); Thu, 17 Dec 2020 16:15:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:49862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731787AbgLQVPS (ORCPT ); Thu, 17 Dec 2020 16:15:18 -0500 From: Tom Zanussi Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: rostedt@goodmis.org, axelrasmussen@google.com Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/5] tracing: Update synth command errors Date: Thu, 17 Dec 2020 15:14:28 -0600 Message-Id: <9c6f559ff46b597312509974a3546e82fdc0907f.1608238451.git.zanussi@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since array types are handled differently, errors referencing them also need to be handled differently. Add and use a new INVALID_ARRAY_SPEC error. Also add INVALID_CMD and INVALID_DYN_CMD to catch and display the correct form for badly-formed commands, which can also be used in place of CMD_INCOMPLETE, which is removed, and remove CMD_TOO_LONG, since it's no longer used. Signed-off-by: Tom Zanussi --- kernel/trace/trace_events_synth.c | 71 +++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index 66ccbab3483b..2a9c8bf74bb2 100644 --- a/kernel/trace/trace_events_synth.c +++ b/kernel/trace/trace_events_synth.c @@ -23,13 +23,14 @@ #undef ERRORS #define ERRORS \ C(BAD_NAME, "Illegal name"), \ - C(CMD_INCOMPLETE, "Incomplete command"), \ + C(INVALID_CMD, "Command must be of the form: field[;field] ..."),\ + C(INVALID_DYN_CMD, "Command must be of the form: s or -:[synthetic/] field[;field] ..."),\ C(EVENT_EXISTS, "Event already exists"), \ C(TOO_MANY_FIELDS, "Too many fields"), \ C(INCOMPLETE_TYPE, "Incomplete type"), \ C(INVALID_TYPE, "Invalid type"), \ - C(INVALID_FIELD, "Invalid field"), \ - C(CMD_TOO_LONG, "Command too long"), + C(INVALID_FIELD, "Invalid field"), \ + C(INVALID_ARRAY_SPEC, "Invalid array specification"), #undef C #define C(a, b) SYNTH_ERR_##a @@ -651,6 +652,10 @@ static struct synth_field *parse_synth_field(int argc, char **argv, size = synth_field_size(field->type); if (size < 0) { + if (array) + synth_err(SYNTH_ERR_INVALID_ARRAY_SPEC, errpos(field_name)); + else + synth_err(SYNTH_ERR_INVALID_TYPE, errpos(field_type)); ret = -EINVAL; goto free; } else if (size == 0) { @@ -1171,7 +1176,7 @@ static int __create_synth_event(const char *name, const char *raw_fields) mutex_lock(&event_mutex); if (name[0] == '\0') { - synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); + synth_err(SYNTH_ERR_INVALID_CMD, 0); ret = -EINVAL; goto out; } @@ -1221,6 +1226,7 @@ static int __create_synth_event(const char *name, const char *raw_fields) argv_free(argv); if (consumed < argc) { + synth_err(SYNTH_ERR_INVALID_CMD, 0); ret = -EINVAL; goto err; } @@ -1229,7 +1235,7 @@ static int __create_synth_event(const char *name, const char *raw_fields) } if (n_fields == 0) { - synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); + synth_err(SYNTH_ERR_INVALID_CMD, 0); ret = -EINVAL; goto err; } @@ -1367,6 +1373,37 @@ int synth_event_delete(const char *event_name) } EXPORT_SYMBOL_GPL(synth_event_delete); +static int check_command(const char *raw_command) +{ + char **argv = NULL, *cmd, *saved_cmd, *name_and_field; + int argc, ret = 0; + + cmd = saved_cmd = kstrdup(raw_command, GFP_KERNEL); + if (!cmd) + return -ENOMEM; + + name_and_field = strsep(&cmd, ";"); + if (!name_and_field) { + ret = -EINVAL; + goto free; + } + + argv = argv_split(GFP_KERNEL, name_and_field, &argc); + if (!argv) { + ret = -ENOMEM; + goto free; + } + + if (argc < 3) + ret = -EINVAL; +free: + kfree(saved_cmd); + if (argv) + argv_free(argv); + + return ret; +} + static int create_or_delete_synth_event(const char *raw_command) { char *name = NULL, *fields, *p; @@ -1378,9 +1415,17 @@ static int create_or_delete_synth_event(const char *raw_command) last_cmd_set(raw_command); + ret = check_command(raw_command); + if (ret) { + synth_err(SYNTH_ERR_INVALID_CMD, 0); + return ret; + } + p = strpbrk(raw_command, " \t"); - if (!p) + if (!p) { + synth_err(SYNTH_ERR_INVALID_CMD, 0); return -EINVAL; + } name = kmemdup_nul(raw_command, p - raw_command, GFP_KERNEL); if (!name) @@ -1954,8 +1999,10 @@ static int create_synth_event(const char *raw_command) last_cmd_set(raw_command); p = strpbrk(raw_command, " \t"); - if (!p) + if (!p) { + synth_err(SYNTH_ERR_INVALID_CMD, 0); return -EINVAL; + } fields = skip_spaces(p); @@ -1968,13 +2015,21 @@ static int create_synth_event(const char *raw_command) /* This interface accepts group name prefix */ if (strchr(name, '/')) { len = str_has_prefix(name, SYNTH_SYSTEM "/"); - if (len == 0) + if (len == 0) { + synth_err(SYNTH_ERR_INVALID_DYN_CMD, 0); return -EINVAL; + } name += len; } len = name - raw_command; + ret = check_command(raw_command + len); + if (ret) { + synth_err(SYNTH_ERR_INVALID_CMD, 0); + return ret; + } + name = kmemdup_nul(raw_command + len, p - raw_command - len, GFP_KERNEL); if (!name) return -ENOMEM; -- 2.17.1