diff options
author | Christopher N. Hesse <raymanfx@gmail.com> | 2017-04-05 18:55:28 +0200 |
---|---|---|
committer | Christopher N. Hesse <raymanfx@gmail.com> | 2017-04-05 18:58:09 +0200 |
commit | e37aedde2e7f2afa69ac63bdfc80cc103b19469d (patch) | |
tree | 97f2f762f6406dd43a9b8675526fc5a586df4108 | |
parent | 235c2987671222299042c7d920f83e21c7632ebb (diff) | |
download | android_hardware_samsung-e37aedde2e7f2afa69ac63bdfc80cc103b19469d.tar.gz android_hardware_samsung-e37aedde2e7f2afa69ac63bdfc80cc103b19469d.tar.bz2 android_hardware_samsung-e37aedde2e7f2afa69ac63bdfc80cc103b19469d.zip |
lights: Put back fd checks before closing
While close(NULL) is indeed a harmless noop, fd can
end up being < 0 for us.
Change-Id: I56dcd7fb61c72d3ce750b13329ff42e11ab63c84
-rw-r--r-- | liblights/lights_helper.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/liblights/lights_helper.c b/liblights/lights_helper.c index 6ac18bf..be59399 100644 --- a/liblights/lights_helper.c +++ b/liblights/lights_helper.c @@ -31,7 +31,7 @@ * Reads an Integer from a file. * * @param path The absolute path string. - * @return The Integer with decimal base, -1 or errno on error. + * @return The Integer with decimal base, -1 or -errno on error. */ static int read_int(char const *path) { @@ -66,7 +66,8 @@ static int read_int(char const *path) } exit: - close(fd); + if (fd >= 0) + close(fd); return ret; } @@ -75,7 +76,7 @@ exit: * * @param path The absolute path string. * @param value The Integer value to be written. - * @return 0 on success, errno on error. + * @return 0 on success, -errno on error. */ static int write_int(char const *path, const int value) { @@ -100,7 +101,8 @@ static int write_int(char const *path, const int value) } exit: - close(fd); + if (fd >= 0) + close(fd); return ret; } |