[英]error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types] .read = dev_read, Linux
[英]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的形式傳遞,無論用戶是將其作為整數還是指針給出。
另外, 在函數體中聲明一個與其中一個參數同名的變量是錯誤的。 請為unsigned long arg[3];
選擇另一個名稱unsigned long arg[3];
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.