backlight: Set structure to safe values when not initialised

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2014-07-23 21:53:31 +01:00
parent bc50dff844
commit f9e7ac7db7
3 changed files with 21 additions and 6 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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);