My question is about usage and behavior of structs in Linux Kernel Space. I am writing a char device driver:
struct LEDs{
int red_l;
};
ssize_t gmem_driver_write(struct file *file, const char *buf,
size_t count, loff_t *ppos)
{
struct LEDs myled;
printk("Red is: %d \n", myled.red_l);
return 0;
}
static long my_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
{
struct LEDs myled = {};
myled.red_l = 1;
return 0;
}
If I call my_ioctl first and then write from user space, I am expecting red_l to have value 1 in struct LEDs and then I am expecting it to print inside write function. But it prints a garbage value.
My question: Since this logic works in user space, is there something different at play here ? What can be done to make it work in Linux Kernel Space ?
myledis a local variable inside the functions. Modifying them won't change anything else. Just like for non-kernel code. - Some programmer dude