主题 : linux驱动模块编译问题 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 8756
精华: 0
发帖: 34
金钱: 340 两
威望: 170 点
综合积分: 68 分
注册时间: 2009-09-05
最后登录: 2010-10-11
楼主  发表于: 2009-09-18 12:34

 linux驱动模块编译问题

我的驱动的ffile_operations dev_fops 如下:
static struct file_operations dev_fops = {
    .owner    =THIS_MODULE,
    .read  =    buttons_read,
    .write =    button_write,//91行
    .ioctl    =sbc2440_leds_ioctl,
};

write函数原型:static ssize_t button_write(struct file *file,char __user *buf,size_t count,loff_t *f_pos)

编译的时候出现如下警告:

drivers/char/getin.c:91: warning: initialization from incompatible pointer type

91行要怎么写呢?


模块能编译出来,我感觉有警告心里就不踏实一样,测试驱动也没有问题,

*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-09-18 12:54
在我用的内核源代码的include/linux/fs.h里有
复制代码
  1. struct file_operations {
  2.         struct module *owner;
  3.         loff_t (*llseek) (struct file *, loff_t, int);
  4.         ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
  5.         ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
  6.         ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
  7. ...

所以驱动里的write()函数严格的声明可以写成
复制代码
  1. static ssize_t button_write(struct file *file,const char __user *buf,size_t count,loff_t *f_pos);

不过你可以放心,这个不影响驱动的功能,只是编译器严格检查函数原型造成的警告而已
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."