summaryrefslogtreecommitdiff
path: root/src/backlight.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2014-07-23 21:53:31 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2014-07-23 21:58:05 +0100
commitf9e7ac7db7b0331131aa1df3a90d4b2692949efa (patch)
tree233f7acaed59163113e9898734fe62eb9a471e18 /src/backlight.c
parentbc50dff844b97e655483c9eaf0effeec6a9ab4dd (diff)
backlight: Set structure to safe values when not initialised
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/backlight.c')
-rw-r--r--src/backlight.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/backlight.c b/src/backlight.c
index f0c549e5..72e6bfe7 100644
--- a/src/backlight.c
+++ b/src/backlight.c
@@ -74,6 +74,15 @@
* If only things were as simple as on OpenBSD! :)
*/
+void backlight_init(struct backlight *b)
+{
+ b->type = BL_NONE;
+ b->iface = NULL;
+ b->fd = -1;
+ b->pid = -1;
+ b->max = -1;
+}
+
#ifdef __OpenBSD__
#include <dev/wscons/wsconsio.h>
@@ -384,23 +393,27 @@ int backlight_open(struct backlight *b, char *iface)
if (iface == NULL)
iface = __backlight_find();
if (iface == NULL)
- return -1;
+ goto err;
b->type = __backlight_type(iface);
b->max = __backlight_read(iface, "max_brightness");
if (b->max <= 0)
- return -1;
+ goto err;
level = __backlight_read(iface, "brightness");
- if (level < 0)
- return -1;
+ if (level)
+ goto err;
if (!__backlight_direct_init(b, iface) &&
!__backlight_helper_init(b, iface))
- return -1;
+ goto err;
return level;
+
+err:
+ backlight_init(b);
+ return -1;
}
int backlight_set(struct backlight *b, int level)