]> git.karo-electronics.de Git - linux-beck.git/commitdiff
leds: trigger: ledtrig-backlight: Fix invalid memory access in fb_event notification...
authorManfred Schlaegl <manfred.schlaegl@gmx.at>
Tue, 13 Aug 2013 11:17:05 +0000 (04:17 -0700)
committerBryan Wu <cooloney@gmail.com>
Tue, 27 Aug 2013 00:46:36 +0000 (17:46 -0700)
fb_notifier_callback is called on any event fired by
fb_notifier_call_chain. Events may, or may not contain some data
(fb_event.data). In case of FB_EVENT_BLANK fb_event.data contains a
pointer to an integer holdingthe blank state. The Problem is, that in
ledtrig-backlight.c - fb_notifier_callback the pointer to blank state
is dereferenced BEFORE the event-type is checked.

Obviously this leads to problems with other events than FB_EVENT_BLANK,
where fb_event.data is undefined or NULL. It seems, that this problem
existed ever since the driver was added.

Like in drivers/video/backlight/backlight.c line 43 I would suggest to
return immediately on events other than FB_EVENT_BLANK.

Signed-off-by: Manfred Schlaegl <manfred.schlaegl@gmx.at>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
drivers/leds/trigger/ledtrig-backlight.c

index 3c9c88a07eb8e45b42e78704940feb3ce4ff804c..47e55aa9eefae1571b4f45060a0532d9733019ec 100644 (file)
@@ -36,26 +36,28 @@ static int fb_notifier_callback(struct notifier_block *p,
                                        struct bl_trig_notifier, notifier);
        struct led_classdev *led = n->led;
        struct fb_event *fb_event = data;
-       int *blank = fb_event->data;
-       int new_status = *blank ? BLANK : UNBLANK;
+       int *blank;
+       int new_status;
 
-       switch (event) {
-       case FB_EVENT_BLANK:
-               if (new_status == n->old_status)
-                       break;
+       /* If we aren't interested in this event, skip it immediately ... */
+       if (event != FB_EVENT_BLANK)
+               return 0;
 
-               if ((n->old_status == UNBLANK) ^ n->invert) {
-                       n->brightness = led->brightness;
-                       __led_set_brightness(led, LED_OFF);
-               } else {
-                       __led_set_brightness(led, n->brightness);
-               }
+       blank = fb_event->data;
+       new_status = *blank ? BLANK : UNBLANK;
 
-               n->old_status = new_status;
+       if (new_status == n->old_status)
+               return 0;
 
-               break;
+       if ((n->old_status == UNBLANK) ^ n->invert) {
+               n->brightness = led->brightness;
+               __led_set_brightness(led, LED_OFF);
+       } else {
+               __led_set_brightness(led, n->brightness);
        }
 
+       n->old_status = new_status;
+
        return 0;
 }