Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASoC: SOF: Fix skipping empty trace filters #2516

Merged

Conversation

ktrzcinx
Copy link
Member

After parsing last entry in trace_filter_parse() function,
for line ended with new line character trace_filter_parse_entry()
will be called and "\n" will be passed as argument to this function.
To skip all possible types of whitechars (which could be introduced
during manual filters setup) sscanf() function is used.

Signed-off-by: Karol Trzcinski [email protected]

Issue: thesofproject/sof#3530

@ktrzcinx ktrzcinx force-pushed the logger-filtering-fix-n branch 2 times, most recently from 44cb561 to e501c04 Compare October 20, 2020 20:41
Copy link

@xiulipan xiulipan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the idea to ignore empty content. But I could not understand what the trick is used here, could you add more comments about how this work?

sound/soc/sof/trace.c Show resolved Hide resolved
After parsing last entry in trace_filter_parse() function,
for line ended with new line character trace_filter_parse_entry()
will be called and "\n" will be passed as argument to this function.
To skip all possible types of whitechars (which could be introduced
during manual filters setup) sscanf() function is used.
Space in sscanf() formatter is responsible for whitespaces consumption,
%n writes number of characters (whitespaces in this case) read by sscanf().
When input string consist only of whitespaces (read == len), then just
skip this content without error notification.

Signed-off-by: Karol Trzcinski <[email protected]>
@ktrzcinx ktrzcinx force-pushed the logger-filtering-fix-n branch from e501c04 to c0bfcbb Compare October 21, 2020 06:28
@ktrzcinx ktrzcinx requested a review from xiulipan October 21, 2020 06:40
Copy link

@lyakh lyakh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, as long as this works... :-)

return 0;
sscanf(line, " %n", &read);
if (read == len)
return len;

ret = sscanf(line, " %d %x %d %d %n", &log_level, &uuid_id, &pipe_id, &comp_id, &read);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktrzcinx Hmm, the sscanf just to read whitespace seems a bit odd. How about if we consume the linefeed in the existing sscanf calll on L51. Would this work?

Copy link
Member Author

@ktrzcinx ktrzcinx Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sscanf just to read whitespace

rather to check if input string consist only from whitespaces or is empty one, so its eg one of "\0", "\n\0", " \0", " \n\0".

seems a bit odd

I think it shortest and reliable solution as long as reader are familiar with scanf() format string. I didn't use any hack here, it's just standard function usage.

How about if we consume the linefeed in the existing sscanf calll on L51. Would this work?

There already is linefeed consumer in the existing sscanf calll on L51 and it doesn't work in all situations 😄. The case here is parsing last entry of strsep("0 0 0 0;\n", ";"), it will be "\n", so scanning 4 numbers fails for it. Without this fix it works for strsep("0 0 0 0;", ";"), because then last entry is "\0" iirc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ktrzcinx Thanks. I agree this is probably the cleanest, but I'm still not entirely convinced having this sort of relaxed parsing in kernel space is the right place. I mean "0 0 0 0;\n" is an invalid input in the end. Why have extra code in kernel for something user-space can easily just get right.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change we have some inconsistence - "0 0 0 0;\n" returns parsing error but "0 0 0 0\n" passes, after change it will be consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the point @ktrzcinx about detecting a line with whitespaces only, but I don't get how this change helps you detect
"0 0 0 0;\n" from "0 0 0 0\n"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart "0 0 0 0;\n" will be split to "0 0 0 0\0" (parsed with success) and "\n" (rising parse error without this patch). Such and situation doesn't happen for "0 0 0 0\n", because there's no spiting char, and this text will be consumed at once.

Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ktrzcinx . The filter specs may be handwritten, so maybe this is worth it. I'd still appreciate feedback from others before we merge.

@kv2019i
Copy link
Collaborator

kv2019i commented Nov 3, 2020

@xiulipan (you stilll have changes-requested pending)?

@kv2019i kv2019i merged commit ace6d6c into thesofproject:topic/sof-dev Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants