Writing Device Drivers


The _fini(9E) function is called when the system is about to try to unload the SCSI HBA driver. The _fini(9E) function must call mod_remove(9F) to determine if the driver can be unloaded. If mod_remove(9F) returns 0, the module can be unloaded, and the HBA driver must deallocate any global resources allocated in _init(9E) and must call scsi_hba_fini(9F).

_fini(9E) must return the value returned by mod_remove(9F).

Note -

The HBA driver must not free any resources or call scsi_hba_fini(9F) unless mod_remove(9F) returns 0.

The _fini(9E) function in Example 14-2 shows how a SCSI HBA driver deallocates a global mutex initialized in _init(9E).

Example 14-2 SCSI HBA _fini(9E) Function

  	int     err;
 	if ((err = mod_remove(&modlinkage)) == 0) {
	  return (err);