sbp2: prevent unloading of 1394 low-level driver
authorStefan Richter <stefanr@s5r6.in-berlin.de>
Wed, 29 Mar 2006 00:54:52 +0000 (19:54 -0500)
committerJody McIntyre <scjody@modernduck.com>
Wed, 29 Mar 2006 00:54:52 +0000 (19:54 -0500)
When a new SBP-2 unit is added, sbp2 now takes a reference on the 1394
low-level driver (ohci1394 or pcilynx).  This prevents the 1394 host driver
module from being unloaded, e.g. by an administrative routine cleanup of
unused kernel modules or when another 1394 driver which depends on ohci1394
is unloaded.

The reference is dropped when the SBP-2 unit was disconnected, when sbp2 is
unloaded or detached from the unit, or when addition of the SBP-2 unit failed.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Jody McIntyre <scjody@modernduck.com>
drivers/ieee1394/sbp2.c

index eca92eb..0b2b0da 100644 (file)
@@ -755,6 +755,12 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud
 #endif
        }
 
+       /* Prevent unloading of the 1394 host */
+       if (!try_module_get(hi->host->driver->owner)) {
+               SBP2_ERR("failed to get a reference on 1394 host driver");
+               goto failed_alloc;
+       }
+
        scsi_id->hi = hi;
 
        list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids);
@@ -1015,6 +1021,9 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id)
 
        scsi_id->ud->device.driver_data = NULL;
 
+       if (hi)
+               module_put(hi->host->driver->owner);
+
        SBP2_DEBUG("SBP-2 device removed, SCSI ID = %d", scsi_id->ud->id);
 
        kfree(scsi_id);