EmbLogic's Blog

problem in character driver —errors and warnings

these are the errors and warnings quoted by the kernel

[root@averma nd1]# make
make -C /lib/modules/2.6.38.8/build M=/home/amit/averma/drivers/nd1 modules
make[1]: Entering directory `/usr/src/linux-2.6.38.8′
CC [M] /home/amit/averma/drivers/nd1/lk.o
/home/amit/averma/drivers/nd1/lk.c: In function ‘scull_open’:
/home/amit/averma/drivers/nd1/lk.c:26:68: warning: initialization makes pointer from integer without a cast [enabled by default]
/home/amit/averma/drivers/nd1/lk.c: In function ‘hello_init’:
/home/amit/averma/drivers/nd1/lk.c:23:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
Building modules, stage 2.
MODPOST 1 modules
CC /home/amit/averma/drivers/nd1/lk.mod.o
LD [M] /home/amit/averma/drivers/nd1/lk.ko
make[1]: Leaving directory `/usr/src/linux-2.6.38.8′

the program is as follows:

#include”header.h”

/*static int scull_open(struct inode *inde,struct file *filep)
{
}*/
struct scull_dev *re;
static int hello_init(void)

{

ret = alloc_chrdev_region(&dev,0,NOD,DEVICE_NAME); //device registeration
printk(KERN_INFO”device registered in kernel sucessfully\n”);
dev = MKDEV(major,minor);
printk(KERN_INFO”major no is : %d\n minorno is : %d\n”,major,minor);//device reg. done
re = (struct scull_dev*)kmalloc(sizeof(struct scull_dev)*100,GFP_KERNEL);
if(re == NULL)
{
printk(KERN_ERR”kmalloc: memory not allocated\n”);
}
printk(KERN_INFO”kamlloc : memory allocated\n”);
memset(re,”,sizeof(struct scull_dev));

int scull_open(struct inod *inode,struct file *filp)
{
struct scull_dev *dev;
dev = container_of (inode->i_cdev,struct scull_dev,cdev);
filp->private_data=dev;
return 0;
}

int scull_release(struct inode *inode,struct filep *filp)
{
return 0;
}
kfree(re);
return 0;
}

static void hello_exit(void)
{

unregister_chrdev_region(dev,1);
printk(KERN_ALERT”bye kernel”);
}

module_init(hello_init);
module_exit(hello_exit);

and the header file is:

#include
#include
#include
#include
#include
#include

MODULE_LICENSE(“GPL”);

#define DEVICE_NAME “AVERMA”
#define NOD 1

dev_t dev;
int ret;
int major;
int minor;

//static int scull_open(struct inode *inode ,struct file *filp);
//static int scull_release(struct inode *inode ,struct file *filp);

struct inod
{
dev_t i_rdev;
dev_t i_cdev;
};
struct filep
{
struct file_operations *fops;
void *private_data;
};

struct c_dev
{
const struct file_operations *ops;
struct module * owner;
dev_t dev ;
unsigned int count;
};

struct scull_dev
{
struct cdev cdev;
struct scull_qset *data;
int quantum;
int qset;

};

struct file_operations fops=

{
// .open =scull_open,
// .release =scull_release,
};

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>