LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-22-2006, 10:03 AM   #1
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Rep: Reputation: 16
Better way to load/unload a kernel module


Hello,
I have a custum made "USB device" (given by my friend) and I am trying to make this device work on linux. I have written a kernel module for this device.

To load and unload this module whenever I plug-in/unplug this "USB device" I did some changes in the "/sbin/hotplug" script.

This is the change I did ...

if [ "$1" = "usb" ]
then
if [ "$ACTION" = "add" ]
then
if [ "$PRODUCT" = "82d/7124/110" ]
then
/sbin/insmod /home/seran/controller.o
fi
fi

if [ "$ACTION" = "remove" ]
then
if [ "$PRODUCT" = "82d/7124/110" ]
then
/sbin/rmmod controller
fi
fi
fi

I added the above condition before hotplug calls "usb.agent" script.
If the ACTION is "add" and if the PRODUCT id matches, it does an insmod of my module.
If the ACTION is "remove" and if the PRODUCT id matches, it does an rmmod of the module.

And in the "usb.agent" script I added the following lines just before the "case" statement.

if [ "$PRODUCT" = "3eb/6124/110" ]
then
exit 2
fi

This will avoid "usb.agent" proceeding further, because "hotplug" already did the required work.

Everything looks fine. But I personally feel this looks sloppy.

Is there any better way I can load/unload my module whenever I plug/unplug this device.

I am using Red Hat Linux release 9 and kernel 2.4.20-8.

Please give me some suggesstions.

Thanks
Seran
 
Old 06-22-2006, 10:35 AM   #2
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
If you just want it to look good then I would have done it more like:
Code:
if [ "$1" = "usb" ];then
 if [ "$PRODUCT" = "82d/7124/110" ];then
  if [ "$ACTION" = "add" ];then
   /sbin/insmod /home/seran/controller.o
  elif [ "$ACTION" = "remove" ];then
   /sbin/rmmod controller
  fi
 fi
fi
 
Old 06-23-2006, 04:55 AM   #3
seran
Member
 
Registered: Aug 2004
Location: Bangalore
Posts: 64

Original Poster
Rep: Reputation: 16
Quote:
...feel this looks sloppy
What I ment was, is there any other way without touching hotplug script, can the module will be loaded/unloaded?

Whenever I get a new device I have to make it work in linux. So, everytime adding some conditions inside "hotplug" to load/unload a particular module won't be nice.

I hope there will be in a smarter way this can achieved.
 
Old 06-23-2006, 08:19 AM   #4
binary_y2k2
Member
 
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
you could put them all in a seperet file and add the line
Code:
. /etc/devices $@
Then the hotplug script would source that file and pass any options to it.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rapid module load/unload = Kernel panic mclerand Linux - Kernel 0 05-06-2006 11:02 AM
forcing a module to unload Ashrack Linux - General 1 01-25-2006 06:59 PM
how to unload kernel module dynamically kushneeraj Programming 1 10-26-2005 11:46 PM
unload ub-module at boot? Urkburk Slackware 10 03-25-2005 05:35 AM
Unable to unload eepro100 module in Kernel 2.6 simjii Linux - General 0 12-08-2003 11:50 PM


All times are GMT -5. The time now is 10:01 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration