diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-10-14 00:17:45 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-10-14 00:22:21 -0400 |
commit | d222ec102452790a07d27adfb297117b83d135bb (patch) | |
tree | 58d12a9c6628f82a2abfe29cc0f4cf359c4c8a64 /src/linux/analog.c | |
parent | 674f58419043c140468a7711d9fd565a0e1aaa25 (diff) | |
download | kutter-d222ec102452790a07d27adfb297117b83d135bb.tar.gz kutter-d222ec102452790a07d27adfb297117b83d135bb.tar.xz kutter-d222ec102452790a07d27adfb297117b83d135bb.zip |
linux: Make sure to close fd on analog/pca9685 init failure
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/linux/analog.c')
-rw-r--r-- | src/linux/analog.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/linux/analog.c b/src/linux/analog.c index c909e286..990f6c4a 100644 --- a/src/linux/analog.c +++ b/src/linux/analog.c @@ -26,14 +26,16 @@ gpio_adc_setup(uint8_t pin) int fd = open(fname, O_RDONLY|O_CLOEXEC); if (fd < 0) { report_errno("analog open", fd); - shutdown("Unable to open adc path"); + goto fail; } int ret = set_non_blocking(fd); - if (ret < 0) { - report_errno("analog set_non_blocking", ret); - shutdown("Unable to set non blocking on adc path"); - } + if (ret < 0) + goto fail; return (struct gpio_adc){ .fd = fd }; +fail: + if (fd >= 0) + close(fd); + shutdown("Unable to open adc device"); } uint32_t |