From: Gerhard Sittig Date: Fri, 2 Oct 2020 09:18:57 +0000 (+0200) Subject: pce-322a: unbreak send_command() return code X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a4be2b327be8;p=libsigrok.git pce-322a: unbreak send_command() return code Data was sent to the serial port, and the non-zero positive write length was mistaken as an error, since it did not match the SR_OK code's value. This snuck in with commit 379e95c587e1d in 2017-08. Rephrase the check for successful serial writes in the pce-322a driver. Pass on error codes from the serial layer in verbatim form. Check for the exact expected write length and derive SR_ERR_IO upon mismatch. Do return SR_OK upon success. Reported-By: Michael Ströder Tested-By: Michael Ströder --- diff --git a/src/hardware/pce-322a/protocol.c b/src/hardware/pce-322a/protocol.c index ee637e80..ee98c7c6 100644 --- a/src/hardware/pce-322a/protocol.c +++ b/src/hardware/pce-322a/protocol.c @@ -26,6 +26,7 @@ static int send_command(const struct sr_dev_inst *sdi, uint16_t command) { struct sr_serial_dev_inst *serial; uint8_t buffer[2]; + int ret; buffer[0] = command >> 8; buffer[1] = command; @@ -33,13 +34,20 @@ static int send_command(const struct sr_dev_inst *sdi, uint16_t command) if (!(serial = sdi->conn)) return SR_ERR; - return serial_write_blocking(serial, (const void *)buffer, 2, 0); + ret = serial_write_blocking(serial, buffer, sizeof(buffer), 0); + if (ret < 0) + return ret; + if ((size_t)ret != sizeof(buffer)) + return SR_ERR_IO; + + return SR_OK; } static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command) { struct sr_serial_dev_inst *serial; uint8_t buffer[4]; + int ret; buffer[0] = command >> 24; buffer[1] = command >> 16; @@ -49,7 +57,13 @@ static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command) if (!(serial = sdi->conn)) return SR_ERR; - return serial_write_blocking(serial, (const void *)buffer, 4, 0); + ret = serial_write_blocking(serial, buffer, sizeof(buffer), 0); + if (ret < 0) + return ret; + if ((size_t)ret != sizeof(buffer)) + return SR_ERR_IO; + + return SR_OK; } static void send_data(const struct sr_dev_inst *sdi, float sample)