-
Notifications
You must be signed in to change notification settings - Fork 349
ll_schedule.c: fix "uninitialized task_take" warning in CONFIG_TRACEV #3944
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
Conversation
Looks like no one ever uses tr_dbg()? Signed-off-by: Marc Herbert <marc.herbert@intel.com>
|
https://travis-ci.org/github/thesofproject/sof/jobs/764043292 has hit a docker rate limit, no other error. |
|
|
||
| /* rearm only if there is work to do */ | ||
| if (atomic_read(&sch->domain->total_num_tasks)) { | ||
| struct task *task_take_dbg = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this moving from the line 162 needed or we can keep it in line 162 (with NULL initialization added)? If the moving needed, so as other items like wlist/tlist/task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The moving is not required to fix the warning but it's a good opportunity. Why have variables with a wider scope than needed? More complexity, confusion and more chances to leave variables unitialized or wrongly initialized, to shadow, harder to const, easier to misuse, etc.
C99 even relaxed the obsolete requirement for variables to be at the top of the block, C is like any other more modern language now. I digress.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marc-hb the descision for variable scope at the start of the function was based on the MISRA C safety critical requirments. https://en.wikipedia.org/wiki/MISRA_C. This is needed for use in motor vehicles.
Any MISRA C complience change here would need to be done by the TSC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgirdwood I have done some research and asked my favorite MISRA expert and there does not seem to be any MISRA guideline that this PR violates. Can you be more specific?
On the contrary, there are many security guidelines that this PR helps with:
https://wiki.sei.cmu.edu/confluence/display/c/DCL19-C.+Minimize+the+scope+of+variables+and+functions
Variables and functions should be declared in the minimum scope from which all references to the identifier are still possible.
It find it relatively obvious that smaller scopes, lower uninitialized risk and (when possible) more const/immutability help with safety.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marc-hb I also like limited scope, but we made a descision to follow MISRA C (and this was our understanding at the time). This can be a topic at next TSC. Can you update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cujomalainey It's actually C99 recommended while breaking C90 per my understanding.
@marc-hb basically I agree with what you change here but as stated in my first comment, since we use C90 style in all other places the single moving of 'task_take' here looks somewhat odd to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew it broke a C standard, thanks for checking :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's actually C99 recommended while breaking C90 per my understanding
No, you're confusing:
main()
{
printf("");
int a = 0;
}with:
main()
{
printf("");
{
int a = 0;
}
}Only the former fails to compile with:
gcc -ansi -pedantic
warning: ISO C90 forbids mixing declarations and code [-Wdeclaration-after-statement]
The latter compiles just fine. Variables at the start of a block have been possible since forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the variable declarations at function level used only within the if (atomic_read(&sch->domain->total_num_tasks)) {}
Moving one declaration under to limit the scope does not help readability (it might even make it worst by implying the the variables at top are used elsewhere - they don't) and when it comes to limiting the scope it is not much effective since the only non scope thing is the call:
platform_shared_commit(sch->domain, sizeof(*sch->domain));
at the end.
I time to time prefer to declare locally in a function to limit the scope and in hope for better readability, in this case I don't see why it would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ujfalusi , that makes sense I will keep everything at the top.
|
Please use "main" as PR target. |
|
So to summarize, the recommendation to move the variable at the top of the function is:
So unless there's some other, serious reason mentioned soon I will resubmit as is to the main branch. UPDATE: will keep it at the top, thanks @ujfalusi . |
|
Re-submitted to |
Looks like no one ever uses tr_dbg()?
Signed-off-by: Marc Herbert marc.herbert@intel.com