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 <redacted>
Tested-By: Michael Ströder <redacted>
{
struct sr_serial_dev_inst *serial;
uint8_t buffer[2];
{
struct sr_serial_dev_inst *serial;
uint8_t buffer[2];
buffer[0] = command >> 8;
buffer[1] = command;
buffer[0] = command >> 8;
buffer[1] = command;
if (!(serial = sdi->conn))
return SR_ERR;
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];
}
static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command)
{
struct sr_serial_dev_inst *serial;
uint8_t buffer[4];
buffer[0] = command >> 24;
buffer[1] = command >> 16;
buffer[0] = command >> 24;
buffer[1] = command >> 16;
if (!(serial = sdi->conn))
return SR_ERR;
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)
}
static void send_data(const struct sr_dev_inst *sdi, float sample)