Simple Misc Driver - Problem with string copy to user

Lucas Tanure tanure at linux.com
Tue May 27 09:03:47 EDT 2014


So, My misc_drv_read returns 0, and it's ok. So why the command head didn't
get the string ?

--
Lucas Tanure
+55 (19) 988176559


On Tue, May 27, 2014 at 9:59 AM, Bjørn Mork <bjorn at mork.no> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140527/58001a15/attachment.html 


More information about the Kernelnewbies mailing list