]> sigrok.org Git - libsigrok.git/commitdiff
serial_libsp: extend diag in code path which opens serial ports
authorGerhard Sittig <redacted>
Sun, 9 May 2021 17:27:22 +0000 (19:27 +0200)
committerGerhard Sittig <redacted>
Sat, 22 May 2021 05:59:18 +0000 (07:59 +0200)
Opening a serial port involves two libserialport calls, while only the
second call's return value gets inspected. Check the lookup before the
open, too, and provide its details in a diag message.

src/serial_libsp.c

index bfdc3202261c8adfb198fff28a8c80a29ccf07fe..7cf5a4602efbea26aef1a58886ca1667625bed8c 100644 (file)
@@ -55,7 +55,14 @@ static int sr_ser_libsp_open(struct sr_serial_dev_inst *serial, int flags)
        char *error;
        int sp_flags;
 
-       sp_get_port_by_name(serial->port, &serial->sp_data);
+       ret = sp_get_port_by_name(serial->port, &serial->sp_data);
+       if (ret != SP_OK) {
+               error = sp_last_error_message();
+               sr_err("Error getting port from name %s: (%d) %s.",
+                       serial->port, sp_last_error_code(), error);
+               sp_free_error_message(error);
+               return SR_ERR;
+       }
 
        sp_flags = 0;
        if (flags & SERIAL_RDWR)