Hi all: I am writting device driver for a PCMCIA data accquistion card. Now PCMCIA part has been taken cared of. and I can read the data from register in the driver code. However when I implement the *_read() function and use copy_to_user() to copy the data to user space. I can't actually get the data from my user program. my code looks like this: driver code:
daq_read(struct inode *inode, struct file *file,
char *buf, unsigned long count)
{
unsigned short *value;
value = kmalloc(sizeof(unsigned short), GFP_KERNEL);
/* device specific code */
if (__copy_to_user(buf, value, count))
{
printk("error: __copy_to_user\n");
return -EFAULT ;
}
....
}
test user code:
int main()
{
unsgined short *buff;
buff = malloc(sizeof(unsigned short));
fd = open("/dev/daq", O_RDONLY);
read(fd, (char *)buff, sizeof(unsigned short));
printf("buff=0x%x\n", *buff);
return 0;
}
when I load the driver and try to run the test program. I always trigger that error "error: __copy_to_user", looks like the system call failed. I'v ever tried copy_to_user(), but it didn't work. Anybody can give me some suggestion and ideas? I would highly appreciate it!! THank you ! lei
|