The problem: I have a pointer to struct file called flip, an int called cmd and an unsigned long called arg. The private_data field in struct file points the private_data structure is defined as follows:
typedef struct {
unsigned char key;
int read_state;
} my_private_data;
and ioctl function is defined as follows:
int my_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
switch (cmd) {
case CMD_CHANGE_KEY:
filp->private_data->key = (char)cmd;
filp->private_data->read_state = (int)arg;
break;
case CMD_SET_READ_STATE:
filp->private_data->key = (char)cmd;
filp->private_data->read_state = (int)arg;
break;
case CMD_ZERO:
kfree(buff_caesar);
break;
}
return 0;
}
However, when I try to compile the code, I get the following warning/error:
Warning: dereferencing 'void *' pointer.
Requesting for Member 'key' in something not a struct or union.
Warning: dereferencing 'void *' pointer.
Requesting for Member 'read_state' in something not a struct or union.
What can I do to fix this?
Here's the open method:
int my_open(struct inode *inode, struct file *filp)
{
int minor = MINOR(inode->i_rdev);
if(minor == ONE) {
/* Caesar*/
filp->f_op = &fops_caesar;
}
else if(minor == TWO){
/*Xor*/
filp->f_op = &fops_xor;
}
else return -ENODEV;
my_private_data* privateData = NULL;
privateData = kmalloc(sizeof(my_private_date),GFP_KERNEL);
if (privateData==NULL){
return -1;
}
filp->private_data = privateData;
return 0;
}