This is my myread and mywrite function of the null driver.
#define SIZE 6
static char c[SIZE];
static ssize_t myread(struct file *file,char __user *buf,size_t len, loff_t *fops)
{
printk(KERN_INFO"My read with length %zd \n",len);
memset(buf,0,SIZE);
//return is status i.e., 0.
if(copy_to_user(buf,c,SIZE) != 0)
return -EFAULT;
else if (*fops > 0)
return 0;
else
*fops += SIZE;
return SIZE;
}
static ssize_t mywrite(struct file *file, const char __user *buf, size_t len, loff_t *fops)
{
printk(KERN_INFO "My write \n");
memset(c,0,SIZE);
if (len <= SIZE)`
{`
if(copy_from_user(c,buf,len) != 0)
return -EFAULT;
else
//number of bytes written to the kernel space is returned
return len;`
}
else
return -EFAULT;`
}
When i build the module it is throwing warning like this:
/usr/src/linux-headers-3.2.0-36-generic-pae/arch/x86/include/asm/uaccess_32.h: In function ‘mywrite’: /usr/src/linux-headers-3.2.0-36-generic-pae/arch/x86/include/asm/uaccess_32.h:211:26: warning: call to ‘copy_from_user_overflow’ declared with attribute warning: copy_from_user() buffer size is not provably correct [enabled by default]
please guide me like how to get rid of this warning. Like where am i doing mistake..
strlen(c);
? (OOPS a static ... brrr) 2) dont printf a size_t with a "%d" format. 3) what is wrong withsizeof c
instead of SIZE ? – wildplasser