Simple Misc Driver - Problem with string copy to user

Lucas Tanure tanure at linux.com
Tue May 27 08:48:43 EDT 2014


Hi!

Goal, when the user do :
# head -1 /dev/miscdrv

The driver prints:  Hello World!

Steps:
# Make
# insmod misc.ko
# head -1 /dev/miscdrv

Why my driver doesn't work ?

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;
}


--
Lucas Tanure
Brazil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140527/87c40ed5/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 599 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140527/87c40ed5/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: misc.c
Type: text/x-csrc
Size: 1288 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140527/87c40ed5/attachment-0001.bin 


More information about the Kernelnewbies mailing list