From: Gerhard Sittig Date: Sun, 9 May 2021 17:27:22 +0000 (+0200) Subject: serial_libsp: extend diag in code path which opens serial ports X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ac1866b9236cd9271c17d2760441759f34befeb7;p=libsigrok.git serial_libsp: extend diag in code path which opens serial ports 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. --- diff --git a/src/serial_libsp.c b/src/serial_libsp.c index bfdc3202..7cf5a460 100644 --- a/src/serial_libsp.c +++ b/src/serial_libsp.c @@ -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)