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

ioctl_readwrite_ptr missing #2098

Closed
Christiaan676 opened this issue Aug 15, 2023 · 3 comments
Closed

ioctl_readwrite_ptr missing #2098

Christiaan676 opened this issue Aug 15, 2023 · 3 comments

Comments

@Christiaan676
Copy link

Christiaan676 commented Aug 15, 2023

Fairly new with LKM's but I have a IOCtl function that is defined as _IORW(MAGIC, 1, struct mystruct *) and the LKM uses the pointer to read and to write to a field in the struct. According to [1] that means the function should be declared are RW.

_IO/_IOR/_IOW/_IOWR
The macro name specifies how the argument will be used. Â It may be a
pointer to data to be passed into the kernel (_IOW), out of the kernel
(_IOR), or both (_IOWR). Â _IO can indicate either commands with no
argument or those passing an integer value instead of a pointer.
It is recommended to only use _IO for commands without arguments,
and use pointers for passing data.

Looking at the issues, this is mentioned a couple of times and people give an implementation but it was never added. Is there any reason its not implemented? Considering the description in [1] I would expect all three variants:

  • ioctl_write_ptr
  • ioctl_read_ptr
  • ioctl_readwrite_ptr

but currently only ioctl_write_ptr is implemented.

Merge requests that add's it: #965
Question with someone offering a implementation: #1386 (comment)

[1] https://www.kernel.org/doc/Documentation/core-api/ioctl.rst

@Christiaan676
Copy link
Author

Ok took some time. But think I under stand it now.

The read and readwrite functions always use a pointer, as else there is no other way to get a value back from the kernal driver. For the write this is different, as you can write a value like char/int/long as a direct parameters, or as a pointer to the value. So the distinction between the two is needed there.

@asomers
Copy link
Member

asomers commented Aug 19, 2023

So is your problem solved, or is there still something else that you need?

@Christiaan676
Copy link
Author

@asomers My problem is fixed. Was planning on reading the documentation again to see if it could use an update to explain the situation with the write and write_ptr a bit better. But haven't had time for that....

Wat thrown me of is that the write_ptr function suggest that there should be a pointer variant for all the other types as well. But this is not the case, as they already use a pointer. (Maybe it would have been better to make the write variant accept a pointer, and to create a write_value version to keep the write macro in line with the other macro's).

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