Hi Folks

Patches are attached and both have explanatory commit messages.


Daniel.
>From 657a3ed2b89bb0c351ca733e0f880868d2201636 Mon Sep 17 00:00:00 2001
From: Daniel Thompson <[email protected]>
Date: Thu, 19 Sep 2013 16:34:05 +0100
Subject: [PATCH 1/2] agilent-dmm: Fix SEGV during incomplete reply from meter.

If bug contains exactly 20 characters (i.e. "Agilent Technologies") then
strcmp() will succeed by the NULL delimiter will be found in tokens[1].

Signed-off-by: Daniel Thompson <[email protected]>

diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c
index 34fa92a..4a1274d 100644
--- a/hardware/agilent-dmm/api.c
+++ b/hardware/agilent-dmm/api.c
@@ -129,7 +129,7 @@ static GSList *scan(GSList *options)
 
        tokens = g_strsplit(buf, ",", 4);
        if (!strcmp("Agilent Technologies", tokens[0])
-                       && tokens[2] && tokens[3]) {
+                       && tokens[1] && tokens[2] && tokens[3]) {
                for (i = 0; supported_agdmm[i].model; i++) {
                        if (strcmp(supported_agdmm[i].modelname, tokens[1]))
                                continue;
-- 
1.8.3.1

>From 790157b7d28260c467a1d0e5700e99c42fb83efe Mon Sep 17 00:00:00 2001
From: Daniel Thompson <[email protected]>
Date: Thu, 19 Sep 2013 16:39:24 +0100
Subject: [PATCH 2/2] serial: Only sleep when no characters are received.

g_usleep(XX) sleeps for *at least* XX microseconds but may sleep for
longers (on older kernels the sleep will typically be 10000us). Thus
byte receive loops containing an unconditional sleep will perform
very poorly (for example it causes the scan in agilent-dmm to timeout
prematurely).

Even on modern kernels serial_readline() has a 2ms sleep per byte which
means it will read at a maximum rate of half a character per millisecond
(~4800baud).

This is fixed by only sleeping when read() returns no data.

Signed-off-by: Daniel Thompson <[email protected]>

diff --git a/hardware/common/serial.c b/hardware/common/serial.c
index 306b889..557022c 100644
--- a/hardware/common/serial.c
+++ b/hardware/common/serial.c
@@ -786,7 +786,8 @@ SR_PRIV int serial_readline(struct sr_serial_dev_inst 
*serial, char **buf,
                if (g_get_monotonic_time() - start > timeout_ms)
                        /* Timeout */
                        break;
-               g_usleep(2000);
+               if (len < 1)
+                       g_usleep(2000);
        }
        if (*buflen)
                sr_dbg("Received %d: '%s'.", *buflen, *buf);
@@ -867,7 +868,8 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst 
*serial,
                        sr_dbg("Detection timed out after %dms.", time);
                        break;
                }
-               g_usleep(byte_delay_us);
+               if (len < 1)
+                       g_usleep(byte_delay_us);
        }
 
        *buflen = ibuf;
-- 
1.8.3.1

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to