On Friday 10 September 2010 18:07:03 Daniel Baluta wrote: > On Fri, Sep 10, 2010 at 6:51 PM, fabio de francesco <fabio@xxxxxxxxxxx> wrote: > > Hi all, > > > > I have modified a simple character device driver as an exercise from the > > Cooperstein's Linux Device Drivers book. > > > > It seems to work fine except that when I "cat /dev/mycdrv" it provides > > garbage. > > > > This is a trimmed down version of the code: > > > > [skipped] > > > > static ssize_t > > mycdrv_read (struct file *file, char __user * buf, size_t lbuf, loff_t * > > ppos) { > > int nbytes, maxbytes, bytes_to_do; > > maxbytes = KBUF_SIZE - *ppos; > > bytes_to_do = lbuf <= maxbytes ? lbuf : maxbytes; > > nbytes = lbuf - copy_to_user (buf, kbuf + *ppos, bytes_to_do); > > *ppos += nbytes; > > printk (KERN_INFO "\n READING function, nbytes=%d, pos=%d\n", nbytes, > > (int)*ppos); > > Can you post the output of this line? Sep 10 18:14:50 host11 kernel: READING function, nbytes=32768, pos=32768 Sep 10 18:14:50 host11 kernel: Sep 10 18:14:50 host11 kernel: READING function, nbytes=32768, pos=65536 Sep 10 18:14:50 host11 kernel: Sep 10 18:14:50 host11 kernel: READING function, nbytes=32768, pos=98304 Sep 10 18:14:50 host11 kernel: Sep 10 18:14:50 host11 kernel: READING function, nbytes=32768, pos=131072 It goes on for tens of lines... I can't understand. > > return nbytes; > > } > > > > [skipped] > > > > Please, could someone explain why the readings of the device return > > garbage data instead of NULL characters as I have set with memset()? -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ