Managing and Developing Dynamically Loadable Kernel Modules

Managing and Developing Dynamically Loadable Kernel Modules
Developing Dynamically Loadable Kernel Modules
Chapter 12542
Example 12-5 WSIO Class Driver _init Function
/*
* Device initialization Link
* Called only for statically linked drivers to link init
* routine into list.
*/
static void
module_name
_linked_init (void)
{
/* Perform driver-specific initialization */
(void)
module_name
_init ();
/* Call next init function in chain */
(void) (*
module_name
_saved_init)();
}
The _unload() function frees resources allocated by the driver and
unregisters the driver from WSIO. If it is safe to unload the driver when
the number of open devices for the driver goes to zero, then the module
need not perform any special checks to determine if it is busy. If any step
in the _unload() process fails, the driver must undo any action prior to
the failure. A sample _unload() function for a WSIO class driver is as
follows:
Example 12-6 WSIO Class Driver _unload Function
/*
* UNLOAD
*/
static int
module_name
_unload(void *drv_infop)
{
/* This function is only called when the administrator
* attempts to unload the module and there are no open
* devices using the module. If there is some reason that
* the module should not be unloaded, check it now and
* return non-zero.
*/
if (
module_name
_no_unload) {
printf("
module_name
> I’m BUSY\n");
return (EBUSY);
}
/* Unregister with WSIO */