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. -- Steve > + > + return ret; > +}