Skip to content
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't read from CAN dev using internal OS interface #111

Closed
lukegluke opened this issue Jan 16, 2020 · 4 comments
Closed

Can't read from CAN dev using internal OS interface #111

lukegluke opened this issue Jan 16, 2020 · 4 comments

Comments

@lukegluke
Copy link
Contributor

In drivers/can/can.c @walmis added support of multiple readers of the same port with 7d112f5, but in current state it breaks ability to work with CAN using internal OS interface.

Issue in current logic:

  1. file_open() with reference to user-provided file structure *filep;
  2. file_open() calls nx_vopen() that allocate a file structure for inode and call can_open() with reference to this file structure.
  3. In can_open() https://github.com/apache/incubator-nuttx/blob/177c037aa9f0536c4d9baf25cf060c0633957b94/drivers/can/can.c#L475 can_reader is added to the list with the reference to file structure (from point 2). And returned
  4. nx_vopen returns file descriptor
  5. and that file descriptor is detached in file_open() if fact by duplicate the 'struct file' content into the user-provided file structure.
  6. then during reading in can_read() https://github.com/apache/incubator-nuttx/blob/177c037aa9f0536c4d9baf25cf060c0633957b94/drivers/can/can.c#L635 appropriate reader is chosen from list by filep value. But in this point filep argument of can_read() is the pointer to user-provided file structure, but the appropriate can_reader has pointer to another file structure (from point 2)! So can_read will not find any reader and fails this debug assertion if enabled: https://github.com/apache/incubator-nuttx/blob/177c037aa9f0536c4d9baf25cf060c0633957b94/drivers/can/can.c#L642

I'm not really good in all this things with inodes, files and descriptors, but as for me the solution will be to distinct readers in can driver not by filep itself, but by for example f_priv field of it.
Could we store value of filep in f_priv on can opening and use it in can_read? What happens with file structure (from point 2) with detaching, is there a chance this pointer be reused before file will be closed by user-provided reference?

p.s. maybe this issue also related to other devices, for instance serial

@lukegluke lukegluke changed the title Can't work with CAN dev using internal OS interface Can't read from CAN dev using internal OS interface Jan 16, 2020
lukegluke added a commit to lukegluke/incubator-nuttx that referenced this issue Jan 16, 2020
Store internal file pointer in f_priv and use it then to distinct readers 
issue apache#111
@lukegluke
Copy link
Contributor Author

I fix it as I suggested. It works now. But there is still important question about possibility that new reader can be added with file pointer that is already in readers list.

@lukegluke
Copy link
Contributor Author

Move to more simple solution: just storing pointer to specific reader in filep->f_priv

patacongo pushed a commit that referenced this issue Jan 17, 2020
…terface (#118)

* Fix CAN driver to work with internal OS interfaces.  Store internal file pointer in f_priv and use it then to distinct readers (See issue #111)
* Store reader pointer in f_priv instead of filep
* Don't need in filep in can_reader_s
patacongo pushed a commit that referenced this issue Jan 17, 2020
…nterface (#118)

Author: Gregory Nutt <[email protected]>

    Run all .c and .h files in last PR through tools/nxstyle and correct all coding standard complaints.

Author: Oleg <[email protected]>

    * Fix CAN driver to work with internal OS interfaces.  Store internal file pointer in f_priv and use it then to distinct readers (See issue #111)
    * Store reader pointer in f_priv instead of filep
    * Don't need in filep in can_reader_s
@patacongo
Copy link
Contributor

I believe that merging PR118 closes this issue. Correct?

@lukegluke
Copy link
Contributor Author

Yes. Thanks!

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

No branches or pull requests

2 participants