07-27-2023, 12:05 PM
I am trying to copy a value from user space to kernel space with the function:
static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t *off)
{
unsigned long copy=0;
int desp=0;
copy = copy_from_user(&desp, &len, 4);
printk(KERN_ALERT "copy: %lx\n", copy);
printk(KERN_ALERT "desp: %d\n", desp);
}
where "len" is the variable that exists in the user space, and I want to copy it to "desp" in the kernel space
the function call I make from the user space is (write is device_write according to file_operations struct):
write (fd,buffer,8, &off);
when I print the value that should be stored in "desp" is always 0 (should be 8).
What is the problem in my code? I've been seeing several examples and I implemented many variations but none works.
static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t *off)
{
unsigned long copy=0;
int desp=0;
copy = copy_from_user(&desp, &len, 4);
printk(KERN_ALERT "copy: %lx\n", copy);
printk(KERN_ALERT "desp: %d\n", desp);
}
where "len" is the variable that exists in the user space, and I want to copy it to "desp" in the kernel space
the function call I make from the user space is (write is device_write according to file_operations struct):
write (fd,buffer,8, &off);
when I print the value that should be stored in "desp" is always 0 (should be 8).
What is the problem in my code? I've been seeing several examples and I implemented many variations but none works.