Skip to content

added error output for rt_rp1lib_init and rp1spi_init, now return zer…#89

Open
iforce2d wants to merge 1 commit intoscottalford75:mainfrom
iforce2d:main
Open

added error output for rt_rp1lib_init and rp1spi_init, now return zer…#89
iforce2d wants to merge 1 commit intoscottalford75:mainfrom
iforce2d:main

Conversation

@iforce2d
Copy link
Copy Markdown
Contributor

…o on failure instead of -1 (calling code interprets return value as boolean, which caused silent failures)

…o on failure instead of -1 (calling code interprets return value as boolean, which caused silent failures)
Copy link
Copy Markdown
Owner

@scottalford75 scottalford75 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, please see https://linuxcnc.org/docs/ja/html/man/man3/rtapi_app_main.3rtapi.html as int rtapi_app_main(void) should return a negative error value. Where does this be seen as a boolean and silently fail?

@iforce2d
Copy link
Copy Markdown
Contributor Author

These changes are in rt_rp1lib_init and rp1spi_init, not rtapi_app_main. The return value for these is used in rt_peripheral_init like:
Selection_598
That's what I meant by "interpreted as boolean", sorry if that wasn't clear. Any non-zero return value is interpreted as success, so returning -1 for the failure cases mean a failure is never caught. Now that I look a bit further, the same is true for rt_peripheral_init as well:
Selection_599

By "silently fail" I mean that for rt_rp1lib_init there were no error outputs for each individual sub-function that could fail, and for rp1spi_init the printf statements were unreachable code.

I should also clarify that there was no problem when running your code completely as-is on a Pi5. The reason I had problems is because I've been stealing parts of this for my own LinuxCNC component, and rearranging things a little. To make a long story short, other parts of my code were causing the rtapi_open_as_root("/dev/mem",...) in rt_rp1lib_init to fail. Without the errors being caught and no detailed feedback it took me an awful long time to figure it out, just figured this might help someone in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants