[PATCH] SCSI core code cleanup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



James:

This patch (as583) makes some minor cleanups and improvements to some 
newly-added sections of code.  The primary benefits are removal of 
misleading error messages in the system log, and moving two BUG_ON lines 
outside spinlock-protected areas (so they won't crash the entire system).

Alan Stern



Signed-off-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>

---

Index: usb-2.6/drivers/scsi/scsi_error.c
===================================================================
--- usb-2.6.orig/drivers/scsi/scsi_error.c
+++ usb-2.6/drivers/scsi/scsi_error.c
@@ -74,9 +74,10 @@ int scsi_eh_scmd_add(struct scsi_cmnd *s
 		return 0;
 
 	spin_lock_irqsave(shost->host_lock, flags);
-	if (scsi_host_set_state(shost, SHOST_RECOVERY))
-		if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY))
-			goto out_unlock;
+	if (scsi_host_set_state(shost,
+			(shost->shost_state == SHOST_CANCEL) ?
+				SHOST_CANCEL_RECOVERY : SHOST_RECOVERY))
+		goto out_unlock;
 
 	ret = 1;
 	scmd->eh_eflags |= eh_flag;
@@ -1446,6 +1447,8 @@ static void scsi_restart_operations(stru
 {
 	struct scsi_device *sdev;
 	unsigned long flags;
+	enum scsi_host_state newstate;
+	int rc;
 
 	/*
 	 * If the door was locked, we need to insert a door lock request
@@ -1466,10 +1469,20 @@ static void scsi_restart_operations(stru
 					  __FUNCTION__));
 
 	spin_lock_irqsave(shost->host_lock, flags);
-	if (scsi_host_set_state(shost, SHOST_RUNNING))
-		if (scsi_host_set_state(shost, SHOST_CANCEL))
-			BUG_ON(scsi_host_set_state(shost, SHOST_DEL));
+	switch (shost->shost_state) {
+	default:
+		newstate = SHOST_RUNNING;
+		break;
+	case SHOST_CANCEL_RECOVERY:
+		newstate = SHOST_CANCEL;
+		break;
+	case SHOST_DEL_RECOVERY:
+		newstate = SHOST_DEL;
+		break;
+	}
+	rc = scsi_host_set_state(shost, newstate);
 	spin_unlock_irqrestore(shost->host_lock, flags);
+	BUG_ON(rc);
 
 	wake_up(&shost->host_wait);
 
Index: usb-2.6/drivers/scsi/hosts.c
===================================================================
--- usb-2.6.orig/drivers/scsi/hosts.c
+++ usb-2.6/drivers/scsi/hosts.c
@@ -154,24 +154,27 @@ EXPORT_SYMBOL(scsi_host_set_state);
  **/
 void scsi_remove_host(struct Scsi_Host *shost)
 {
+	int rc;
 	unsigned long flags;
+
 	down(&shost->scan_mutex);
 	spin_lock_irqsave(shost->host_lock, flags);
-	if (scsi_host_set_state(shost, SHOST_CANCEL))
-		if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY)) {
-			spin_unlock_irqrestore(shost->host_lock, flags);
-			up(&shost->scan_mutex);
-			return;
-		}
+	rc = scsi_host_set_state(shost,
+			(shost->shost_state == SHOST_RECOVERY) ?
+				SHOST_CANCEL_RECOVERY : SHOST_CANCEL);
 	spin_unlock_irqrestore(shost->host_lock, flags);
 	up(&shost->scan_mutex);
+	if (rc)
+		return;
 	scsi_forget_host(shost);
 	scsi_proc_host_rm(shost);
 
 	spin_lock_irqsave(shost->host_lock, flags);
-	if (scsi_host_set_state(shost, SHOST_DEL))
-		BUG_ON(scsi_host_set_state(shost, SHOST_DEL_RECOVERY));
+	rc = scsi_host_set_state(shost,
+			(shost->shost_state == SHOST_CANCEL_RECOVERY) ?
+				SHOST_DEL_RECOVERY : SHOST_DEL);
 	spin_unlock_irqrestore(shost->host_lock, flags);
+	BUG_ON(rc);
 
 	transport_unregister_device(&shost->shost_gendev);
 	class_device_unregister(&shost->shost_classdev);

-
: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux