linux 第1个参数时在不兼容的指针类型间转换,linux – 为什么存在不兼容的指针类型警告?...

我正在使用内核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]

据我所知,我的file_operations设置proc函数与设备函数相同.我可以读/写/ dev / MyDevice没有问题,也没有警告. proc写入函数不会发出警告,只会读取.我做错了什么?

/*****************************************************************************/

//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,是因为它对于未来的访客来说更加迂腐和明显.

解决方法:

read_proc函数的返回类型(抛出警告)与干净编译的函数不匹配.

static ssize_t dev_read(struct file *pfil, char __user *pBuf, size_t len, loff_t *p_off)

static int read_proc(struct file *pfil, char __user *pBuf, size_t len, loff_t *p_off)

ssize_t和int可以是不同的大小.你的函数的返回类型应该是ssize_t.

标签:device-driver,linux,kernel,linux-device-driver

来源: https://codeday.me/bug/20190722/1505884.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值