Commit 74403b6c authored by Tom Zanussi's avatar Tom Zanussi Committed by Steven Rostedt (VMware)

tracing: Remove check_arg() callbacks from dynevent args

It's kind of strange to have check_arg() callbacks as part of the arg
objects themselves; it makes more sense to just pass these in when the
args are added instead.

Remove the check_arg() callbacks from those objects which also means
removing the check_arg() args from the init functions, adding them to
the add functions and fixing up existing callers.

Link: http://lkml.kernel.org/r/c7708d6f177fcbe1a36b6e4e8e150907df0fa5d2.1580506712.git.zanussi@kernel.orgReviewed-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarTom Zanussi <zanussi@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 249d7b2e
...@@ -228,27 +228,30 @@ fs_initcall(init_dynamic_event); ...@@ -228,27 +228,30 @@ fs_initcall(init_dynamic_event);
* dynevent_arg_add - Add an arg to a dynevent_cmd * dynevent_arg_add - Add an arg to a dynevent_cmd
* @cmd: A pointer to the dynevent_cmd struct representing the new event cmd * @cmd: A pointer to the dynevent_cmd struct representing the new event cmd
* @arg: The argument to append to the current cmd * @arg: The argument to append to the current cmd
* @check_arg: An (optional) pointer to a function checking arg sanity
* *
* Append an argument to a dynevent_cmd. The argument string will be * Append an argument to a dynevent_cmd. The argument string will be
* appended to the current cmd string, followed by a separator, if * appended to the current cmd string, followed by a separator, if
* applicable. Before the argument is added, the check_arg() * applicable. Before the argument is added, the @check_arg function,
* function, if defined, is called. * if present, will be used to check the sanity of the current arg
* string.
* *
* The cmd string, separator, and check_arg() function should be set * The cmd string and separator should be set using the
* using the dynevent_arg_init() before any arguments are added using * dynevent_arg_init() before any arguments are added using this
* this function. * function.
* *
* Return: 0 if successful, error otherwise. * Return: 0 if successful, error otherwise.
*/ */
int dynevent_arg_add(struct dynevent_cmd *cmd, int dynevent_arg_add(struct dynevent_cmd *cmd,
struct dynevent_arg *arg) struct dynevent_arg *arg,
dynevent_check_arg_fn_t check_arg)
{ {
int ret = 0; int ret = 0;
int delta; int delta;
char *q; char *q;
if (arg->check_arg) { if (check_arg) {
ret = arg->check_arg(arg); ret = check_arg(arg);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -269,6 +272,7 @@ int dynevent_arg_add(struct dynevent_cmd *cmd, ...@@ -269,6 +272,7 @@ int dynevent_arg_add(struct dynevent_cmd *cmd,
* dynevent_arg_pair_add - Add an arg pair to a dynevent_cmd * dynevent_arg_pair_add - Add an arg pair to a dynevent_cmd
* @cmd: A pointer to the dynevent_cmd struct representing the new event cmd * @cmd: A pointer to the dynevent_cmd struct representing the new event cmd
* @arg_pair: The argument pair to append to the current cmd * @arg_pair: The argument pair to append to the current cmd
* @check_arg: An (optional) pointer to a function checking arg sanity
* *
* Append an argument pair to a dynevent_cmd. An argument pair * Append an argument pair to a dynevent_cmd. An argument pair
* consists of a left-hand-side argument and a right-hand-side * consists of a left-hand-side argument and a right-hand-side
...@@ -278,24 +282,26 @@ int dynevent_arg_add(struct dynevent_cmd *cmd, ...@@ -278,24 +282,26 @@ int dynevent_arg_add(struct dynevent_cmd *cmd,
* *
* The lhs argument string will be appended to the current cmd string, * The lhs argument string will be appended to the current cmd string,
* followed by an operator, if applicable, followd by the rhs string, * followed by an operator, if applicable, followd by the rhs string,
* followed finally by a separator, if applicable. Before anything is * followed finally by a separator, if applicable. Before the
* added, the check_arg() function, if defined, is called. * argument is added, the @check_arg function, if present, will be
* used to check the sanity of the current arg strings.
* *
* The cmd strings, operator, separator, and check_arg() function * The cmd strings, operator, and separator should be set using the
* should be set using the dynevent_arg_pair_init() before any arguments * dynevent_arg_pair_init() before any arguments are added using this
* are added using this function. * function.
* *
* Return: 0 if successful, error otherwise. * Return: 0 if successful, error otherwise.
*/ */
int dynevent_arg_pair_add(struct dynevent_cmd *cmd, int dynevent_arg_pair_add(struct dynevent_cmd *cmd,
struct dynevent_arg_pair *arg_pair) struct dynevent_arg_pair *arg_pair,
dynevent_check_arg_fn_t check_arg)
{ {
int ret = 0; int ret = 0;
int delta; int delta;
char *q; char *q;
if (arg_pair->check_arg) { if (check_arg) {
ret = arg_pair->check_arg(arg_pair); ret = check_arg(arg_pair);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -385,20 +391,16 @@ void dynevent_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen, ...@@ -385,20 +391,16 @@ void dynevent_cmd_init(struct dynevent_cmd *cmd, char *buf, int maxlen,
/** /**
* dynevent_arg_init - Initialize a dynevent_arg object * dynevent_arg_init - Initialize a dynevent_arg object
* @arg: A pointer to the dynevent_arg struct representing the arg * @arg: A pointer to the dynevent_arg struct representing the arg
* @check_arg: An (optional) pointer to a function checking arg sanity
* @separator: An (optional) separator, appended after adding the arg * @separator: An (optional) separator, appended after adding the arg
* *
* Initialize a dynevent_arg object. A dynevent_arg represents an * Initialize a dynevent_arg object. A dynevent_arg represents an
* object used to append single arguments to the current command * object used to append single arguments to the current command
* string. The @check_arg function, if present, will be used to check * string. After the arg string is successfully appended to the
* the sanity of the current arg string (which is directly set by the
* caller). After the arg string is successfully appended to the
* command string, the optional @separator is appended. If no * command string, the optional @separator is appended. If no
* separator was specified when initializing the arg, a space will be * separator was specified when initializing the arg, a space will be
* appended. * appended.
*/ */
void dynevent_arg_init(struct dynevent_arg *arg, void dynevent_arg_init(struct dynevent_arg *arg,
dynevent_check_arg_fn_t check_arg,
char separator) char separator)
{ {
memset(arg, '\0', sizeof(*arg)); memset(arg, '\0', sizeof(*arg));
...@@ -406,14 +408,11 @@ void dynevent_arg_init(struct dynevent_arg *arg, ...@@ -406,14 +408,11 @@ void dynevent_arg_init(struct dynevent_arg *arg,
if (!separator) if (!separator)
separator = ' '; separator = ' ';
arg->separator = separator; arg->separator = separator;
arg->check_arg = check_arg;
} }
/** /**
* dynevent_arg_pair_init - Initialize a dynevent_arg_pair object * dynevent_arg_pair_init - Initialize a dynevent_arg_pair object
* @arg_pair: A pointer to the dynevent_arg_pair struct representing the arg * @arg_pair: A pointer to the dynevent_arg_pair struct representing the arg
* @check_arg: An (optional) pointer to a function checking arg sanity
* @operator: An (optional) operator, appended after adding the first arg * @operator: An (optional) operator, appended after adding the first arg
* @separator: An (optional) separator, appended after adding the second arg * @separator: An (optional) separator, appended after adding the second arg
* *
...@@ -422,16 +421,13 @@ void dynevent_arg_init(struct dynevent_arg *arg, ...@@ -422,16 +421,13 @@ void dynevent_arg_init(struct dynevent_arg *arg,
* variable_name;' or 'x+y' to the current command string. An * variable_name;' or 'x+y' to the current command string. An
* argument pair consists of a left-hand-side argument and a * argument pair consists of a left-hand-side argument and a
* right-hand-side argument separated by an operator, which can be * right-hand-side argument separated by an operator, which can be
* whitespace, all followed by a separator, if applicable. The * whitespace, all followed by a separator, if applicable. After the
* @check_arg function, if present, will be used to check the sanity * first arg string is successfully appended to the command string,
* of the current arg strings (which is directly set by the caller). * the optional @operator is appended, followed by the second arg and
* After the first arg string is successfully appended to the command * and optional @separator. If no separator was specified when
* string, the optional @operator is appended, followed by the second * initializing the arg, a space will be appended.
* arg and and optional @separator. If no separator was specified
* when initializing the arg, a space will be appended.
*/ */
void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair, void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair,
dynevent_check_arg_fn_t check_arg,
char operator, char separator) char operator, char separator)
{ {
memset(arg_pair, '\0', sizeof(*arg_pair)); memset(arg_pair, '\0', sizeof(*arg_pair));
...@@ -443,8 +439,6 @@ void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair, ...@@ -443,8 +439,6 @@ void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair,
if (!separator) if (!separator)
separator = ' '; separator = ' ';
arg_pair->separator = separator; arg_pair->separator = separator;
arg_pair->check_arg = check_arg;
} }
/** /**
......
...@@ -126,28 +126,27 @@ typedef int (*dynevent_check_arg_fn_t)(void *data); ...@@ -126,28 +126,27 @@ typedef int (*dynevent_check_arg_fn_t)(void *data);
struct dynevent_arg { struct dynevent_arg {
const char *str; const char *str;
char separator; /* e.g. ';', ',', or nothing */ char separator; /* e.g. ';', ',', or nothing */
dynevent_check_arg_fn_t check_arg;
}; };
extern void dynevent_arg_init(struct dynevent_arg *arg, extern void dynevent_arg_init(struct dynevent_arg *arg,
dynevent_check_arg_fn_t check_arg,
char separator); char separator);
extern int dynevent_arg_add(struct dynevent_cmd *cmd, extern int dynevent_arg_add(struct dynevent_cmd *cmd,
struct dynevent_arg *arg); struct dynevent_arg *arg,
dynevent_check_arg_fn_t check_arg);
struct dynevent_arg_pair { struct dynevent_arg_pair {
const char *lhs; const char *lhs;
const char *rhs; const char *rhs;
char operator; /* e.g. '=' or nothing */ char operator; /* e.g. '=' or nothing */
char separator; /* e.g. ';', ',', or nothing */ char separator; /* e.g. ';', ',', or nothing */
dynevent_check_arg_fn_t check_arg;
}; };
extern void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair, extern void dynevent_arg_pair_init(struct dynevent_arg_pair *arg_pair,
dynevent_check_arg_fn_t check_arg,
char operator, char separator); char operator, char separator);
extern int dynevent_arg_pair_add(struct dynevent_cmd *cmd, extern int dynevent_arg_pair_add(struct dynevent_cmd *cmd,
struct dynevent_arg_pair *arg_pair); struct dynevent_arg_pair *arg_pair,
dynevent_check_arg_fn_t check_arg);
extern int dynevent_str_add(struct dynevent_cmd *cmd, const char *str); extern int dynevent_str_add(struct dynevent_cmd *cmd, const char *str);
#endif #endif
...@@ -1334,12 +1334,12 @@ int synth_event_add_field(struct dynevent_cmd *cmd, const char *type, ...@@ -1334,12 +1334,12 @@ int synth_event_add_field(struct dynevent_cmd *cmd, const char *type,
if (!type || !name) if (!type || !name)
return -EINVAL; return -EINVAL;
dynevent_arg_pair_init(&arg_pair, synth_event_check_arg_fn, 0, ';'); dynevent_arg_pair_init(&arg_pair, 0, ';');
arg_pair.lhs = type; arg_pair.lhs = type;
arg_pair.rhs = name; arg_pair.rhs = name;
ret = dynevent_arg_pair_add(cmd, &arg_pair); ret = dynevent_arg_pair_add(cmd, &arg_pair, synth_event_check_arg_fn);
if (ret) if (ret)
return ret; return ret;
...@@ -1377,11 +1377,11 @@ int synth_event_add_field_str(struct dynevent_cmd *cmd, const char *type_name) ...@@ -1377,11 +1377,11 @@ int synth_event_add_field_str(struct dynevent_cmd *cmd, const char *type_name)
if (!type_name) if (!type_name)
return -EINVAL; return -EINVAL;
dynevent_arg_init(&arg, NULL, ';'); dynevent_arg_init(&arg, ';');
arg.str = type_name; arg.str = type_name;
ret = dynevent_arg_add(cmd, &arg); ret = dynevent_arg_add(cmd, &arg, NULL);
if (ret) if (ret)
return ret; return ret;
...@@ -1472,9 +1472,9 @@ int __synth_event_gen_cmd_start(struct dynevent_cmd *cmd, const char *name, ...@@ -1472,9 +1472,9 @@ int __synth_event_gen_cmd_start(struct dynevent_cmd *cmd, const char *name,
if (cmd->type != DYNEVENT_TYPE_SYNTH) if (cmd->type != DYNEVENT_TYPE_SYNTH)
return -EINVAL; return -EINVAL;
dynevent_arg_init(&arg, NULL, 0); dynevent_arg_init(&arg, 0);
arg.str = name; arg.str = name;
ret = dynevent_arg_add(cmd, &arg); ret = dynevent_arg_add(cmd, &arg, NULL);
if (ret) if (ret)
return ret; return ret;
...@@ -1546,9 +1546,9 @@ int synth_event_gen_cmd_array_start(struct dynevent_cmd *cmd, const char *name, ...@@ -1546,9 +1546,9 @@ int synth_event_gen_cmd_array_start(struct dynevent_cmd *cmd, const char *name,
if (n_fields > SYNTH_FIELDS_MAX) if (n_fields > SYNTH_FIELDS_MAX)
return -EINVAL; return -EINVAL;
dynevent_arg_init(&arg, NULL, 0); dynevent_arg_init(&arg, 0);
arg.str = name; arg.str = name;
ret = dynevent_arg_add(cmd, &arg); ret = dynevent_arg_add(cmd, &arg, NULL);
if (ret) if (ret)
return ret; return ret;
......
...@@ -962,9 +962,9 @@ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe, ...@@ -962,9 +962,9 @@ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe,
if (ret) if (ret)
return ret; return ret;
dynevent_arg_init(&arg, NULL, 0); dynevent_arg_init(&arg, 0);
arg.str = loc; arg.str = loc;
ret = dynevent_arg_add(cmd, &arg); ret = dynevent_arg_add(cmd, &arg, NULL);
if (ret) if (ret)
return ret; return ret;
...@@ -982,7 +982,7 @@ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe, ...@@ -982,7 +982,7 @@ int __kprobe_event_gen_cmd_start(struct dynevent_cmd *cmd, bool kretprobe,
} }
arg.str = field; arg.str = field;
ret = dynevent_arg_add(cmd, &arg); ret = dynevent_arg_add(cmd, &arg, NULL);
if (ret) if (ret)
break; break;
} }
...@@ -1017,7 +1017,7 @@ int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...) ...@@ -1017,7 +1017,7 @@ int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...)
if (cmd->type != DYNEVENT_TYPE_KPROBE) if (cmd->type != DYNEVENT_TYPE_KPROBE)
return -EINVAL; return -EINVAL;
dynevent_arg_init(&arg, NULL, 0); dynevent_arg_init(&arg, 0);
va_start(args, cmd); va_start(args, cmd);
for (;;) { for (;;) {
...@@ -1033,7 +1033,7 @@ int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...) ...@@ -1033,7 +1033,7 @@ int __kprobe_event_add_fields(struct dynevent_cmd *cmd, ...)
} }
arg.str = field; arg.str = field;
ret = dynevent_arg_add(cmd, &arg); ret = dynevent_arg_add(cmd, &arg, NULL);
if (ret) if (ret)
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment