-
Notifications
You must be signed in to change notification settings - Fork 1.4k
include/uk/event: Make handler and raise return values type-safe #1687
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: staging
Are you sure you want to change the base?
include/uk/event: Make handler and raise return values type-safe #1687
Conversation
mogasergiu
left a comment
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, just a couple of missed type updated I think
472282d to
6f779b3
Compare
uk_event handlers often omit using one of the designated macro values, and return an integer instead. This is particularly problematic when returning zero to signify that the event was handled, as event.h assigns zero to UK_EVENT_NOT_HANDLED. Convert uk_event handler return values to enum to catch such errors at compile-time. Introduce a UK_EVENT_ERROR state and an additional parameter in the handler prototype that handlers must populate before returning UK_EVENT_ERROR. Checkpatch-ignore: MACRO_ARG_REUSE Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Checkpatch-Ignore: LONG_LINE Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Signed-off-by: Michalis Pappas <[email protected]>
Update event handlers and event raising calls to use the new enum return type and error parameter. Checkpatch-ignore: MACRO_ARG_REUSE Checkpatch-ignore: MACRO_ARG_PRECEDENCE Checkpatch-ignore: UNNECESSARY_PARENTHESES Signed-off-by: Michalis Pappas <[email protected]>
6f779b3 to
b37f342
Compare
mogasergiu
left a comment
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.
For me it feels viscerally wrong whenever I end up having to add functions with lateral effect and can't help but wonder if there is a better way. But, yeah, for now I can't see a better way than this that would fit all requirements either...
So I guess we can stick with this or... maybe leave it for later and brainstorm some more. I would approve either way.
| * else if (!rc) | ||
| * uk_pr_err("myevent not handled!\n"); | ||
| * rc = uk_raise_event(myevent, &myevent_data, &error); | ||
| * if (unlikely(rc < UK_EVENT_ERROR)) |
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 would drop the unlikely from the documentation and leave as it was. Also the type of rc might need to be updated.
| { | ||
| const uk_event_handler_t *itr; | ||
| int rc; | ||
| int ret = UK_EVENT_NOT_HANDLED; |
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 think ret should have been enum?
| return UK_EVENT_HANDLED; | ||
|
|
||
| if (rc == UK_EVENT_HANDLED_CONT) | ||
| if (ret == UK_EVENT_HANDLED_CONT) |
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 think this if statement is no longer necessary
| #define uk_raise_event(event, data, error) \ | ||
| ({ _UK_EVT_IMPORT_EVENT(event); \ | ||
| uk_raise_event_ptr(UK_EVENT_PTR(event), data); }) | ||
| uk_raise_event_ptr(UK_EVENT_PTR(event), data, error); }) |
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.
Maybe we should enclose data and error between paranthesis? Also don't forget to now add the error argument documentation to uk_raise_event as well.
| int pprocess_raise_execve_event(struct posix_process_execve_event_data *data) | ||
| enum uk_event_status | ||
| pprocess_raise_execve_event(struct posix_process_execve_event_data *event_data, | ||
| int event_error) |
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 think you meant int *event_error? (You do have it in the header definition :D)
| #if __INTERRUPTSAFE__ && CONFIG_LIBUKBOOT_SHUTDOWNREQ_HANDLER | ||
| static int shutdown_req_handler(void *data) | ||
| static | ||
| enum uk_event_status shutdown_req_handler(void *data, int *error __unused) |
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 think you can update error to return value of rc.
| #include <uk/print.h> | ||
|
|
||
| static int vmem_arch_pagefault(void *data) | ||
| static enum uk_event_status vmem_arch_pagefault(void *data, int *error __unused) |
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.
Ditto (for x86 too)
uk_eventhandlers often omit using one of the designated macro values, and return an integer instead. This is particularly problematic when returning zero to signify that the event was handled, asevent.hassigns zero toUK_EVENT_NOT_HANDLED.Convert
uk_eventhandler return values to enum to catch such errors at compile-time. Introduce aUK_EVENT_ERRORstate and an additional parameter in the handler prototype that handlers must populate before returningUK_EVENT_ERROR.Prerequisite checklist
checkpatch.ukon your commit series before opening this PR;Base target
Additional configuration
Description of changes