]> sigrok.org Git - libsigrok.git/commitdiff
serial: Shorten a few code snippets.
authorUwe Hermann <redacted>
Sat, 15 Jun 2019 15:35:42 +0000 (17:35 +0200)
committerUwe Hermann <redacted>
Sat, 15 Jun 2019 15:35:42 +0000 (17:35 +0200)
src/serial.c
src/serial_bt.c
src/serial_hid.c

index a2d0189fbb734c9908079e3d8bee768acc48b82a..7f9de4f686f1f08fb01d11276420ae5f09a9dd2e 100644 (file)
 
 #ifdef HAVE_SERIAL_COMM
 
-/* See if a (assumed opened) serial port is of any supported type. */
+/* See if an (assumed opened) serial port is of any supported type. */
 static int dev_is_supported(struct sr_serial_dev_inst *serial)
 {
-       if (!serial)
-               return 0;
-       if (!serial->lib_funcs)
+       if (!serial || !serial->lib_funcs)
                return 0;
 
        return 1;
@@ -270,9 +268,7 @@ SR_PRIV int serial_set_read_chunk_cb(struct sr_serial_dev_inst *serial,
  */
 SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial)
 {
-       if (!serial)
-               return;
-       if (!serial->rcv_buffer)
+       if (!serial || !serial->rcv_buffer)
                return;
 
        g_string_truncate(serial->rcv_buffer, 0);
@@ -288,9 +284,7 @@ SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial)
  */
 SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial)
 {
-       if (!serial)
-               return 0;
-       if (!serial->rcv_buffer)
+       if (!serial || !serial->rcv_buffer)
                return 0;
 
        return serial->rcv_buffer->len;
@@ -309,9 +303,7 @@ SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial)
 SR_PRIV void sr_ser_queue_rx_data(struct sr_serial_dev_inst *serial,
        const uint8_t *data, size_t len)
 {
-       if (!serial)
-               return;
-       if (!data || !len)
+       if (!serial || !data || !len)
                return;
 
        if (serial->rx_chunk_cb_func)
@@ -336,9 +328,7 @@ SR_PRIV size_t sr_ser_unqueue_rx_data(struct sr_serial_dev_inst *serial,
        size_t qlen;
        GString *buf;
 
-       if (!serial)
-               return 0;
-       if (!data || !len)
+       if (!serial || !data || !len)
                return 0;
 
        qlen = sr_ser_has_queued_data(serial);
@@ -1027,9 +1017,7 @@ SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id)
 /** @private */
 SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes)
 {
-       int bits, baud;
-       int ret;
-       int timeout_ms;
+       int bits, baud, ret, timeout_ms;
 
        /* Get the bitrate and frame length. */
        bits = baud = 0;
index 37a1a68b0ad2147d5b540c10b49ec53773fcb59f..8ed4523b8167ee1f42686d1ff9309f3b0f9c8c8f 100644 (file)
@@ -494,10 +494,8 @@ static int ser_bt_read(struct sr_serial_dev_inst *serial,
         * Immediately satisfy the caller's request from the RX buffer
         * if the requested amount of data is available already.
         */
-       if (sr_ser_has_queued_data(serial) >= count) {
-               rc = sr_ser_unqueue_rx_data(serial, buf, count);
-               return rc;
-       }
+       if (sr_ser_has_queued_data(serial) >= count)
+               return sr_ser_unqueue_rx_data(serial, buf, count);
 
        /*
         * When a timeout was specified, then determine the deadline
@@ -766,9 +764,8 @@ static void scan_cb(void *cb_args, const char *addr, const char *name)
 
        /* Check whether the device was seen before. */
        for (l = scan_args->addr_list; l; l = l->next) {
-               if (strcmp(addr, l->data) == 0) {
+               if (strcmp(addr, l->data) == 0)
                        return;
-               }
        }
 
        /* Substitute colons in the address by dashes. */
index d2776fc7d79cf2f789d3d62939c3b7892e764132..ee073d1dbbb509d60d7d62cdc69975c9d90e3f4b 100644 (file)
@@ -635,9 +635,8 @@ SR_PRIV const char *ser_hid_chip_find_name_vid_pid(uint16_t vid, uint16_t pid)
                if (!vid_pids)
                        continue;
                while (vid_pids->vid) {
-                       if (vid_pids->vid == vid && vid_pids->pid == pid) {
+                       if (vid_pids->vid == vid && vid_pids->pid == pid)
                                return desc->chipname;
-                       }
                        vid_pids++;
                }
        }
@@ -1298,10 +1297,8 @@ static int ser_hid_read(struct sr_serial_dev_inst *serial,
         * Immediately satisfy the caller's request from the RX buffer
         * if the requested amount of data is available already.
         */
-       if (sr_ser_has_queued_data(serial) >= count) {
-               rc = sr_ser_unqueue_rx_data(serial, buf, count);
-               return rc;
-       }
+       if (sr_ser_has_queued_data(serial) >= count)
+               return sr_ser_unqueue_rx_data(serial, buf, count);
 
        /*
         * When a timeout was specified, then determine the deadline
@@ -1387,9 +1384,8 @@ static int ser_hid_read(struct sr_serial_dev_inst *serial,
        if (got > count)
                got = count;
        sr_dbg("DBG: %s() passing %d bytes.", __func__, got);
-       rc = sr_ser_unqueue_rx_data(serial, buf, count);
 
-       return rc;
+       return sr_ser_unqueue_rx_data(serial, buf, count);
 }
 
 static struct ser_lib_functions serlib_hid = {