I am trying to write kernel module for ubuntu 12.04 LTS OS. kernel version is 3.4.0-030400-generic-pae I am able to compile it & load it to kernel. For loading I use
sudo insmod nmod_main.ko
Now, If I try to remove it using
sudo rmmod nmod_main.ko
it gives me bellow error. ERROR: Removing 'nmod_main': Device or resource busy
lsmod gives bellow information:
Module Size Used by
nmod_main 12394 0 [permanent]
Why this module shows permanent?
Bellow is the C-code for this module.
/********** Start of code ************/
#define __KERNEL__
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "init_module() called\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "cleanup_module() called\n");
}
/********** End of code ************/
I am getting some compilation warnings as bellow:
Building with KERNELRELEASE = 3.4.0-030400-generic-pae
CC [M] ../src/nmod_main.o
../src/nmod_main.c:1:0: warning: "KERNEL" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
../src/nmod_main.c:2:0: warning: "MODULE" redefined [enabled by default]
:0:0: note: this is the location of the previous definition
Building modules, stage 2.
Building with KERNELRELEASE = 3.4.0-030400-generic-pae
Please can anybody help me in this regard.
I am using bellow makefile for building this module:
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 ../src/*.o ../src/*~ core ../src/.depend ../src/.*.cmd ../src/*.ko ../src/*.mod.c
else
$(info Building with KERNELRELEASE = ${KERNELRELEASE})
obj-m := ../src/nmod_main.o
endi