Hi,
I wrote a character device driver for an Embedded Linux build (Kernel Revision 2.6.17.1) running on ARM9. In the module's "read()" function, I'm returning the number of bytes that were copied into the user buffer. I saw some module code samples online and in most cases the "read()" function is returning the number of bytes read.
The very strange behavior I saw in my case was, if I use a variable to return the value from the module's "read()" function, the user application reading from the module always saw "0".
For instance:
Code:
static int zlg7289_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
int bytes = 0;
// Read bytes, copy to user space using "put_user()"
...
...
...
// Added this for debugging
if(bytes) printk("Bytes: %d\n", bytes);
return (bytes);
}
If I use the code given above, the user application always got back "0". In case I returned a hard-coded value, it worked fine, i.e.:
Code:
.
.
.
// Any number here works fine
return (1);
Any explanation for this behavior?
Thanks!
- Shahzeb