[PATCH spice-gtk v2 15/33] fixup! usb-redir: add files for SCSI and USB MSC implementation

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

 



Reuse MIN macro.
---
 src/cd-scsi.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/cd-scsi.c b/src/cd-scsi.c
index 616c65da..bce7191b 100644
--- a/src/cd-scsi.c
+++ b/src/cd-scsi.c
@@ -849,8 +849,7 @@ static void cd_scsi_cmd_request_sense(CdScsiLU *dev, CdScsiRequest *req)
     req->xfer_dir = SCSI_XFER_FROM_DEV;
 
     req->req_len = req->cdb[4];
-    req->in_len = (req->req_len < sizeof(dev->fixed_sense)) ?
-                   req->req_len : sizeof(dev->fixed_sense);
+    req->in_len = MIN(req->req_len, sizeof(dev->fixed_sense));
 
     if (dev->short_sense.key != NO_SENSE) {
         SPICE_DEBUG("%s, lun:%u reported sense: 0x%02x %02x %02x - %s, %s",
@@ -918,7 +917,7 @@ static void cd_scsi_cmd_inquiry_vpd_no_lun(CdScsiLU *dev, CdScsiRequest *req,
     outbuf[2] = 0x00; /* page length MSB */
     outbuf[3] = 0x00; /* page length LSB - no more data */
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     SPICE_DEBUG("inquiry_vpd, unsupported lun:%u"
                 " perif_qual:0x%x resp_len: %" G_GUINT64_FORMAT,
@@ -1044,7 +1043,7 @@ static void cd_scsi_cmd_inquiry_standard_no_lun(CdScsiLU *dev, CdScsiRequest *re
 
     outbuf[4] = resp_len - 4; /* additional length, after header */
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     SPICE_DEBUG("inquiry_standard, unsupported lun:%u perif_qual:0x%x "
                 "inquiry_len: %u resp_len: %" G_GUINT64_FORMAT,
@@ -1087,7 +1086,7 @@ static void cd_scsi_cmd_inquiry_standard(CdScsiLU *dev, CdScsiRequest *req)
         outbuf[65] = INQUIRY_VERSION_DESC_SBC2 & 0xff;
     }
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     SPICE_DEBUG("inquiry_standard, lun:%u"
                 " inquiry_len: %u resp_len: %" G_GUINT64_FORMAT,
@@ -1196,7 +1195,7 @@ static void cd_scsi_cmd_get_read_disc_information(CdScsiLU *dev, CdScsiRequest *
     }
 
     req->req_len = (req->cdb[7] << 8) | req->cdb[8];
-    req->in_len = (req->req_len < RDI_STANDARD_LEN) ? req->req_len : RDI_STANDARD_LEN;
+    req->in_len = MIN(req->req_len, RDI_STANDARD_LEN);
 
     memset(outbuf, 0, RDI_STANDARD_LEN);
     outbuf[1] = RDI_STANDARD_LEN - 2; /* length excluding the counter itself */
@@ -1287,7 +1286,7 @@ static void cd_scsi_cmd_get_read_track_information(CdScsiLU *dev, CdScsiRequest
     }
 
     req->req_len = (req->cdb[7] << 8) | req->cdb[8];
-    req->in_len = (req->req_len < TIB_LEN) ? req->req_len : TIB_LEN;
+    req->in_len = MIN(req->req_len, TIB_LEN);
 
     memset(outbuf, 0, TIB_LEN);
     outbuf[1] = TIB_LEN - 2;
@@ -1332,7 +1331,7 @@ static void cd_scsi_cmd_read_toc(CdScsiLU *dev, CdScsiRequest *req)
     track_num = req->cdb[6];
 
     req->req_len = (req->cdb[7] << 8) | req->cdb[8];
-    req->in_len = (req->req_len < READ_TOC_RESP_LEN) ? req->req_len : READ_TOC_RESP_LEN;
+    req->in_len = MIN(req->req_len, READ_TOC_RESP_LEN);
 
     memset(outbuf, 0, READ_TOC_RESP_LEN);
     outbuf[1] = READ_TOC_RESP_LEN - 2; /* length excluding the counter itself */
@@ -1487,7 +1486,7 @@ static void cd_scsi_cmd_mode_sense_10(CdScsiLU *dev, CdScsiRequest *req)
     outbuf[0] = ((resp_len - 2) >> 8) & 0xff;
     outbuf[1] = (resp_len - 2) & 0xff;
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     SPICE_DEBUG("mode_sense_10, lun:%u"
                 " long_lba %d, dbd %d, page %d, sub_page %d, pc %d; "
@@ -1912,7 +1911,7 @@ static void cd_scsi_cmd_get_configuration(CdScsiLU *dev, CdScsiRequest *req)
     outbuf[6] = (profile_num >> 8) & 0xff;
     outbuf[7] = profile_num & 0xff;
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     SPICE_DEBUG("get_configuration, lun:%u rt:%u start_f:%u resp_len:%u",
                 req->lun, req_type, start_feature, resp_len);
@@ -2023,7 +2022,7 @@ static void cd_scsi_cmd_get_event_status_notification(CdScsiLU *dev, CdScsiReque
                                           * field itself */
     outbuf[3] = (uint8_t)classes_supported;
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
     cd_scsi_cmd_complete_good(dev, req);
 }
 
@@ -2336,7 +2335,7 @@ static void cd_scsi_get_performance_resp_performance(CdScsiLU *dev, CdScsiReques
     req->req_len = CD_PERF_HEADER_LEN +
                    (max_num_descr * CD_PERF_TYPE_PERFORMANCE_DESCR_LEN);
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     cd_scsi_cmd_complete_good(dev, req);
 }
@@ -2422,7 +2421,7 @@ static void cd_scsi_cmd_mechanism_status(CdScsiLU *dev, CdScsiRequest *req)
     /* For non-changer devices the number of slot tables returned shall be zero, so we leave
        both 'Number of Slots Available' and 'Length of Slot Table' fields as zeros */
 
-    req->in_len = (req->req_len < resp_len) ? req->req_len : resp_len;
+    req->in_len = MIN(req->req_len, resp_len);
 
     SPICE_DEBUG("mechanism_status, lun:%u", req->lun);
 
@@ -2463,7 +2462,7 @@ static void cd_scsi_read_async_complete(GObject *src_object,
                     " req: %"  G_GUINT64_FORMAT,
                     req->lun, finished, (uint64_t)bytes_read, req->req_len);
 
-        req->in_len = (bytes_read <= req->req_len) ? bytes_read : req->req_len;
+        req->in_len = MIN(bytes_read, req->req_len);
         req->status = GOOD;
     } else {
         if (error != NULL) {
-- 
2.20.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]