Initialization error from incompatible IOCTL function pointer in Linux kernel 4.8.0-53-generic Linux Mint 64 bit

I got an error while writing a char device module with a command Ioctl.

static struct file_operations my_fops =
{
    .unlocked_ioctl = my_ioctl, error is here. I can not fix this.
};

Note. Please ignore all mine print_k.

Please help me fix this. I thank you all.

Here is my code:

static long my_ioctl(struct file *f,unsigned int cm,unsigned long arg[b]) 
{  
    int re; 
    unsigned long arg[3];

    switch (cm) 
    { 
        case H_ADD:          

          arg[2] = arg[0] + arg[1];  
          print_k("Driver:Calculating is complete,Result = %d \n",arg[2]); 
        break;  
        case H_SUB: 
          print_k ("Driver: Start ...\n"); 
          arg[2] = arg[0] - arg[1];  
          print_k("Driver:Calculating is complete,Result = %d \n",arg[2]);
        break; 
        case H_MULL:  
          print_k ("Driver: Start ...\n");  
          arg[2] = arg[0] * arg[1]; 
          print_k("Driver:Calculating is complete,Result = %d \n",arg[2]); 
        break; 
        case H_DIV:  
          print_k ("Driver: Start ...\n");  
          arg[2] = arg[0] / arg[1]; 
          print_k("Driver:Calculating is complete,Result = %d \n",arg[2]); 
        break; 
        default:  
          print_k ("Driver: I don't have this operation!\n"); 
        re = -Er; 
        break; 
        }  
    return re; 
} 

static struct file_operations my_fops =
{
    .unlocked_ioctl = my_ioctl, 
};
+4
source share
1 answer

The third argument unsigned long arg[b]in the function prototype is dubious. It should be simple unsigned long arg, even if it should be a pointer. It is easy to attribute it to the type of interest within the body of the function.

.. arg unsigned long, , .

( Linux 3, 6, 1)

, , , . unsigned long arg[3];.

+2

Source: https://habr.com/ru/post/1688332/


All Articles