Changeset 08135c85 in rtems


Ignore:
Timestamp:
Jul 23, 2015, 7:00:31 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
98a41f41
Parents:
19078dc6
Message:

i2c: Fix return status of i2c dev read/write

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/dev/i2c/i2c-dev.c

    r19078dc6 r08135c85  
    4444
    4545  n = (*dev->read)(dev, buffer, count, iop->offset);
    46   if (n > 0) {
     46  if (n >= 0) {
    4747    iop->offset += n;
    48   }
    49 
    50   return n;
     48
     49    return n;
     50  } else {
     51    rtems_set_errno_and_return_minus_one(-n);
     52  }
    5153}
    5254
     
    6163
    6264  n = (*dev->write)(dev, buffer, count, iop->offset);
    63   if (n > 0) {
     65  if (n >= 0) {
    6466    iop->offset += n;
    65   }
    66 
    67   return n;
     67
     68    return n;
     69  } else {
     70    rtems_set_errno_and_return_minus_one(-n);
     71  }
    6872}
    6973
  • testsuites/libtests/i2c01/init.c

    r19078dc6 r08135c85  
    7272typedef struct {
    7373  test_device base;
     74  bool eio;
    7475  unsigned current_address;
    7576  uint8_t data[EEPROM_SIZE];
     
    198199  i2c_msg *msg = &msgs[0];
    199200  uint32_t i;
     201
     202  if (dev->eio) {
     203    return -EIO;
     204  }
    200205
    201206  if (msg_count > 0 && (msg->flags & I2C_M_RD) == 0) {
     
    407412}
    408413
    409 static void test_eeprom(void)
     414static void test_eeprom(test_bus *bus)
    410415{
    411416  int rv;
     
    443448  memset(&out[0], 0, sizeof(out));
    444449
     450  bus->eeprom.eio = true;
     451
     452  errno = 0;
     453  n = read(fd_in, &in[0], 1);
     454  rtems_test_assert(n == -1);
     455  rtems_test_assert(errno == EIO);
     456
     457  errno = 0;
     458  n = write(fd_out, &out[0], 1);
     459  rtems_test_assert(n == -1);
     460  rtems_test_assert(errno == EIO);
     461
     462  bus->eeprom.eio = false;
     463
    445464  n = read(fd_in, &in[0], sizeof(in) + 1);
    446465  rtems_test_assert(n == (ssize_t) sizeof(in));
     
    609628
    610629  test_simple_read_write(bus, fd);
    611   test_eeprom();
     630  test_eeprom(bus);
    612631  test_gpio_nxp_pca9535();
    613632  test_switch_nxp_pca9548a();
Note: See TracChangeset for help on using the changeset viewer.