[rtems commit] i2c: Do not close file descriptor 0 if open fails
Sebastian Huber
sebh at rtems.org
Wed Nov 26 08:59:24 UTC 2014
Module: rtems
Branch: master
Commit: 90b0e28456560f3509cc03c5648d77d5b3f9ef36
Changeset: http://git.rtems.org/rtems/commit/?id=90b0e28456560f3509cc03c5648d77d5b3f9ef36
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Nov 26 09:53:52 2014 +0100
i2c: Do not close file descriptor 0 if open fails
---
cpukit/dev/i2c/i2c-dev.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/cpukit/dev/i2c/i2c-dev.c b/cpukit/dev/i2c/i2c-dev.c
index cf1cf41..76ae757 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;
}
More information about the vc
mailing list