diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-26 09:53:52 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-11-26 09:56:01 +0100 |
commit | 90b0e28456560f3509cc03c5648d77d5b3f9ef36 (patch) | |
tree | cd31fbba881bca7596c13cc9805300a926771433 /cpukit/dev/i2c | |
parent | i2c: Avoid undefined right shift operation (diff) | |
download | rtems-90b0e28456560f3509cc03c5648d77d5b3f9ef36.tar.bz2 |
i2c: Do not close file descriptor 0 if open fails
Diffstat (limited to 'cpukit/dev/i2c')
-rw-r--r-- | cpukit/dev/i2c/i2c-dev.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/cpukit/dev/i2c/i2c-dev.c b/cpukit/dev/i2c/i2c-dev.c index cf1cf41ba8..76ae757eb0 100644 --- a/cpukit/dev/i2c/i2c-dev.c +++ b/cpukit/dev/i2c/i2c-dev.c @@ -218,19 +218,19 @@ static int i2c_dev_do_init( void (*destroy)(i2c_dev *dev) ) { - int fd; int rv; - fd = open(bus_path, O_RDWR); - if (fd < 0) { + dev->bus_fd = open(bus_path, O_RDWR); + if (dev->bus_fd < 0) { (*destroy)(dev); + return -1; } - rv = ioctl(fd, I2C_BUS_GET_CONTROL, &dev->bus); + rv = ioctl(dev->bus_fd, I2C_BUS_GET_CONTROL, &dev->bus); if (rv != 0) { - (void) close(fd); (*destroy)(dev); + return -1; } @@ -240,7 +240,6 @@ static int i2c_dev_do_init( dev->get_size = i2c_dev_get_size_default; dev->get_block_size = i2c_dev_get_block_size_default; dev->destroy = destroy; - dev->bus_fd = fd; dev->address = address; return 0; @@ -251,7 +250,7 @@ void i2c_dev_destroy(i2c_dev *dev) int rv; rv = close(dev->bus_fd); - _Assert(rv == 0); + _Assert(dev->bus_fd < 0 || rv == 0); (void) rv; } |