]> Git Repo - J-linux.git/commitdiff
tracing histograms: Simplify parse_actions() function
authorSteven Rostedt (Google) <[email protected]>
Mon, 8 Jan 2024 01:32:58 +0000 (20:32 -0500)
committerSteven Rostedt (Google) <[email protected]>
Mon, 8 Jan 2024 18:24:56 +0000 (13:24 -0500)
The parse_actions() function uses 'len = str_has_prefix()' to test which
action is in the string being parsed. But then it goes and repeats the
logic for each different action. This logic can be simplified and
duplicate code can be removed as 'len' contains the length of the found
prefix which should be used for all actions.

Link: https://lore.kernel.org/all/[email protected]/
Link: https://lore.kernel.org/linux-trace-kernel/[email protected]
Cc: Masami Hiramatsu <[email protected]>
Cc: Mathieu Desnoyers <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Tom Zanussi <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
kernel/trace/trace_events_hist.c

index 5ecf3c8bde205f360e880b608b11abcddb689a70..6ece1308d36a02dec5af3ca3cebdb9d6b427aac7 100644 (file)
@@ -4805,36 +4805,35 @@ static int parse_actions(struct hist_trigger_data *hist_data)
        int len;
 
        for (i = 0; i < hist_data->attrs->n_actions; i++) {
+               enum handler_id hid = 0;
+               char *action_str;
+
                str = hist_data->attrs->action_str[i];
 
-               if ((len = str_has_prefix(str, "onmatch("))) {
-                       char *action_str = str + len;
+               if ((len = str_has_prefix(str, "onmatch(")))
+                       hid = HANDLER_ONMATCH;
+               else if ((len = str_has_prefix(str, "onmax(")))
+                       hid = HANDLER_ONMAX;
+               else if ((len = str_has_prefix(str, "onchange(")))
+                       hid = HANDLER_ONCHANGE;
 
-                       data = onmatch_parse(tr, action_str);
-                       if (IS_ERR(data)) {
-                               ret = PTR_ERR(data);
-                               break;
-                       }
-               } else if ((len = str_has_prefix(str, "onmax("))) {
-                       char *action_str = str + len;
+               action_str = str + len;
 
-                       data = track_data_parse(hist_data, action_str,
-                                               HANDLER_ONMAX);
-                       if (IS_ERR(data)) {
-                               ret = PTR_ERR(data);
-                               break;
-                       }
-               } else if ((len = str_has_prefix(str, "onchange("))) {
-                       char *action_str = str + len;
+               switch (hid) {
+               case HANDLER_ONMATCH:
+                       data = onmatch_parse(tr, action_str);
+                       break;
+               case HANDLER_ONMAX:
+               case HANDLER_ONCHANGE:
+                       data = track_data_parse(hist_data, action_str, hid);
+                       break;
+               default:
+                       data = ERR_PTR(-EINVAL);
+                       break;
+               }
 
-                       data = track_data_parse(hist_data, action_str,
-                                               HANDLER_ONCHANGE);
-                       if (IS_ERR(data)) {
-                               ret = PTR_ERR(data);
-                               break;
-                       }
-               } else {
-                       ret = -EINVAL;
+               if (IS_ERR(data)) {
+                       ret = PTR_ERR(data);
                        break;
                }
 
This page took 0.061215 seconds and 4 git commands to generate.