[spice-gtk,23/44] fixup! usb-redir: add files for SCSI and USB MSC implementation

Submitted by Frediano Ziglio on July 30, 2019, 12:03 p.m.

Details

Message ID 20190730120331.17967-23-fziglio@redhat.com
State Superseded
Headers show
Series "Follow ups for CD emulation patch series" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 30, 2019, 12:03 p.m.
Use constructor to initialize structure, avoid multiple calls
to cd_scsi_cmd_names_init and a variable.
---
 src/cd-scsi.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cd-scsi.c b/src/cd-scsi.c
index 9963762f..2a3595bb 100644
--- a/src/cd-scsi.c
+++ b/src/cd-scsi.c
@@ -112,7 +112,6 @@  struct CdScsiTarget {
     CdScsiLU units[MAX_LUNS];
 };
 
-static gboolean cmd_names_initialized = FALSE;
 static const char* scsi_cmd_name[256];
 
 /* Predefined sense codes */
@@ -371,14 +370,10 @@  static void cd_scsi_cmd_complete_good(CdScsiLU *dev, CdScsiRequest *req)
 
 /* SCSI Target */
 
-static void cd_scsi_cmd_names_init(void)
+SPICE_CONSTRUCTOR_FUNC(cd_scsi_cmd_names_init)
 {
     uint32_t opcode;
 
-    if (cmd_names_initialized) {
-        return;
-    }
-
     for (opcode = 0; opcode < 256; opcode++) {
         scsi_cmd_name[opcode] = "UNSUPPORTED";
     }
@@ -407,8 +402,6 @@  static void cd_scsi_cmd_names_init(void)
     scsi_cmd_name[START_STOP] = "START STOP UNIT";
     scsi_cmd_name[MMC_GET_PERFORMANCE] = "GET PERFORMANCE";
     scsi_cmd_name[MMC_MECHANISM_STATUS] = "MECHANISM STATUS";
-
-    cmd_names_initialized = TRUE;
 }
 
 CdScsiTarget *cd_scsi_target_alloc(void *target_user_data, uint32_t max_luns)
@@ -428,8 +421,6 @@  CdScsiTarget *cd_scsi_target_alloc(void *target_user_data, uint32_t max_luns)
     st->cancellable = g_cancellable_new();
     st->max_luns = max_luns;
 
-    cd_scsi_cmd_names_init();
-
     return st;
 }