Re: [PATCH v3 04/12] tracing: Add dynamic event command creation interface

From: Tom Zanussi
Date: Wed Jan 29 2020 - 14:02:57 EST


Hi Steve,

On Wed, 2020-01-29 at 13:00 -0500, Steven Rostedt wrote:
> On Fri, 24 Jan 2020 16:56:15 -0600
> Tom Zanussi <zanussi@xxxxxxxxxx> wrote:
>
> > +/**
> > + * dynevent_arg_add - Add an arg to a dynevent_cmd
> > + * @cmd: A pointer to the dynevent_cmd struct representing the new
> > event cmd
> > + * @arg: The argument to append to the current cmd
> > + *
> > + * Append an argument to a dynevent_cmd. The argument string will
> > be
> > + * appended to the current cmd string, followed by a separator, if
> > + * applicable. Before the argument is added, the check_arg()
> > + * function, if defined, is called.
> > + *
> > + * The cmd string, separator, and check_arg() function should be
> > set
> > + * using the dynevent_arg_init() before any arguments are added
> > using
> > + * this function.
> > + *
> > + * Return: 0 if successful, error otherwise.
> > + */
> > +int dynevent_arg_add(struct dynevent_cmd *cmd,
> > + struct dynevent_arg *arg)
> > +{
> > + int ret = 0;
> > + int delta;
> > + char *q;
> > +
> > + if (arg->check_arg) {
> > + ret = arg->check_arg(arg);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + q = cmd->buf + (cmd->maxlen - cmd->remaining);
> > +
> > + delta = snprintf(q, cmd->remaining, " %s%c", arg->str,
> > arg->separator);
> > + if (delta >= cmd->remaining) {
> > + pr_err("String is too long: %s\n", arg->str);
> > + return -E2BIG;
> > + }
> > + cmd->remaining -= delta;
>
> This looks like you can take advantage of the seq_buf code
> (see /lib/seq_buf.c), as that handles a lot of this for you.
>
> As I'm trying to get this into the merge window, I won't delay this
> for
> that (unless I find something else to delay this for), but this
> should
> definitely incorporate seq_buf and not handle its own buffering.
>

OK, I can send a follow-on patch that does this.

Note that I just sent a v4 series which moves most of the code in this
patch to trace_dynevent.{c,h} as requested by Masami. No other changes
from v3 were made other than adding acks.

Thanks,

Tom


> -- Steve
>
>
>
> > +
> > + return ret;
> > +}