Skip to contentSkip to conversation

drivers/acpi/video: fix brightness allocation

PATCH Superseded Julia Jomantaite 3 participants 5 messages Jun 21, 2008 – Jun 27, 2008 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drivers/acpi/video: fix brightness allocation

This patch is to fix problem with device->brightness allocation.

drivers/acpi/video.c +75 -52
@@ -631,6 +631,75 @@
  *  	device	: video output device (LCD, CRT, ..)
  *
  *  Return Value:
+ *  	Maximum brightness level
+ *
+ *  Allocate and initialize device->brightness.
+ */
+ 
+static int
+acpi_video_init_brightness(struct acpi_video_device *device)
+{
+	union acpi_object *obj = NULL;
+	int i, max_level = 0, count = 0;
+	union acpi_object *o;
+	struct acpi_video_device_brightness *br = NULL;
+
+	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
+		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available " 
+						"LCD brightness level\n"));
+		goto out;
+	}
+
+	if (obj->package.count < 2)
+		goto out;
+
+	br = kzalloc(sizeof(*br), GFP_KERNEL);
+	if (!br) {
+		printk(KERN_ERR "can't allocate memory\n");
+		goto out;
+	}
+
+	br->levels = kmalloc(obj->package.count * sizeof *(br->levels), GFP_KERNEL);
+	if (!br->levels)
+		goto out_free;
+
+	for (i = 0; i < obj->package.count; i++) {
+		o = (union acpi_object *)&obj->package.elements[i];
+		if (o->type != ACPI_TYPE_INTEGER) {
+			printk(KERN_ERR PREFIX "Invalid data\n");
+			continue;
+		}
+		br->levels[count] = (u32) o->integer.value;
+
+		if (br->levels[count] > max_level)
+			max_level = br->levels[count];
+		count++;
+	}
+
+	if (count < 2)
+		goto out_free_levels;
+
+	br->count = count;
+	device->brightness = br;
+	ACPI_DEBUG_PRINT((ACPI_DB_INFO,	"found %d brightness levels\n",	count));
+	kfree(obj); 
+	return max_level;
+
+out_free_levels:
+	kfree(br->levels);
+out_free:
+	kfree(br);
+out:
+	device->brightness = NULL;
+	kfree(obj);
+	return 0;
+}
+
+/*
+ *  Arg:	
+ *  	device	: video output device (LCD, CRT, ..)
+ *
+ *  Return Value:
  *  	None
  *
  *  Find out all required AML methods defined under the output
@@ -640,10 +709,7 @@
 static void acpi_video_device_find_cap(struct acpi_video_device *device)
 {
 	acpi_handle h_dummy1;
-	int i;
 	u32 max_level = 0;
-	union acpi_object *obj = NULL;
-	struct acpi_video_device_brightness *br = NULL;
 
 
 	memset(&device->cap, 0, sizeof(device->cap));
@@ -657,8 +723,9 @@
 	if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
 		device->cap._BCM = 1;
 	}
-	if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
+	if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BQC", &h_dummy1))) {
 		device->cap._BQC = 1;
+	}
 	if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
 		device->cap._DDC = 1;
 	}
@@ -672,54 +739,8 @@
 		device->cap._DSS = 1;
 	}
 
-	if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
-
-		if (obj->package.count >= 2) {
-			int count = 0;
-			union acpi_object *o;
-
-			br = kzalloc(sizeof(*br), GFP_KERNEL);
-			if (!br) {
-				printk(KERN_ERR "can't allocate memory\n");
-			} else {
-				br->levels = kmalloc(obj->package.count *
-						     sizeof *(br->levels), GFP_KERNEL);
-				if (!br->levels)
-					goto out;
-
-				for (i = 0; i < obj->package.count; i++) {
-					o = (union acpi_object *)&obj->package.
-					    elements[i];
-					if (o->type != ACPI_TYPE_INTEGER) {
-						printk(KERN_ERR PREFIX "Invalid data\n");
-						continue;
-					}
-					br->levels[count] = (u32) o->integer.value;
-
-					if (br->levels[count] > max_level)
-						max_level = br->levels[count];
-					count++;
-				}
-			      out:
-				if (count < 2) {
-					kfree(br->levels);
-					kfree(br);
-				} else {
-					br->count = count;
-					device->brightness = br;
-					ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-							  "found %d brightness levels\n",
-							  count));
-				}
-			}
-		}
-
-	} else {
-		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
-	}
-
-	kfree(obj);
-
+	max_level = acpi_video_init_brightness(device);
+	
 	if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
 		int result;
 		static int count = 0;
@@ -1695,6 +1716,8 @@
 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
 {
 	unsigned long level_current, level_next;
+	if (!device->brightness) 
+		return;
 	acpi_video_device_lcd_get_level_current(device, &level_current);
 	level_next = acpi_video_get_next_level(device, level_current, event);
 	acpi_video_device_lcd_set_level(device, level_next);
#1 lore raw
Quoted 1 line · Julia Jomantaite

This patch is to fix problem with device->brightness allocation.

Looks good. Please run checkpatch to fix the coding style problems. :)

thanks,
rui

Quoted 198 lines
drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +16 -0
+0100
@@ -631,6 +631,75 @@
  *     device  : video output device (LCD, CRT, ..)
  *
  *  Return Value:
+ *     Maximum brightness level
+ *
+ *  Allocate and initialize device->brightness.
+ */
+
+static int
+acpi_video_init_brightness(struct acpi_video_device *device)
+{
+       union acpi_object *obj = NULL;
+       int i, max_level = 0, count = 0;
+       union acpi_object *o;
+       struct acpi_video_device_brightness *br = NULL;
+
+       if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device,
 &obj))) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query

available "
+ "LCD brightness level
\n"));

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +13 -0
+               goto out;
+       }
+
+       if (obj->package.count < 2)
+               goto out;
+
+       br = kzalloc(sizeof(*br), GFP_KERNEL);
+       if (!br) {
+               printk(KERN_ERR "can't allocate memory\n");
+               goto out;
+       }
+
+       br->levels = kmalloc(obj->package.count * sizeof

*(br->levels), GFP_KERNEL);

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +22 -0
+       if (!br->levels)
+               goto out_free;
+
+       for (i = 0; i < obj->package.count; i++) {
+               o = (union acpi_object *)&obj->package.elements[i];
+               if (o->type != ACPI_TYPE_INTEGER) {
+                       printk(KERN_ERR PREFIX "Invalid data\n");
+                       continue;
+               }
+               br->levels[count] = (u32) o->integer.value;
+
+               if (br->levels[count] > max_level)
+                       max_level = br->levels[count];
+               count++;
+       }
+
+       if (count < 2)
+               goto out_free_levels;
+
+       br->count = count;
+       device->brightness = br;
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels

\n", count));

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +18 -3
+       kfree(obj);
+       return max_level;
+
+out_free_levels:
+       kfree(br->levels);
+out_free:
+       kfree(br);
+out:
+       device->brightness = NULL;
+       kfree(obj);
+       return 0;
+}
+
+/*
+ *  Arg:      
+ *     device  : video output device (LCD, CRT, ..)
+ *
+ *  Return Value:
  *     None
  *
  *  Find out all required AML methods defined under the output
@@ -640,10 +709,7 @@
 static void acpi_video_device_find_cap(struct acpi_video_device
 *device)
 {
        acpi_handle h_dummy1;
-       int i;
        u32 max_level = 0;
-       union acpi_object *obj = NULL;
-       struct acpi_video_device_brightness *br = NULL;
 
 
        memset(&device->cap, 0, sizeof(device->cap));
drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +2 -1
@@ -657,8 +723,9 @@
        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM",
 &h_dummy1))) {
                device->cap._BCM = 1;
        }
-       if
 (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
+       if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BQC",
 &h_dummy1))) {
                device->cap._BQC = 1;
+       }
        if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC",
&h_dummy1))) {
                device->cap._DDC = 1;
        }
drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -11
@@ -672,54 +739,8 @@
                device->cap._DSS = 1;
        }
 
-       if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device,
 &obj))) {
-
-               if (obj->package.count >= 2) {
-                       int count = 0;
-                       union acpi_object *o;
-
-                       br = kzalloc(sizeof(*br), GFP_KERNEL);
-                       if (!br) {
-                               printk(KERN_ERR "can't allocate memory
 \n");
-                       } else {
-                               br->levels =

kmalloc(obj->package.count *
- sizeof
*(br->levels), GFP_KERNEL);

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +1 -5
-                               if (!br->levels)
-                                       goto out;
-
-                               for (i = 0; i < obj->package.count; i
++) {
-                                       o = (union acpi_object

*)&obj->package.

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -2
-                                           elements[i];
-                                       if (o->type !=

ACPI_TYPE_INTEGER) {
- printk(KERN_ERR PREFIX
"Invalid data\n");

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -3
-                                               continue;
-                                       }
-                                       br->levels[count] = (u32)

o->integer.value;

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -2
-
-                                       if (br->levels[count] >

max_level)
- max_level =
br->levels[count];

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -10
-                                       count++;
-                               }
-                             out:
-                               if (count < 2) {
-                                       kfree(br->levels);
-                                       kfree(br);
-                               } else {
-                                       br->count = count;
-                                       device->brightness = br;
-

ACPI_DEBUG_PRINT((ACPI_DB_INFO,
- "found %d
brightness levels\n",

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -7
-                                                         count));
-                               }
-                       }
-               }
-
-       } else {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query

available LCD brightness level\n"));

drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +2 -4
-       }
-
-       kfree(obj);
-
+       max_level = acpi_video_init_brightness(device);
+      
        if (device->cap._BCL && device->cap._BCM && device->cap._BQC
&& max_level > 0){
                int result;
                static int count = 0;
drivers/acpi/video.c 2008-06-21 11:40:46.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +2 -0
@@ -1695,6 +1716,8 @@
 acpi_video_switch_brightness(struct acpi_video_device *device, int
 event)
 {
        unsigned long level_current, level_next;
+       if (!device->brightness)
+               return;
        acpi_video_device_lcd_get_level_current(device,
 &level_current);

level_next = acpi_video_get_next_level(device, level_current,

event);
        acpi_video_device_lcd_set_level(device, level_next);
#2 lore raw

PATCH v3 1/1 drivers/acpi/video: fix brightness allocation

Fix use of uninitialized device->brightness.

---

drivers/acpi/video.c +73 -50
@@ -631,6 +631,76 @@ acpi_video_bus_DOS(struct acpi_video_bus
  *  	device	: video output device (LCD, CRT, ..)
  *
  *  Return Value:
+ *  	Maximum brightness level
+ *
+ *  Allocate and initialize device->brightness.
+ */
+
+static int
+acpi_video_init_brightness(struct acpi_video_device *device)
+{
+	union acpi_object *obj = NULL;
+	int i, max_level = 0, count = 0;
+	union acpi_object *o;
+	struct acpi_video_device_brightness *br = NULL;
+
+	if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
+		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available "
+						"LCD brightness level\n"));
+		goto out;
+	}
+
+	if (obj->package.count < 2)
+		goto out;
+
+	br = kzalloc(sizeof(*br), GFP_KERNEL);
+	if (!br) {
+		printk(KERN_ERR "can't allocate memory\n");
+		goto out;
+	}
+
+	br->levels = kmalloc(obj->package.count * sizeof *(br->levels),
+				GFP_KERNEL);
+	if (!br->levels)
+		goto out_free;
+
+	for (i = 0; i < obj->package.count; i++) {
+		o = (union acpi_object *)&obj->package.elements[i];
+		if (o->type != ACPI_TYPE_INTEGER) {
+			printk(KERN_ERR PREFIX "Invalid data\n");
+			continue;
+		}
+		br->levels[count] = (u32) o->integer.value;
+
+		if (br->levels[count] > max_level)
+			max_level = br->levels[count];
+		count++;
+	}
+
+	if (count < 2)
+		goto out_free_levels;
+
+	br->count = count;
+	device->brightness = br;
+	ACPI_DEBUG_PRINT((ACPI_DB_INFO,	"found %d brightness levels\n",	count));
+	kfree(obj);
+	return max_level;
+
+out_free_levels:
+	kfree(br->levels);
+out_free:
+	kfree(br);
+out:
+	device->brightness = NULL;
+	kfree(obj);
+	return 0;
+}
+
+/*
+ *  Arg:
+ *  	device	: video output device (LCD, CRT, ..)
+ *
+ *  Return Value:
  *  	None
  *
  *  Find out all required AML methods defined under the output
@@ -640,10 +710,7 @@ acpi_video_bus_DOS(struct acpi_video_bus
 static void acpi_video_device_find_cap(struct acpi_video_device *device)
 {
 	acpi_handle h_dummy1;
-	int i;
 	u32 max_level = 0;
-	union acpi_object *obj = NULL;
-	struct acpi_video_device_brightness *br = NULL;
 
 
 	memset(&device->cap, 0, sizeof(device->cap));
@@ -672,53 +739,7 @@ static void acpi_video_device_find_cap(s
 		device->cap._DSS = 1;
 	}
 
-	if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
-
-		if (obj->package.count >= 2) {
-			int count = 0;
-			union acpi_object *o;
-
-			br = kzalloc(sizeof(*br), GFP_KERNEL);
-			if (!br) {
-				printk(KERN_ERR "can't allocate memory\n");
-			} else {
-				br->levels = kmalloc(obj->package.count *
-						     sizeof *(br->levels), GFP_KERNEL);
-				if (!br->levels)
-					goto out;
-
-				for (i = 0; i < obj->package.count; i++) {
-					o = (union acpi_object *)&obj->package.
-					    elements[i];
-					if (o->type != ACPI_TYPE_INTEGER) {
-						printk(KERN_ERR PREFIX "Invalid data\n");
-						continue;
-					}
-					br->levels[count] = (u32) o->integer.value;
-
-					if (br->levels[count] > max_level)
-						max_level = br->levels[count];
-					count++;
-				}
-			      out:
-				if (count < 2) {
-					kfree(br->levels);
-					kfree(br);
-				} else {
-					br->count = count;
-					device->brightness = br;
-					ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-							  "found %d brightness levels\n",
-							  count));
-				}
-			}
-		}
-
-	} else {
-		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
-	}
-
-	kfree(obj);
+	max_level = acpi_video_init_brightness(device);
 
 	if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
 		int result;
@@ -1695,6 +1716,8 @@ static void
 acpi_video_switch_brightness(struct acpi_video_device *device, int event)
 {
 	unsigned long level_current, level_next;
+	if (!device->brightness)
+		return;
 	acpi_video_device_lcd_get_level_current(device, &level_current);
 	level_next = acpi_video_get_next_level(device, level_current, event);
 	acpi_video_device_lcd_set_level(device, level_next);
Acked-by on v3 1/1
#3 lore raw
Quoted 3 lines · Julia Jomantaite

Fix use of uninitialized device->brightness.

thanks,
rui

Quoted 182 lines

---

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +16 -0
+0100
@@ -631,6 +631,76 @@ acpi_video_bus_DOS(struct acpi_video_bus
  *     device  : video output device (LCD, CRT, ..)
  *
  *  Return Value:
+ *     Maximum brightness level
+ *
+ *  Allocate and initialize device->brightness.
+ */
+
+static int
+acpi_video_init_brightness(struct acpi_video_device *device)
+{
+       union acpi_object *obj = NULL;
+       int i, max_level = 0, count = 0;
+       union acpi_object *o;
+       struct acpi_video_device_brightness *br = NULL;
+
+       if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device,
 &obj))) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query

available "
+ "LCD brightness level
\n"));

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +13 -0
+               goto out;
+       }
+
+       if (obj->package.count < 2)
+               goto out;
+
+       br = kzalloc(sizeof(*br), GFP_KERNEL);
+       if (!br) {
+               printk(KERN_ERR "can't allocate memory\n");
+               goto out;
+       }
+
+       br->levels = kmalloc(obj->package.count * sizeof

*(br->levels),

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +23 -0
+                               GFP_KERNEL);
+       if (!br->levels)
+               goto out_free;
+
+       for (i = 0; i < obj->package.count; i++) {
+               o = (union acpi_object *)&obj->package.elements[i];
+               if (o->type != ACPI_TYPE_INTEGER) {
+                       printk(KERN_ERR PREFIX "Invalid data\n");
+                       continue;
+               }
+               br->levels[count] = (u32) o->integer.value;
+
+               if (br->levels[count] > max_level)
+                       max_level = br->levels[count];
+               count++;
+       }
+
+       if (count < 2)
+               goto out_free_levels;
+
+       br->count = count;
+       device->brightness = br;
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels

\n", count));

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +18 -3
+       kfree(obj);
+       return max_level;
+
+out_free_levels:
+       kfree(br->levels);
+out_free:
+       kfree(br);
+out:
+       device->brightness = NULL;
+       kfree(obj);
+       return 0;
+}
+
+/*
+ *  Arg:
+ *     device  : video output device (LCD, CRT, ..)
+ *
+ *  Return Value:
  *     None
  *
  *  Find out all required AML methods defined under the output
@@ -640,10 +710,7 @@ acpi_video_bus_DOS(struct acpi_video_bus
 static void acpi_video_device_find_cap(struct acpi_video_device
 *device)
 {
        acpi_handle h_dummy1;
-       int i;
        u32 max_level = 0;
-       union acpi_object *obj = NULL;
-       struct acpi_video_device_brightness *br = NULL;
 
 
        memset(&device->cap, 0, sizeof(device->cap));
drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -11
@@ -672,53 +739,7 @@ static void acpi_video_device_find_cap(s
                device->cap._DSS = 1;
        }
 
-       if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device,
 &obj))) {
-
-               if (obj->package.count >= 2) {
-                       int count = 0;
-                       union acpi_object *o;
-
-                       br = kzalloc(sizeof(*br), GFP_KERNEL);
-                       if (!br) {
-                               printk(KERN_ERR "can't allocate memory
 \n");
-                       } else {
-                               br->levels =

kmalloc(obj->package.count *
- sizeof
*(br->levels), GFP_KERNEL);

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +1 -5
-                               if (!br->levels)
-                                       goto out;
-
-                               for (i = 0; i < obj->package.count; i
++) {
-                                       o = (union acpi_object

*)&obj->package.

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -2
-                                           elements[i];
-                                       if (o->type !=

ACPI_TYPE_INTEGER) {
- printk(KERN_ERR PREFIX
"Invalid data\n");

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -3
-                                               continue;
-                                       }
-                                       br->levels[count] = (u32)

o->integer.value;

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -2
-
-                                       if (br->levels[count] >

max_level)
- max_level =
br->levels[count];

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -10
-                                       count++;
-                               }
-                             out:
-                               if (count < 2) {
-                                       kfree(br->levels);
-                                       kfree(br);
-                               } else {
-                                       br->count = count;
-                                       device->brightness = br;
-

ACPI_DEBUG_PRINT((ACPI_DB_INFO,
- "found %d
brightness levels\n",

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -7
-                                                         count));
-                               }
-                       }
-               }
-
-       } else {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query

available LCD brightness level\n"));

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +1 -3
-       }
-
-       kfree(obj);
+       max_level = acpi_video_init_brightness(device);
 
        if (device->cap._BCL && device->cap._BCM && device->cap._BQC
&& max_level > 0){
                int result;
drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +2 -0
@@ -1695,6 +1716,8 @@ static void
 acpi_video_switch_brightness(struct acpi_video_device *device, int
 event)
 {
        unsigned long level_current, level_next;
+       if (!device->brightness)
+               return;
        acpi_video_device_lcd_get_level_current(device,
 &level_current);

level_next = acpi_video_get_next_level(device, level_current,

event);
        acpi_video_device_lcd_set_level(device, level_next);
reviewer Applied
#4 lore raw
Quoted 7 lines · Zhang Rui
Quoted 3 lines · Julia Jomantaite

Fix use of uninitialized device->brightness.

applied.
thanks,
-Len

Quoted 188 lines
Quoted 178 lines

---

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +16 -0
+0100
@@ -631,6 +631,76 @@ acpi_video_bus_DOS(struct acpi_video_bus
  *     device  : video output device (LCD, CRT, ..)
  *
  *  Return Value:
+ *     Maximum brightness level
+ *
+ *  Allocate and initialize device->brightness.
+ */
+
+static int
+acpi_video_init_brightness(struct acpi_video_device *device)
+{
+       union acpi_object *obj = NULL;
+       int i, max_level = 0, count = 0;
+       union acpi_object *o;
+       struct acpi_video_device_brightness *br = NULL;
+
+       if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device,
 &obj))) {
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query

available "
+ "LCD brightness level
\n"));

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +13 -0
+               goto out;
+       }
+
+       if (obj->package.count < 2)
+               goto out;
+
+       br = kzalloc(sizeof(*br), GFP_KERNEL);
+       if (!br) {
+               printk(KERN_ERR "can't allocate memory\n");
+               goto out;
+       }
+
+       br->levels = kmalloc(obj->package.count * sizeof

*(br->levels),

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +23 -0
+                               GFP_KERNEL);
+       if (!br->levels)
+               goto out_free;
+
+       for (i = 0; i < obj->package.count; i++) {
+               o = (union acpi_object *)&obj->package.elements[i];
+               if (o->type != ACPI_TYPE_INTEGER) {
+                       printk(KERN_ERR PREFIX "Invalid data\n");
+                       continue;
+               }
+               br->levels[count] = (u32) o->integer.value;
+
+               if (br->levels[count] > max_level)
+                       max_level = br->levels[count];
+               count++;
+       }
+
+       if (count < 2)
+               goto out_free_levels;
+
+       br->count = count;
+       device->brightness = br;
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "found %d brightness levels

\n", count));

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +18 -3
+       kfree(obj);
+       return max_level;
+
+out_free_levels:
+       kfree(br->levels);
+out_free:
+       kfree(br);
+out:
+       device->brightness = NULL;
+       kfree(obj);
+       return 0;
+}
+
+/*
+ *  Arg:
+ *     device  : video output device (LCD, CRT, ..)
+ *
+ *  Return Value:
  *     None
  *
  *  Find out all required AML methods defined under the output
@@ -640,10 +710,7 @@ acpi_video_bus_DOS(struct acpi_video_bus
 static void acpi_video_device_find_cap(struct acpi_video_device
 *device)
 {
        acpi_handle h_dummy1;
-       int i;
        u32 max_level = 0;
-       union acpi_object *obj = NULL;
-       struct acpi_video_device_brightness *br = NULL;
 
 
        memset(&device->cap, 0, sizeof(device->cap));
drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -11
@@ -672,53 +739,7 @@ static void acpi_video_device_find_cap(s
                device->cap._DSS = 1;
        }
 
-       if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device,
 &obj))) {
-
-               if (obj->package.count >= 2) {
-                       int count = 0;
-                       union acpi_object *o;
-
-                       br = kzalloc(sizeof(*br), GFP_KERNEL);
-                       if (!br) {
-                               printk(KERN_ERR "can't allocate memory
 \n");
-                       } else {
-                               br->levels =

kmalloc(obj->package.count *
- sizeof
*(br->levels), GFP_KERNEL);

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +1 -5
-                               if (!br->levels)
-                                       goto out;
-
-                               for (i = 0; i < obj->package.count; i
++) {
-                                       o = (union acpi_object

*)&obj->package.

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -2
-                                           elements[i];
-                                       if (o->type !=

ACPI_TYPE_INTEGER) {
- printk(KERN_ERR PREFIX
"Invalid data\n");

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -3
-                                               continue;
-                                       }
-                                       br->levels[count] = (u32)

o->integer.value;

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -2
-
-                                       if (br->levels[count] >

max_level)
- max_level =
br->levels[count];

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -10
-                                       count++;
-                               }
-                             out:
-                               if (count < 2) {
-                                       kfree(br->levels);
-                                       kfree(br);
-                               } else {
-                                       br->count = count;
-                                       device->brightness = br;
-

ACPI_DEBUG_PRINT((ACPI_DB_INFO,
- "found %d
brightness levels\n",

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +0 -7
-                                                         count));
-                               }
-                       }
-               }
-
-       } else {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query

available LCD brightness level\n"));

drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +1 -3
-       }
-
-       kfree(obj);
+       max_level = acpi_video_init_brightness(device);
 
        if (device->cap._BCL && device->cap._BCM && device->cap._BQC
&& max_level > 0){
                int result;
drivers/acpi/video.c 2008-06-23 08:44:35.000000000 renamed from drivers/acpi/video.c 2008-06-12 17:15:08.000000000 +0100 +2 -0
@@ -1695,6 +1716,8 @@ static void
 acpi_video_switch_brightness(struct acpi_video_device *device, int
 event)
 {
        unsigned long level_current, level_next;
+       if (!device->brightness)
+               return;
        acpi_video_device_lcd_get_level_current(device,
 &level_current);

level_next = acpi_video_get_next_level(device, level_current,

Quoted 4 lines
event);
        acpi_video_device_lcd_set_level(device, level_next);

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html