您的位置:首页 > 运维架构 > Linux

linux 模块编译错误

2017-07-13 17:41 465 查看
在为android kernel编写模块的时候,将之前另一个工程的ko包驱动移植到新系统工程下,配置kernledir 等参数后,编译出现

warning: initialization from incompatible pointer type [enabled by default]

error, forbidden warning:

错误,因为在之前工程中编译没有问题,(因为之前的工程没有开始warning 停止选项)。

其中报警与错误信息解释如下

warning: initialization from incompatible pointer type [enabled by default]

表示编写的函数与系统中默认的函数参数不全相同。

error, forbidden warning:

表示开启了编译出现warning时退出报错选项,在这里是因为之前报了函数参数类型不相同的警告,所以编译停止报错。

查找了出错代码行 内容如下:

static const struct file_operations mytest_proc_fops = {
.owner = THIS_MODULE,
.read=xxx_proc_read,
.write=xxx_proc_write,

};

代码中实现的函数命名为

static ssize_t xxx_proc_write(struct file* filp,char __user *buf,size_t count,loff_t* f_pos)

{

}

而查找file_operations  中对于.write的命名为:

struct file_operations {
struct module *owner;
loff_t(*llseek) (struct file *, loff_t, int);
ssize_t(*read) (struct file *, char __user *, size_t, loff_t *);
ssize_t(*aio_read) (struct kiocb *, char __user *, size_t, loff_t);
ssize_t(*write) (struct file *, const char __user *, size_t, loff_t *);
ssize_t(*aio_write) (struct kiocb *, const char __user *, size_t,
loff_t);
int (*readdir) (struct file *, void *, filldir_t);
unsigned int (*poll) (struct file *, struct poll_table_struct *);
int (*ioctl) (struct inode *, struct file *, unsigned int,
unsigned long);
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
int (*flush) (struct file *);
int (*release) (struct inode *, struct file *);
int (*fsync) (struct file *, struct dentry *, int datasync);
int (*aio_fsync) (struct kiocb *, int datasync);
int (*fasync) (int, struct file *, int);
int (*lock) (struct file *, int, struct file_lock *);
ssize_t(*readv) (struct file *, const struct iovec *, unsigned long,
loff_t *);
ssize_t(*writev) (struct file *, const struct iovec *, unsigned long,
loff_t *);
ssize_t(*sendfile) (struct file *, loff_t *, size_t, read_actor_t,
void __user *);
ssize_t(*sendpage) (struct file *, struct page *, int, size_t,
loff_t *, int);
unsigned long (*get_unmapped_area) (struct file *, unsigned long,
unsigned long, unsigned long,
unsigned long);
};
其中
ssize_t(*write) (struct file *, const char __user *, size_t, loff_t *); 
static ssize_t xxx_proc_write(struct file* filp,char __user *buf,size_t count,loff_t* f_pos)
对比,第二个参数缺少了一个const 添加上后,编译警告去除,并编译通过。
总结:
在编写linux 驱动代码时,对于系统中定义的结构体中的函数,每个参数需要对应正确,否则会出现警告。不要凭印象,直接从相应结构体
头文件中获取函数参数为佳。


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: