Skip to contentSkip to conversation

Fixup scsi_sysfs_add_sdev()

PATCH New Hannes Reinecke 1 participant 1 message Jun 18, 2007 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 10/11 Fixup scsi_sysfs_add_sdev()

scsi_sysfs_add_sdev() should not modify the sdev state as it doesn't require any hardware access. And we should take care to retrace our steps on failure.

---
 drivers/scsi/scsi_sysfs.c |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)
drivers/scsi/scsi_sysfs.c +10 -14
index 0e11fa3..6be59c9 100644
@@ -720,21 +721,16 @@ int scsi_sysfs_add_sdev(struct scsi_devi
 {
 	int error, i;
 
-	if ((error = scsi_device_set_state(sdev, SDEV_RUNNING)) != 0)
-		return error;
-
 	error = device_add(&sdev->sdev_gendev);
 	if (error) {
 		sdev_printk(KERN_INFO, sdev,
 			    "failed to add device (error %d)\n", error);
-		scsi_device_set_state(sdev, SDEV_DEL);
 		return error;
 	}
 	error = class_device_add(&sdev->sdev_classdev);
 	if (error) {
 		sdev_printk(KERN_INFO, sdev,
 			    "failed to add class device (error %d)\n", error);
-		scsi_device_set_state(sdev, SDEV_DEL);
 		device_del(&sdev->sdev_gendev);
 		return error;
 	}
@@ -746,14 +742,11 @@ int scsi_sysfs_add_sdev(struct scsi_devi
 		for (i = 0; sdev->host->hostt->sdev_attrs[i]; i++) {
 			error = attr_add(&sdev->sdev_gendev,
 					sdev->host->hostt->sdev_attrs[i]);
-			if (error) {
-				scsi_sysfs_remove_sdev(sdev);
-				scsi_destroy_device(sdev);
+			if (error)
 				goto out;
-			}
 		}
 	}
-	
+
 	for (i = 0; scsi_sysfs_sdev_attrs[i]; i++) {
 		if (!attr_overridden(sdev->host->hostt->sdev_attrs,
 					scsi_sysfs_sdev_attrs[i])) {
@@ -761,16 +754,20 @@ int scsi_sysfs_add_sdev(struct scsi_devi
 				attr_changed_internally(sdev->host, 
 							scsi_sysfs_sdev_attrs[i]);
 			error = device_create_file(&sdev->sdev_gendev, attr);
-			if (error) {
-				scsi_sysfs_remove_sdev(sdev);
-				scsi_destroy_device(sdev);
+			if (error)
 				goto out;
-			}
 		}
 	}
 
 	transport_add_device(&sdev->sdev_gendev);
+
+	return 0;
+
  out:
+	class_device_del(&sdev->sdev_classdev);
+	put_device(&sdev->sdev_gendev);
+	device_del(&sdev->sdev_gendev);
+
 	return error;
 }
 
Signature · 1 line
1.4.3.4