Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp438057pxx; Mon, 26 Oct 2020 11:55:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT6vubw6W61KNB7IJzA8pOE+yrawQqtKZUQt12KpJVeQruJQb+yRw22Wfm+2Z/i+JGjIwq X-Received: by 2002:aa7:cc84:: with SMTP id p4mr1525909edt.97.1603738525674; Mon, 26 Oct 2020 11:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603738525; cv=none; d=google.com; s=arc-20160816; b=S8RCG3JSQXe/fXRQQMZcoAU6NiwJ8p/eUnLkj04GyLb7KnVwFcMaZ9GVrxYlT/PJQS p3gWBpgjrIaATGjdRGVVpqsTKO4xLKnxnQ6M2pG1cHBiiVB2NUopWPs3Vccy6lE6OcwX OaRYuLTijTMkdBkf1e7ibMDj6/U/NxokbYyKX5FSj58huUDEhI8boHfUYcXdudus6V3v 9kQ+wT6/k3jJLsIicuLicmOLrobwVBl5DBhbH+V9xO4PUbNtLaiyPNcgH8xrGCN3/yrJ DlJwcDzDnvckwx7zYhZldvcR6Nw5OqX68ZRX5gaVY6fm0T5U8bcR9OnNhHjnsPBB9KvI FDvA== 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:dkim-signature; bh=kGC7YoO4vfsIcpSXeQPhctABNnKDDelHz4CuOUizP/0=; b=b2j1Zonl/8JXj+Je3QppGaKIzPJHZcfhKQBqcGi5AtSu27r5Xu51izXzd9FG2v3mQh z0QmwJ9LwXEwfonXOeSy+Qo/NXkYwo9zmhIBYnu2kpIJ/uRws/mFr5XgDl5lgTAvUH0k T55AD/8Lh3tHXtsGDlv19xCNCaR+zlPNBamSMEGoyFum3QCkHZQkOEyXpH8wGUPeezR2 kumpQhQl1izcKaqq3JlZxteP5tnAOlBKUhGcM6hP+BCxDXtvwFz7e8LqcqbXKCJhEzsc YH4exhaKWe0YjoSaao8D056Qnz8c+5/kapW/6oEtaKpXiMXK0ZdXTX2aLLFhEmChYBWz 8feA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kDXS8pV5; 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 v13si11024132edl.552.2020.10.26.11.55.03; Mon, 26 Oct 2020 11:55:25 -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=@kernel.org header.s=default header.b=kDXS8pV5; 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 S1783125AbgJZPGZ (ORCPT + 99 others); Mon, 26 Oct 2020 11:06:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:44370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1783098AbgJZPGV (ORCPT ); Mon, 26 Oct 2020 11:06:21 -0400 Received: from localhost.localdomain (c-73-209-127-30.hsd1.il.comcast.net [73.209.127.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7443B239D2; Mon, 26 Oct 2020 15:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603724780; bh=0S1lNpt6nPnQcmwiQtEKAjQ4DLfZe9YHBSGXOYUKwIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=kDXS8pV5H8cZkE5gUkles6CYsF7RTltSpO0i/d15jCGx7WpUpFC5nCYDWWI+hPQWD 4Qj7Zs4XFRoK5wzow/SwLXtgHanjDlsyf3zG17D0sekE9bUXp1l6YoFxBFYuzsKMwV Vv1tOaxJIEGjBmdOGHe4MFG3jkYaAibEPkbdJnXc= From: Tom Zanussi To: rostedt@goodmis.org, axelrasmussen@google.com Cc: mhiramat@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/5] tracing: Update synth command errors Date: Mon, 26 Oct 2020 10:06:11 -0500 Message-Id: <8671adc7ce95ff1d5c7b037d371467e96f7f2914.1603723933.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 | 68 +++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c index 0d2fe4b6bd94..fdf0e85c0b8a 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 @@ -648,6 +649,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) { @@ -1169,7 +1174,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; } @@ -1222,7 +1227,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; } @@ -1360,6 +1365,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; @@ -1372,12 +1408,16 @@ static int create_or_delete_synth_event(const char *raw_command) last_cmd_set(raw_command); ret = check_command(raw_command); - if (ret) + 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); fields = skip_spaces(p); @@ -1948,8 +1988,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); @@ -1962,13 +2004,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); ret = __create_synth_event(name, fields); -- 2.17.1