summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-26 09:53:52 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-11-26 09:56:01 +0100
commit90b0e28456560f3509cc03c5648d77d5b3f9ef36 (patch)
treecd31fbba881bca7596c13cc9805300a926771433
parentd6f0ca64a5932ee38fb5891dbce886e0b10f63e7 (diff)
downloadrtems-90b0e28456560f3509cc03c5648d77d5b3f9ef36.tar.bz2
i2c: Do not close file descriptor 0 if open fails
-rw-r--r--cpukit/dev/i2c/i2c-dev.c13
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;
}