Simple Misc Driver - Problem with string copy to user

Bjørn Mork bjorn at mork.no
Tue May 27 08:59:56 EDT 2014


Lucas Tanure <tanure at linux.com> writes:

>> What is worg with my read operation?
>
> static ssize_t
> misc_drv_read(struct file *filp, char __user * buf, size_t count, loff_t *
> offp){
>     int nbytes;
> char * string = "hello World";
> nbytes = copy_to_user(buf, string, 12);
>  return nbytes;
> }

copy_to_user returns the number of bytes which could *not* be copied.
So it will return 0 on success, making your read return 0.


Bjørn



More information about the Kernelnewbies mailing list