-
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
Uh oh!
There was an error while loading. Please reload this page.
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
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.
No, you're confusing:
with:
Only the former fails to compile with:
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.