mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 14:18:20 +00:00
i2c: Fix return status of i2c dev read/write
This commit is contained in:
@@ -43,11 +43,13 @@ static ssize_t i2c_dev_read(
|
||||
ssize_t n;
|
||||
|
||||
n = (*dev->read)(dev, buffer, count, iop->offset);
|
||||
if (n > 0) {
|
||||
if (n >= 0) {
|
||||
iop->offset += n;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(-n);
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t i2c_dev_write(
|
||||
@@ -60,11 +62,13 @@ static ssize_t i2c_dev_write(
|
||||
ssize_t n;
|
||||
|
||||
n = (*dev->write)(dev, buffer, count, iop->offset);
|
||||
if (n > 0) {
|
||||
if (n >= 0) {
|
||||
iop->offset += n;
|
||||
}
|
||||
|
||||
return n;
|
||||
return n;
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(-n);
|
||||
}
|
||||
}
|
||||
|
||||
static int i2c_dev_ioctl(
|
||||
|
||||
@@ -71,6 +71,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
test_device base;
|
||||
bool eio;
|
||||
unsigned current_address;
|
||||
uint8_t data[EEPROM_SIZE];
|
||||
} test_device_eeprom;
|
||||
@@ -198,6 +199,10 @@ static int test_eeprom_transfer(
|
||||
i2c_msg *msg = &msgs[0];
|
||||
uint32_t i;
|
||||
|
||||
if (dev->eio) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (msg_count > 0 && (msg->flags & I2C_M_RD) == 0) {
|
||||
if (msg->len < 1) {
|
||||
return -EIO;
|
||||
@@ -406,7 +411,7 @@ static void test_gpio_nxp_pca9535(void)
|
||||
rtems_test_assert(rv == 0);
|
||||
}
|
||||
|
||||
static void test_eeprom(void)
|
||||
static void test_eeprom(test_bus *bus)
|
||||
{
|
||||
int rv;
|
||||
int fd_in;
|
||||
@@ -442,6 +447,20 @@ static void test_eeprom(void)
|
||||
|
||||
memset(&out[0], 0, sizeof(out));
|
||||
|
||||
bus->eeprom.eio = true;
|
||||
|
||||
errno = 0;
|
||||
n = read(fd_in, &in[0], 1);
|
||||
rtems_test_assert(n == -1);
|
||||
rtems_test_assert(errno == EIO);
|
||||
|
||||
errno = 0;
|
||||
n = write(fd_out, &out[0], 1);
|
||||
rtems_test_assert(n == -1);
|
||||
rtems_test_assert(errno == EIO);
|
||||
|
||||
bus->eeprom.eio = false;
|
||||
|
||||
n = read(fd_in, &in[0], sizeof(in) + 1);
|
||||
rtems_test_assert(n == (ssize_t) sizeof(in));
|
||||
|
||||
@@ -608,7 +627,7 @@ static void test(void)
|
||||
rtems_test_assert(bus->base.timeout == 0);
|
||||
|
||||
test_simple_read_write(bus, fd);
|
||||
test_eeprom();
|
||||
test_eeprom(bus);
|
||||
test_gpio_nxp_pca9535();
|
||||
test_switch_nxp_pca9548a();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user