-
Notifications
You must be signed in to change notification settings - Fork 7.7k
kernel: fix error propagation for device deferred initialization #91221
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
base: main
Are you sure you want to change the base?
Conversation
@andyross or @peter-mitsis: A relative straightforward PR, but no urgency. Thanks! |
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.
Question on the initialized flag semantics. Also pedantry: you want to introduce the test after the fix in the commit sequence, otherwise the PR introduces a bisection failure.
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.
A couple of comments--hopefully they are useful.
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.
Sorry - I started a review of this quite a while ago but didn't finish. Please see my comments as well.
For bugs, introducing the test first, then the fix, has the advantage to give an audit trail. (fail before the fix, pass after). This can be useful for certification process/audit (IEC 61508 and the like). If that's a problem from a git/zephyr way of working, happy to reorder... I have anyway some reviews findings from Cris to include for the test 😉 |
0cd51af
to
fd0e524
Compare
Right, but it breaks "git bisect" by introducing an unrelated/phantom failure in the tree, which is an actual software tool we need to run with some regularity. Human audits can always make do with an extra patch reversion or whatever. Please reorder :) |
@andyross: I have already re-ordered the commits in the atest push: the commit for the test comes now after the commit for the code change. |
@cfriedt please re-reivew |
|
fd0e524
to
04e456c
Compare
Chris's suggestion to use CLAMP() has been implemented. |
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.
LGTM - the only thing I didn't notice earlier is that <zephyr/sys/util.h>
isn't explicitly included, but if it builds, it builds.
Correct. |
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.
Sorry, some nits on the error code handling that rise just to my -1 threshold. The preprocessor one is the only fatal one though, I'm willing to be convinced on the translation code for the number.
This fix makes sure that do_device_init() returns a negative value if the device's initialization failed. Previously, it mistakely returned +errno instead of -errno. This oversight happened during the refactoring of z_sys_init_run_level() to support deferred initialization, from which most of do_device_init() code derives. The rc value computed and stored in dev->state->init_res is the POSITIVE value of the resulting errno. Returning rc therefore breaks the convention of a negative value to signal failure. Signed-off-by: Loic Domaigne <tech@domaigne.com>
These tests verify the expected returned value and device state for error cases (-EALREADY, -errno) conform to the device_init() documentation. Signed-off-by: Loic Domaigne <tech@domaigne.com>
I found a radical solution that minimizes the code change, and should address all review comments discussed so far. I hope that works for you. |
04e456c
to
d7e8792
Compare
|
This fix propagates the failure code returned from the device initialization function to the application when deferred initialization is used. Previously,
device_init()
mistakenly returnederrno
instead of-errno
.A test has been added to test.kernel.device to verify the changes (fail before the fix, pass after).
Fix: #91095