【发布时间】:2014-12-28 00:35:20
【问题描述】:
我正在使用内核 3.13.0 编写 Linux 设备驱动程序,但我很困惑为什么会收到此警告。
warning: initialization from incompatible pointer type [enabled by default]
.read = read_proc,
^
warning: (near initialization for ‘proc_fops.read’) [enabled by default]
据我所知,proc 函数的 file_operations 设置与设备函数相同。我可以毫无问题地读取/写入 /dev/MyDevice 并且没有警告。 proc write 函数不会发出警告,只会发出警告。我做错了什么?
/*****************************************************************************/
//DEVICE OPERATIONS
/*****************************************************************************/
static ssize_t dev_read(struct file *pfil, char __user *pBuf, size_t
len, loff_t *p_off)
{
//Not relevant to this question
}
static ssize_t dev_write(struct file *pfil, const char __user *pBuf,
size_t len, loff_t *p_off)
{
//Not relevant to this question
}
static struct file_operations dev_fops =
{ //None of these cause a warning but the code is identical the proc code below
.owner = THIS_MODULE,
.read = dev_read,
.write = dev_write
};
/*****************************************************************************/
//PROCESS OPERATIONS
/*****************************************************************************/
static int read_proc(struct file *pfil, char __user *pBuf, size_t
len, loff_t *p_off)
{
//Not relevant to this question
}
static ssize_t write_proc(struct file *pfil, const char __user *pBuf,
size_t len, loff_t *p_off)
{
//Not relevant to this question
}
struct file_operations proc_fops =
{
.owner = THIS_MODULE,
.write = write_proc,
.read = read_proc, //This line causes the warning.
};
编辑:所以答案是我是个白痴,因为我没有看到“int”与“ssize_t”。谢谢大家! Codenheim 和 Andrew Medico 几乎同时给出了正确答案,但我选择了 Medico's,因为它对未来的访客来说更加迂腐和明显。
【问题讨论】:
标签: linux kernel linux-device-driver device-driver