Linux 内核 4.8.0-53-generic 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
命令编写字符设备模块时出错。
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
即使它应该是一个指针。在函数体中将其转换为感兴趣的类型很容易。
..the optional arg argument is passed in the form of an unsigned long, regardless of whether it was given by the user as an integer or a pointer.
( Linux Device Drivers 3, Chapter 6, Section 1 )
此外,在函数体中声明一个与参数之一同名的变量是错误的。请为 unsigned long arg[3];
选择另一个名称。
我在使用 Ioctl
命令编写字符设备模块时出错。
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
即使它应该是一个指针。在函数体中将其转换为感兴趣的类型很容易。
..the optional arg argument is passed in the form of an unsigned long, regardless of whether it was given by the user as an integer or a pointer.
( Linux Device Drivers 3, Chapter 6, Section 1 )
此外,在函数体中声明一个与参数之一同名的变量是错误的。请为 unsigned long arg[3];
选择另一个名称。