Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp6150821pxu; Wed, 23 Dec 2020 15:19:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwC8ubBcy32JwaMAcNKgh7L1nyg5tDeOUZuZDLN55fpr9hmR6NQ2UjeGmVFmgaa61IWEHGi X-Received: by 2002:a17:906:b306:: with SMTP id n6mr25745244ejz.473.1608765555902; Wed, 23 Dec 2020 15:19:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608765555; cv=none; d=google.com; s=arc-20160816; b=j6e398EIL73kRbbrmzhn/tMlFwPx011eubxwaicXxJ0W75hPGonEn2mmjtMh8WEnLr aRKDt8NoLEtiyq8n2AHppu+pb3p8ykM3yRxiDchWPLp6l7eWmE52g9X2BbpcBfVHjHY4 /C8LUTvYT0+2ZzECOo5P/2HjZgEhmfkwBY5tbf3TcC03WYFrTTO9hKusZvIcdoa40J/H 3rglLm4SmfA01Uh/4ss8PB0KeaN9lSDwCGx3DCXfncwd4p7IJxhMgxN6hKr4PD+GR56q iWuWCajGWXatycNonRmfcV0bmhzikyj5tU9P/gNhmGF1LflAMzid7A0XDU7dvWFmPGex SKGg== 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 :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=hLH+Wn/Q4B1lNprxxNPJ4LKYzTm6RXZgFSTKd8mtfDM=; b=gysnsq39cPvnUExDeFgDEJkyZ1jsZnpnJ/0bFHsuysETD56hSDGILeEZTSB3RvLKVV dzJ8VxqNj91/2Nvwz4AoQH0EGbNijV5CThL1tlWY8eq5CIoQsDEVlldq/oxGEy5+/ksj mkA5EfsAeOAWwUyk1BFe23ovOpw9GltYHXpdl4RD7N6LLC5sniSp7Z7X/16tnvNTN9V8 eiIgdtm3m7QlKvweagdJbmmXJ6Px2i/dmKCi1T0hfjv81snKA8oUI2a+t2cmpcScyHk9 38wdU4VixR9uPiG6oFdFZQYZGGatGz3oKnRBAwzvaPLGBhUMdHAJFiQJ42pPF2ao+Jzm P5SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iH27+XaA; 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 q6si14844221edn.416.2020.12.23.15.18.53; Wed, 23 Dec 2020 15:19:15 -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=@kernel.org header.s=k20201202 header.b=iH27+XaA; 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 S1727064AbgLWXSK (ORCPT + 99 others); Wed, 23 Dec 2020 18:18:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:35168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726611AbgLWXSK (ORCPT ); Wed, 23 Dec 2020 18:18:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05617223E0; Wed, 23 Dec 2020 23:17:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1608765449; bh=A3WSiGWqc+kIrTK8z3wKHj/uIm8ph2fAerx7FVPkG3o=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=iH27+XaAE2Ku8KEaiAUIhgPQsmm0uu/s92aOFZovdjjmvfNvSxkPjVKmIH5cTs3G0 RW7A+cbWNgZlNcGp6J3JaUo0bmx7+vxqECHM9unbGK4Yw8BRHTzNcUdP2yciJ0NmhE IB/JP5m4mLw1ZPVvSsjUhNoeN3gT7d4cvQgB6omS/OeY6X1WYItXfZ2KAsV7tVTKPE 0Yn+aGDhIkaTg9n+ZrNiLoW3uSYLGUYt0b8qVIsdTyDgT9XOCbJ3PvEMtAEUQn7/LQ cDADy1HLRGbPECnsUnHKPpf/re25VYf7wD8BhjlMbPbx9x/v4fPGfzKDzyg/YXOERS Hj7YX70cjMvTA== Message-ID: <48d21108d635e707ef135cac7fa0eaabc1cf5e9a.camel@kernel.org> Subject: Re: [PATCH v5 2/5] tracing: Rework synthetic event command parsing From: Tom Zanussi To: Masami Hiramatsu Cc: rostedt@goodmis.org, axelrasmussen@google.com, dan.carpenter@oracle.com, linux-kernel@vger.kernel.org Date: Wed, 23 Dec 2020 17:17:27 -0600 In-Reply-To: <20201222214259.464311df07a343de821db568@kernel.org> References: <20201222214259.464311df07a343de821db568@kernel.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Masami, On Tue, 2020-12-22 at 21:42 +0900, Masami Hiramatsu wrote: > Hi Tom, > > On Mon, 21 Dec 2020 15:44:28 -0600 > Tom Zanussi wrote: > > > > @@ -656,7 +651,6 @@ static struct synth_field > > *parse_synth_field(int argc, const char **argv, > > > > size = synth_field_size(field->type); > > if (size < 0) { > > - synth_err(SYNTH_ERR_INVALID_TYPE, errpos(field_type)); > > Why did you remove this error message? It wasn't actually removed - it was just moved into the next patch, so is still there. I'll move it back here to avoid confusion. > > [..] > > @@ -1228,26 +1189,47 @@ static int __create_synth_event(int argc, > > const char *name, const char **argv) > > goto out; > > } > > > > - for (i = 0; i < argc - 1; i++) { > > - if (strcmp(argv[i], ";") == 0) > > - continue; > > + tmp_fields = saved_fields = kstrdup(raw_fields, GFP_KERNEL); > > + if (!tmp_fields) { > > + ret = -ENOMEM; > > + goto out; > > + } > > + > > + while ((field_str = strsep(&tmp_fields, ";")) != NULL) { > > if (n_fields == SYNTH_FIELDS_MAX) { > > synth_err(SYNTH_ERR_TOO_MANY_FIELDS, 0); > > ret = -EINVAL; > > goto err; > > } > > > > - field = parse_synth_field(argc - i, &argv[i], > > &consumed); > > + argv = argv_split(GFP_KERNEL, field_str, &argc); > > + if (!argv) { > > + ret = -ENOMEM; > > + goto err; > > + } > > + > > + if (!argc) > > + continue; > > + > > + field = parse_synth_field(argc, argv, &consumed); > > if (IS_ERR(field)) { > > + argv_free(argv); > > ret = PTR_ERR(field); > > goto err; > > } > > + > > + argv_free(argv); > > + > > + if (consumed < argc) { > > + ret = -EINVAL; > > + goto err; > > + } > > You can check the consumed < argc in parse_synth_field(), unless > you keep the backward compatibility - I think you can add an > inner loop for it, something like > > while ((field_str = strsep(&tmp_fields, ";")) != NULL) { > argv = argv_split(...); > consumed = 0; > while (argc > consumed) { > // increment consumed in parse_synth_field() > field = parse_synth_field(argc - consumed, argv + consumed, > &consumed); > if (IS_ERR(field)) {...} > > fields[n_fields++] = field; > if (n_fields == SYNTH_FIELDS_MAX) {...} > } > > argv_free(argv); > } > > what would you think? Hmm, not sure this helps - there's only supposed to be one field per field_str and consumed returns either 2 or 3 depending on the field. consumed is only used to detect whether there were unused words and if so flag an error, rather than loop around to try to get another field. > > > + > > fields[n_fields++] = field; > > - i += consumed - 1; > > } > > > > - if (i < argc && strcmp(argv[i], ";") != 0) { > > - synth_err(SYNTH_ERR_INVALID_FIELD, errpos(argv[i])); > > + if (n_fields == 0) { > > + synth_err(SYNTH_ERR_CMD_INCOMPLETE, 0); > > ret = -EINVAL; > > goto err; > > } > > @@ -1266,6 +1248,8 @@ static int __create_synth_event(int argc, > > const char *name, const char **argv) > > out: > > mutex_unlock(&event_mutex); > > > > + kfree(saved_fields); > > + > > return ret; > > err: > > for (i = 0; i < n_fields; i++) > > @@ -1385,29 +1369,35 @@ EXPORT_SYMBOL_GPL(synth_event_delete); > > > > static int create_or_delete_synth_event(const char *raw_command) > > { > > - char **argv, *name = NULL; > > - int argc = 0, ret = 0; > > + char *name = NULL, *fields, *p; > > + int ret = 0; > > > > - argv = argv_split(GFP_KERNEL, raw_command, &argc); > > - if (!argv) > > - return -ENOMEM; > > + raw_command = skip_spaces(raw_command); > > + if (raw_command[0] == '\0') > > + return ret; > > > > - if (!argc) > > - goto free; > > + last_cmd_set(raw_command); > > > > - name = argv[0]; > > + p = strpbrk(raw_command, " \t"); > > + if (!p) > > + return -EINVAL; > > Hmm, this may drop the ability to delete an event with "!name", > it always requires some spaces after the name. > Yes, good point, will fix that and also add a test case for just !name. Thanks, Tom > Thank you, > >