char *memory_buffer[];
to
char *memory_buffer;
- Manoj
On Sun, Sep 19, 2010 at 5:05 AM, Bond <jamesbond.2k.g@xxxxxxxxx> wrote:
Hi,
I am modifying one of my drivers it had once worked but currently giving me some errors.
The Makefile is at the end of the code
Here is the code for
bond.c
----------------------------------------------------------------------
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/proc_fs.h>
#include <linux/fcntl.h> /* O_ACCMODE */
#include <asm/system.h> /* cli(), *_flags */
#include <asm/uaccess.h> /* copy_from/to_user */
MODULE_LICENSE("Dual BSD/GPL");
int memory_open(struct inode *inode, struct file *filp);
int memory_release(struct inode *inode, struct file *filp);
ssize_t memory_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);
ssize_t memory_write(struct file *filp, char *buf, size_t count, loff_t *f_pos);
void memory_exit(void);
int memory_init(void);
/* Structure that declares the usual file */
/* access functions */
struct file_operations memory_fops = {
read: memory_read,
write: memory_write,
open: memory_open,
release: memory_release
};
/* Declaration of the init and exit functions */
module_init(memory_init);
module_exit(memory_exit);
/* Global variables of the driver */
/* Major number */
int memory_major = 60;
/* Buffer to store data */
char *memory_buffer[];
int memory_init(void) {
int result;
/* Registering device */
result = register_chrdev(memory_major, "bond", &memory_fops);
if (result < 0) {
printk(KERN_ALERT "memory: cannot obtain major number %d\n", memory_major);
return result;
}
/* Allocating memory for the buffer */
memory_buffer = kmalloc(1, GFP_KERNEL);
if (!memory_buffer) {
result = -ENOMEM;
goto fail;
}
memset(memory_buffer, 0, 10);
printk(KERN_ALERT "Inserting bond module\n");
return 0;
fail:
memory_exit();
return result;
}
void memory_exit(void) {
/* Freeing the major number */
unregister_chrdev(memory_major, "bond");
/* Freeing buffer memory */
if (memory_buffer) {
kfree(memory_buffer);
}
printk( KERN_ALERT "Removing bond module\n");
}
int memory_open(struct inode *inode, struct file *filp) {
/* Success */
return 0;
}
int memory_release(struct inode *inode, struct file *filp) {
/* Success */
return 0;
}
ssize_t memory_read(struct file *filp, char *buf,
size_t count, loff_t *f_pos) {
/* Transfering data to user space */
copy_to_user(buf,memory_buffer,10);
/* Changing reading position as best suits */
if (*f_pos == 0) {
*f_pos+=1;
return 1;
} else {
return 0;
}
}
ssize_t memory_write( struct file *filp, char *buf,
size_t count, loff_t *f_pos) {
char *tmp;
tmp=buf+count-1;
copy_from_user(memory_buffer,tmp,1);
return 1;
}
----------------------------------------------------------------------
Makefile
----------------------------------------------------------------------
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
.PHONY: build clean
build:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c
rm -rf modules.order Module.symvers
else
$(info Building with KERNELRELEASE =${KERNELRELEASE})
obj-m := bond.o
endif
----------------------------------------------------------------------
When ever I am compiling it I am getting following error
----------------------------------------------------------------------
/home/s/programming/bond.c:29: warning: initialization from incompatible pointer type
/home/s/programming/bond.c: In function ‘memory_init’:
/home/s/programming/bond.c:54: error: ‘memory_buffer’ has an incomplete type
/home/s/programming/bond.c:55: warning: the address of ‘memory_buffer’ will always evaluate as ‘true’
/home/s/programming/bond.c: In function ‘memory_exit’:
/home/s/programming/bond.c:75: warning: the address of ‘memory_buffer’ will always evaluate as ‘true’
make[2]: *** [/home/s/programming/bond.o] Error 1
make[1]: *** [_module_/home/s/programming] Error 2
make: *** [build] Error 2
----------------------------------------------------------------------
What could be the possible error ?
I have checked kernel headers they are installed.
but I am not clear with the error which the above is coming in above.