The prototype of the write function in the manual is:
ssize_t write(int fd, const void *buf, size_t count);
Therefore, you need to transfer only 3 values ββto write , namely: the file descriptor fd , buffer , where your data is located, and count bytes that you want to write.
This applies to user space. Now we turn to the function of writing to kernel space, i.e. Your device_write .
The buf argument for this function is the one that contains the data you want to write from user space, count is the length of the data sent for writing by the kernel. Thus, you should copy the data from the buf pointer, not len .
So the correct way:
char *desp; //allocate memory for this in kernel using malloc copy_from_user (desp, buff, len);
It has to be done.
source share