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 |
If you just want it to look good then I would have done it more like:
Code:
if [ "$1" = "usb" ];then |
Quote:
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. |
you could put them all in a seperet file and add the line
Code:
. /etc/devices $@ |
All times are GMT -5. The time now is 12:29 PM. |