LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-19-2014, 03:51 AM   #1
Prafull Barpute
LQ Newbie
 
Registered: Feb 2014
Posts: 2

Rep: Reputation: Disabled
Unhappy not able to remove loadable kernel module(LKM) using rmmod.


Hello,

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
Quote:
sudo insmod nmod_main.ko
Now, If I try to remove it using
Quote:
sudo rmmod nmod_main.ko
it gives me bellow error.
ERROR: Removing 'nmod_main': Device or resource busy

lsmod gives bellow information:
Quote:
Module Size Used by
nmod_main 12394 0 [permanent]
Why this module shows permanent?

Bellow is the C-code for this module.

Code:
/********** 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

Quote:
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]
<command-line>:0:0: note: this is the location of the previous definition
../src/nmod_main.c:2:0: warning: "MODULE" redefined [enabled by default]
<command-line>: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.

Thanks
Prafull Barpute
 
Old 02-20-2014, 09:52 AM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
A couple of things come to mind.

first I wouldn't do the __KERNEL__ and MODULE defines
second you aren't telling the kernel what the init and exit fuctions are, you need to do something like

module_init(init_module);
module_exit(cleanup_module);

third they need to be declared to be of a type module_init and module_exit can work with, use the __init and __exit macros to do this.

static int __init init_module(void) {...}
static int __exit cleanup_module(void) {...}

forth make sure you are using a compatible compiler, if they aren't compatible you'll sometimes get this issue
 
1 members found this post helpful.
Old 02-24-2014, 05:05 AM   #3
Prafull Barpute
LQ Newbie
 
Registered: Feb 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Problem Solved

This problem is solved. Yes it is problem related to toolchain. I downloaded .deb files to install kernel from url "http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/". But I was no sure about the toolchain used to generate these .deb files. So I finally download linux kernel source from "https://www.kernel.org/"->compile & install on my laptop & then compile my module. Problem disappeared. Thanks @estabroo for providing me valuable clue.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"insmod inserted the LKM into the kernel, But rmmod not removing it back" SIG_SEGV Linux - Embedded & Single-board computer 3 07-31-2012 10:17 AM
[Q] HOW TO rmmod with malfunction device driver kernel module. jspking Linux - General 2 04-08-2012 03:16 AM
loadable kernel module (LKM) issues shakthi Linux - Kernel 4 07-26-2011 10:02 AM
I want add my own system call using LKM (loadable kernel module)... raga4223688 Linux - Software 1 03-07-2007 08:21 AM
Linux 2.6 PCI driver module causing kernel panic on remove (rmmod) briek Linux - Software 2 09-18-2006 11:04 AM


All times are GMT -5. The time now is 06:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration