Writing Device Drivers

_fini() Example

The following example demonstrates the _fini() routine.

        int error;
    error = mod_remove(&modlinkage);
    if (error != 0) {
        return (error);
     * Cleanup resources allocated in _init()
    return (0);

Similarly, in _fini(), the driver should release any resources that were allocated in _init(). The driver must remove itself from the system module list.

Note –

_fini() might be called when the driver is attached to hardware instances. In this case, mod_remove(9F) returns failure. Therefore, driver resources should not be released until mod_remove() returns success.