cf91b1d
From: Paolo Bonzini <pbonzini@redhat.com>
cf91b1d
Date: Wed, 15 Jun 2016 14:29:33 +0200
cf91b1d
Subject: [PATCH] scsi: esp: clean up handle_ti/esp_do_dma if s->do_cmd
cf91b1d
cf91b1d
Avoid duplicated code between esp_do_dma and handle_ti.  esp_do_dma
cf91b1d
has the same code that handle_ti contains after the call to esp_do_dma;
cf91b1d
but the code in handle_ti is never reached because it is in an "else if".
cf91b1d
Remove the else and also the pointless return.
cf91b1d
cf91b1d
esp_do_dma also has a partially dead assignment of the to_device
cf91b1d
variable.  Sink it to the point where it's actually used.
cf91b1d
cf91b1d
Finally, assert that the other caller of esp_do_dma (esp_transfer_data)
cf91b1d
only transfers data and not a command.  This is true because get_cmd
cf91b1d
cancels the old request synchronously before its caller handle_satn_stop
cf91b1d
sets do_cmd to 1.
cf91b1d
cf91b1d
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
cf91b1d
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
cf91b1d
(cherry picked from commit 7f0b6e114ae4e142e2b3dfc9fac138f4a30edc4f)
cf91b1d
---
cf91b1d
 hw/scsi/esp.c | 11 ++++-------
cf91b1d
 1 file changed, 4 insertions(+), 7 deletions(-)
cf91b1d
cf91b1d
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
cf91b1d
index 6407844..68d3e4d 100644
cf91b1d
--- a/hw/scsi/esp.c
cf91b1d
+++ b/hw/scsi/esp.c
cf91b1d
@@ -245,15 +245,10 @@ static void esp_do_dma(ESPState *s)
cf91b1d
     uint32_t len;
cf91b1d
     int to_device;
cf91b1d
 
cf91b1d
-    to_device = (s->ti_size < 0);
cf91b1d
     len = s->dma_left;
cf91b1d
     if (s->do_cmd) {
cf91b1d
         trace_esp_do_dma(s->cmdlen, len);
cf91b1d
         s->dma_memory_read(s->dma_opaque, &s->cmdbuf[s->cmdlen], len);
cf91b1d
-        s->ti_size = 0;
cf91b1d
-        s->cmdlen = 0;
cf91b1d
-        s->do_cmd = 0;
cf91b1d
-        do_cmd(s, s->cmdbuf);
cf91b1d
         return;
cf91b1d
     }
cf91b1d
     if (s->async_len == 0) {
cf91b1d
@@ -263,6 +258,7 @@ static void esp_do_dma(ESPState *s)
cf91b1d
     if (len > s->async_len) {
cf91b1d
         len = s->async_len;
cf91b1d
     }
cf91b1d
+    to_device = (s->ti_size < 0);
cf91b1d
     if (to_device) {
cf91b1d
         s->dma_memory_read(s->dma_opaque, s->async_buf, len);
cf91b1d
     } else {
cf91b1d
@@ -318,6 +314,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len)
cf91b1d
 {
cf91b1d
     ESPState *s = req->hba_private;
cf91b1d
 
cf91b1d
+    assert(!s->do_cmd);
cf91b1d
     trace_esp_transfer_data(s->dma_left, s->ti_size);
cf91b1d
     s->async_len = len;
cf91b1d
     s->async_buf = scsi_req_get_buf(req);
cf91b1d
@@ -358,13 +355,13 @@ static void handle_ti(ESPState *s)
cf91b1d
         s->dma_left = minlen;
cf91b1d
         s->rregs[ESP_RSTAT] &= ~STAT_TC;
cf91b1d
         esp_do_dma(s);
cf91b1d
-    } else if (s->do_cmd) {
cf91b1d
+    }
cf91b1d
+    if (s->do_cmd) {
cf91b1d
         trace_esp_handle_ti_cmd(s->cmdlen);
cf91b1d
         s->ti_size = 0;
cf91b1d
         s->cmdlen = 0;
cf91b1d
         s->do_cmd = 0;
cf91b1d
         do_cmd(s, s->cmdbuf);
cf91b1d
-        return;
cf91b1d
     }
cf91b1d
 }
cf91b1d