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
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 @@
     }
 
 exit:
-    close(fd);
+    if (fd >= 0)
+        close(fd);
     return ret;
 }
 
@@ -75,7 +76,7 @@
  *
  * @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 @@
     }
 
 exit:
-    close(fd);
+    if (fd >= 0)
+        close(fd);
     return ret;
 }