From: Kyle S. <ksc...@fo...> - 2008-03-07 22:17:12
|
I'm writing a driver to run on the gumstix and I'm running into problems copying data from kernel space to user space. I can successfully print out the correct data in the driver using printk, and then read it back from the user space buffer and print it out again correctly. My problem is that I cannot see the correct data from user space. Below I show the short snippets of driver code, unit test code, and unit test output. Any help is appreciated. Here's my test "read" implementation for my char device driver that only copies 4 bytes: ssize_t i2s_read (struct file *filep, char __user *buff, size_t count, loff_t *offp) { char bufCheck[4]; unsigned int sample = SADR; printk(KERN_NOTICE "i2s: entering i2s_read!\n"); printk(KERN_NOTICE "i2s: read %X from SADR\n", sample); if( copy_to_user(buff, &sample, 4) ) { printk(KERN_ERR "i2s: error copying data to userspace\n"); return -EFAULT; } else { printk(KERN_NOTICE "i2s: data copied to userspace!\n"); if( copy_from_user(bufCheck, buff, 4) ) { printk(KERN_ERR "i2s: error copying data from userspace\n"); return -EFAULT; } else { printk(KERN_NOTICE "i2s: data copied back from userspace."); printk(" Data is: %X\n", *(unsigned int *)bufCheck); } } printk(KERN_NOTICE "i2s: leaving i2s_read!\n"); return 0; } Here's my user space unit tester: unsigned int data = 0; FILE *adc = fopen("/dev/i2s0", "r"); if(!adc) { printf("run 'mknod /dev/i2s0 c 50 0' on gumstix\n"); return 1; } fread(&data, 4, 1, adc); printf("data = %X\n", data); And here's the unit test output: i2s: entering i2s_read! i2s: read 64BCF212 from SADR i2s: data copied to userspace! i2s: data copied back from userspace. Data is: 64BCF212 i2s: leaving i2s_read! data = 0 Anyone see something out of place? Thanks! -- Kyle |