Skip to contentSkip to conversation

hw/scsi/megasas: Simplify using the ldst API

PATCH Applied Philippe Mathieu-Daudé 2 participants 2 messages Dec 18, 2021 – Jan 12, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/scsi/megasas: Simplify using the ldst API

This code is easier to review using the load/store API.

---
v2: Fixed offset in megasas_setup_inquiry (rth)

---
 hw/scsi/megasas.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
hw/scsi/megasas.c +3 -14
index 619b66ef0f3..9a4e9ba87e6 100644
@@ -375,8 +375,7 @@ static int megasas_setup_inquiry(uint8_t *cdb, int pg, int len)
         cdb[1] = 0x1;
         cdb[2] = pg;
     }
-    cdb[3] = (len >> 8) & 0xff;
-    cdb[4] = (len & 0xff);
+    stw_be_p(&cdb[3], len);
     return len;
 }
 
@@ -392,18 +391,8 @@ static void megasas_encode_lba(uint8_t *cdb, uint64_t lba,
     } else {
         cdb[0] = READ_16;
     }
-    cdb[2] = (lba >> 56) & 0xff;
-    cdb[3] = (lba >> 48) & 0xff;
-    cdb[4] = (lba >> 40) & 0xff;
-    cdb[5] = (lba >> 32) & 0xff;
-    cdb[6] = (lba >> 24) & 0xff;
-    cdb[7] = (lba >> 16) & 0xff;
-    cdb[8] = (lba >> 8) & 0xff;
-    cdb[9] = (lba) & 0xff;
-    cdb[10] = (len >> 24) & 0xff;
-    cdb[11] = (len >> 16) & 0xff;
-    cdb[12] = (len >> 8) & 0xff;
-    cdb[13] = (len) & 0xff;
+    stq_be_p(&cdb[2], lba);
+    stl_be_p(&cdb[2 + 8], len);
 }
 
 /*
Signature · 1 line
2.33.1
#1 lore raw

Le 18/12/2021 à 12:19, Philippe Mathieu-Daudé a écrit :

Quoted 35 lines

This code is easier to review using the load/store API.

---
v2: Fixed offset in megasas_setup_inquiry (rth)

---
  hw/scsi/megasas.c | 17 +++--------------
  1 file changed, 3 insertions(+), 14 deletions(-)
hw/scsi/megasas.c +1 -9
index 619b66ef0f3..9a4e9ba87e6 100644
@@ -375,8 +375,7 @@ static int megasas_setup_inquiry(uint8_t *cdb, int pg, int len)
          cdb[1] = 0x1;
          cdb[2] = pg;
      }
-    cdb[3] = (len >> 8) & 0xff;
-    cdb[4] = (len & 0xff);
+    stw_be_p(&cdb[3], len);
      return len;
  }
 
@@ -392,18 +391,8 @@ static void megasas_encode_lba(uint8_t *cdb, uint64_t lba,
      } else {
          cdb[0] = READ_16;
      }
-    cdb[2] = (lba >> 56) & 0xff;
-    cdb[3] = (lba >> 48) & 0xff;
-    cdb[4] = (lba >> 40) & 0xff;
-    cdb[5] = (lba >> 32) & 0xff;
-    cdb[6] = (lba >> 24) & 0xff;
-    cdb[7] = (lba >> 16) & 0xff;
-    cdb[8] = (lba >> 8) & 0xff;

hw/scsi/megasas.c static void megasas_encode_lba(uint8_t *cdb, uint64_t lba, · line 398

Quoted 10 lines
hw/scsi/megasas.c +2 -5
-    cdb[9] = (lba) & 0xff;
-    cdb[10] = (len >> 24) & 0xff;
-    cdb[11] = (len >> 16) & 0xff;
-    cdb[12] = (len >> 8) & 0xff;
-    cdb[13] = (len) & 0xff;
+    stq_be_p(&cdb[2], lba);
+    stl_be_p(&cdb[2 + 8], len);
  }
 
  /*

Applied to my trivial-patches branch.

Thanks,
Laurent