簡體   English   中英

從Linux內核4.8.0-53-通用Linux Mint 64位中的IOCTL函數的不兼容指針初始化錯誤

[英]Error initialization from incompatible pointer of IOCTL function in Linux kernel 4.8.0-53-generic Linux Mint 64 bit

使用Ioctl命令編寫char設備模塊時出錯。

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

注意:請忽略我的所有print_k

請幫我解決這個問題。 謝謝你們所有人。

這是我的代碼:

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, 
};

函數原型中的第三個參數unsigned long arg[b]是可疑的。 它應該是簡單的unsigned long arg即使它應該是一個指針。 可以很容易地將它轉換為的函數體內感興趣的類型。

..可選的arg參數以無符號long的形式傳遞,無論用戶是將其作為整數還是指針給出。

Linux設備驅動程序3,第6章,第1節

另外, 函數體中聲明一個與其中一個參數同名的變量是錯誤的。 請為unsigned long arg[3];選擇另一個名稱unsigned long arg[3];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM