summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/misc/apds990x_proxy.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/drivers/misc/apds990x_proxy.c b/drivers/misc/apds990x_proxy.c
index cd0c7e4..bcfee83 100644
--- a/drivers/misc/apds990x_proxy.c
+++ b/drivers/misc/apds990x_proxy.c
@@ -87,20 +87,12 @@ int read_proxy(void)
sleep(1);
fd = open(apds990x_dev.prox_raw, O_RDONLY);
- if (fd < 0) {
- retval = errno;
- fprintf(stderr, "%s: %s\n", apds990x_dev.prox_raw,
- strerror(errno));
- return retval;
- }
+ if (fd < 0)
+ goto error;
ret = read(fd, val, sizeof(val));
- if (ret < 0) {
- retval = errno;
- fprintf(stderr, "%s: %s\n",
- apds990x_dev.prox_raw, strerror(errno));
- break;
- }
+ if (ret < 0)
+ goto error;
/* replace EOF with \n */
val[ret-1] = '\n';
@@ -117,6 +109,12 @@ int read_proxy(void)
}
return retval;
+
+error:
+ retval = errno;
+ fprintf(stderr, "%s: %s\n", apds990x_dev.prox_raw, strerror(errno));
+ close(fd);
+ return retval;
}
void print_usage(char *name)