summaryrefslogtreecommitdiff
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
parentbc50dff844b97e655483c9eaf0effeec6a9ab4dd (diff)
backlight: Set structure to safe values when not initialised
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--src/backlight.c23
-rw-r--r--src/backlight.h3
-rw-r--r--src/sna/sna_display.c1
3 files changed, 21 insertions, 6 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)
diff --git a/src/backlight.h b/src/backlight.h
index c251bd92..6391be76 100644
--- a/src/backlight.h
+++ b/src/backlight.h
@@ -38,12 +38,13 @@ enum backlight_type {
struct backlight {
char *iface;
enum backlight_type type;
- int max;
+ int original, max;
int pid, fd;
};
enum backlight_type backlight_exists(const char *iface);
+void backlight_init(struct backlight *backlight);
int backlight_open(struct backlight *backlight, char *iface);
int backlight_set(struct backlight *backlight, int level);
int backlight_get(struct backlight *backlight);
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index ffb8bb99..376f2618 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -3683,6 +3683,7 @@ reset:
output->driver_private = sna_output;
sna_output->base = output;
+ backlight_init(&sna_output->backlight);
if (sna_output->is_panel)
sna_output_backlight_init(output);