Re: [PATCH] tracing histograms: Simplify parse_actions() function
From: Andy Shevchenko
Date: Mon Jan 08 2024 - 03:33:01 EST
On Mon, Jan 8, 2024 at 3:31 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>
>
> 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/20240107112044.6702cb66@xxxxxxxxxxxxxxxxxx/
>
> Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
If you want Link to be formally a tag, you should drop the following
blank line.
> + 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;
The repeating check for ( might be moved out as well after this like
if (str[len] != '(') {
// not sure if you need data to be assigned here as well
ret = -EINVAL;
...
}
--
With Best Regards,
Andy Shevchenko