Commit 6fabb2eb authored by Lucas Russo's avatar Lucas Russo

sm_io/protocols/*: fix buffer copying to/from chips/protocols

Theere were multiple trivial errors in the
handling of buffers, such as putting an extra
"&" to get the address and not copying the
read data back to user.
parent 88fb2869
......@@ -640,10 +640,10 @@ static ssize_t _i2c_write_generic (smpr_t *self, size_t size_offs, uint64_t offs
size_t trans_size = 0;
/* Copy address + data */
memcpy (&raw_data, &offs, size_offs);
memcpy (raw_data, &offs, size_offs);
trans_size += size_offs;
if (data != NULL) {
memcpy (&raw_data + size_offs, data, size);
memcpy (raw_data + size_offs, data, size);
trans_size += size;
}
......
......@@ -377,7 +377,7 @@ static ssize_t _spi_read_write_raw (smpr_t *self, size_t size, uint8_t *data,
if (mode == SPI_MODE_WRITE || mode == SPI_MODE_WRITE_READ) {
/* Copy data to temp */
uint8_t data_write[SPI_PROTO_REG_RXTX_NUM * SMPR_WB_REG_2_BYTE] = {0};
memcpy (data_write, data, size_align);
memcpy (data_write, data, size);
uint32_t i;
/* We write 32-bit at a time */
......@@ -480,22 +480,22 @@ static ssize_t _spi_read_write_generic (smpr_t *self, size_t size_offs, uint64_t
if (addr_msb) {
/* Copy address (MSB) + data */
if (data != NULL) {
memcpy (&raw_data, data, size);
memcpy (&raw_data + size, &offs, size_offs);
memcpy (raw_data, data, size);
memcpy (raw_data + size, &offs, size_offs);
trans_size += size + size_offs;
}
/* Only copy address to buffer */
else {
memcpy (&raw_data, &offs, size_offs);
memcpy (raw_data, &offs, size_offs);
trans_size += size_offs;
}
}
else {
/* Copy data (MSB) + address */
memcpy (&raw_data, &offs, size_offs);
memcpy (raw_data, &offs, size_offs);
trans_size += size_offs;
if (data != NULL) {
memcpy (&raw_data + size_offs, data, size);
memcpy (raw_data + size_offs, data, size);
trans_size += size;
}
}
......@@ -504,6 +504,9 @@ static ssize_t _spi_read_write_generic (smpr_t *self, size_t size_offs, uint64_t
ASSERT_TEST(err > 0 && (size_t) err == trans_size /* in bytes*/,
"Could not write data to SPI", err_exit, -1);
/* Copy the number of bytes request back to user */
memcpy (data, raw_data, size);
/* We return only the number of data bytes actually written, not addr+data */
err = size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment