-
Notifications
You must be signed in to change notification settings - Fork 2k
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
can: add proper checks for ifnum validity #14909
Conversation
That The other checks all make sense. ACK on those. Possibly unrelated, but I tried to test the changes on native (before trying it on a nucleo board), and I wasn't able to get it working. When adding It's entirely possible that I'm doing something wrong here (or there's something wrong with my system), but can you confirm that this test should be able to run on native without any changes? (And if yes: any clue what I'm doing wrong here? Haven't really used conn_can myself yet) |
@wosym thanks for the review. I removed the For the native issue. It seems master was also broken (probably for quite some time, btw). The native CAN driver was not properly ported to the |
The new commits you added look a lot scarier than the initial one. Anyways, I tested the changes by running the candev app (before and after this patch), and it seems to function the same. |
IMO, it should not impact your work on #13624 since mcp2515 is not a periph, but an external driver. |
I tested the conn_can with this PR today. two remarks: On native, On nucleo-f207zg it complains at compile time about not having periph_can. I assume this is because it is missing in the KConfig for that board (but I guess that is out of scope for this PR). |
Finally found some time to check.
|
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.
Code looks good to me and makes sense.
ACK
(Murdock still has some complaints though)
ee93c8c
to
3b4a10b
Compare
@vincent-d there are some issue murdock seems to have flaged out;
Header wise you have these This is just a suggestion there might be better way to layout this. You could do something like what is done for
|
@fjmolinas I tried to clean up a bit. First I renamed On the side of the headers, I modified both native and esp32 so they are done the same way stm32 did: the specific header ( Let me know if it's good enough with you. |
Looks good! lets see if murdock is happy now! |
@vincent-d this should fix the last remaining issues: diff --git a/cpu/native/include/can_params.h b/cpu/native/include/can_params.h
index 61e42117f3..8c7f37c391 100644
--- a/cpu/native/include/can_params.h
+++ b/cpu/native/include/can_params.h
@@ -29,7 +29,7 @@ extern "C" {
/**
* @brief Default parameters (device names)
*/
-static candev_params_t candev_params[] = {
+static const candev_params_t candev_params[] = {
{ .name = "can0", },
{ .name = "can1", },
};
diff --git a/sys/auto_init/can/auto_init_periph_can.c b/sys/auto_init/can/auto_init_periph_can.c
index 0c2ffb6697..8fa49fbdd1 100644
--- a/sys/auto_init/can/auto_init_periph_can.c
+++ b/sys/auto_init/can/auto_init_periph_can.c
@@ -16,6 +16,7 @@
* @}
*/
+#include "periph/can.h"
#include "can/device.h"
#include "can_params.h" On a side note what is the difference between these two headers, or more specifically I'm a bit lost regarding the header hierarchy
|
I guess this part might be refactored, at least the naming. But |
@vincent-d murdock is failing to report to status... but its all green but for static tests, please squash! |
Most functions were using asserts, but in some cases it might not be a programmatic error to pass an invalid ifnum. This makes sure the code does not crash by testing it at runtim and returning an error.
Native CAN device was not properly ported to periph_can interface. This commit fixes this by renaming all needed structures and files so auto_init_can can initialize the native device. FEATURES_PROVIDED is also updated for native.
This makes tests/candev use periph_can by default instead of old native specific driver.
5e23623
to
590f07b
Compare
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.
Untested ACK, trusting @vincent-d testing.
@fjmolinas I had tested the initial version, but after that a lot more changes were added to this PR. In any case: I must say that the code looks a lot cleaner with this change, and I think it also solves a potential future problem that had been discussed a few weeks ago. Kudos to you! :) |
Contribution description
Improve error checking of user-facing CAN APIs.
Most functions were using asserts, but in some cases it might not be a
programmatic error to pass an invalid ifnum. This makes sure the code
does not crash by testing it at runtime and returning an error.