天嵌 ARM开发社区

 找回密码
 注册
查看: 1185|回复: 1

应用程序和驱动配套函数参数类型不一致问题

[复制链接]
haffman 发表于 2013-8-15 23:34:30 | 显示全部楼层 |阅读模式
file_operations结构体中定义的函数ssize_t(*read) (struct file *, char __user *, size_t, loff_t *);
但在实际驱动定义的函数为static int xxx_read(struct file *filp, int __user *buff, size_t count, loff_t *offp)
(请注意:函数的第二个参数类型不一样,一个char,另一个int)。
在驱动xxx_read这个函数中将某一整型数据拷贝到用户空间buff中去,如下:
err = copy_to_user(buff,&values, min(sizeof(key_values), count));
上面实际编译中会出现警告如passing argument 2 of 'copy_to_user' discards qualifiers from pointer target type
warning: initialization from incompatible pointer type
忽略上面信息。。。
应用程序调用read函数,将相应的第二个参数定义为int型。。然后进行测试。。
通过printf可以查看内核驱动回传的数据。。。通过实验可以看到回传数据正确。。
如通过copy_to_user函数将0x183写入buff中,应用程序打印出来为0x183..
现有一个疑问:file_operations结构体定义的函数,其参数类型没有限制吗?
 楼主| haffman 发表于 2013-8-15 23:48:37 | 显示全部楼层
感觉gcc编译条件太宽松了,只提示警告。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-19 14:46 , Processed in 1.062500 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表