Skip to content
Advertisement

Writing into a device file prints “Invalid argument”

I am currently working on a device driver where I want to write a sentence to that driver and display it in the kernel. Reading an internal buffer and calling the driver with cat works perfectly fine. However, if I try to write to the device driver it returns the following message: enter image description here

I have the following code for my device driver. I can’t seem to find where I went wrong in my write function…

JavaScript

Advertisement

Answer

Note that redirection >/dev/my-driver is done by the shell under the current user before sudo is invoked. EINVAL from write means fd is attached to an object which is unsuitable for writing.

It is not clear whether hello is a file or a string. cat expects it to be a file.

To write string hello into your device try:

JavaScript

To write file hello into your device try:

JavaScript
Advertisement