Skip to contentSkip to conversation

scsi_get_host_dev

RFC PATCH New Mike Anderson 1 participant 1 message Jan 28, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 scsi_get_host_dev

Patch against: 2.5.59

This problem was noticed in a driver that was being ported from 2.4 to 2.5.xx.

The error signature was an oops in sg_attach do to sdev_driverfs_dev not being registered. This is because the common scsi_alloc_sdev code puts the scsi_device on the my_devices list that will later be iterated for attach calls. Adding to the my_devices is probably a good side effect in case this host scsi_device ever has a timeout and scsi_error fires up.

The failure mode can be inconsistent if you use the newer scsi_add_host interface.

An alternate solution could have been to honor the comment in scsi_get_host_dev to not have upper levels attach to the scsi_device by setting the type to 0x1f (Unknown or no device type) and have sg not attach to this type.

-andmike
--
Michael Anderson
[email protected]

 scsi_scan.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletion(-)

------

drivers/scsi/scsi_scan.c +9 -1
@@ -1937,6 +1937,11 @@
 	if (sdev) {
 		sdev->borken = 0;
 	}
+
+	scsi_device_register(sdev);
+
+	scsi_attach_device(sdev);
+
 	return sdev;
 }
 
@@ -1945,7 +1950,7 @@
  *
  * Purpose:     Free a scsi_device that points to the host adapter itself.
  *
- * Arguments:   SHpnt   - Host that needs a Scsi_Device
+ * Arguments:   sdev   - Host Scsi_Device
  *
  * Lock status: None assumed.
  *
@@ -1956,5 +1961,8 @@
 void scsi_free_host_dev(struct scsi_device *sdev)
 {
 	BUG_ON(sdev->id != sdev->host->this_id);
+
+	scsi_detach_device(sdev);
+	scsi_device_unregister(sdev);
 	scsi_free_sdev(sdev);
 }