Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12371

how to fix problem with initialization from incompatible pointer type

$
0
0

I'm trying to create a kernel module, which creates a subdirectory in the /proc directory, and contains a file that can be written and read from user space.

But always when I compile the module I get the same errors:

error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types].read = read_proc,error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types].write = write_proc,error: dereferencing pointer to incomplete type ‘struct proc_dir_entry’     Our_Proc_File->read_proc = read_proc;

Code:

#define __KERNEL__#define MODULE#include<linux/seq_file.h> #include <linux/module.h>#include <linux/proc_fs.h>#include <linux/string.h>#include <linux/init.h>#include <linux/kernel.h>   #include <asm/uaccess.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("1");#define MAXBUFFSIZE 256static char mm_buff[MAXBUFFSIZE];static struct proc_dir_entry* Our_Proc_File;static struct proc_dir_entry* Our_Proc_Dir;static ssize_t read_proc(  char* buffer,  char** buffer_location, off_t offset,        int buffer_length,  int* eof, void* data){        int len =0;        static int count = 1;        if(offset > 0){                *eof = 1;                return len;        }        len = sprintf(buffer,"[%d] %s\n",count++,mm_buff);        return len;}static ssize_t write_proc( struct file* file,const char* buffer, unsigned long count,            void *data){        if(count < (MAXBUFFSIZE-1)){                strncpy(mm_buff,buffer,count);                mm_buff[count] = '\0';                printk("Buffer: %s\n",mm_buff);        }        return count;}static struct file_operations myops ={    .owner = THIS_MODULE,    .read = read_proc,    .write = write_proc,};static int __init simple_init(void){        printk("MyModule Loaded Successfully\n");        Our_Proc_Dir = proc_mkdir("Colours",NULL);        if(IS_ERR(Our_Proc_Dir)){                printk("Failed to create directory\n");                return -1;        }        Our_Proc_File = proc_create("Orange",0644,Our_Proc_Dir,&myops);       if(IS_ERR(Our_Proc_File)){                proc_remove(Our_Proc_Dir);                return -1;        }        Our_Proc_File->read_proc = read_proc;        Our_Proc_File->write_proc =write_proc;        return 0;}static void __exit fun(void){        if(Our_Proc_File) proc_remove(Our_Proc_File); if(Our_Proc_Dir) proc_remove(Our_Proc_Dir);        printk("MyModule Exit!\n");}module_init(simple_init);module_exit(fun);

Viewing all articles
Browse latest Browse all 12371

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>