From 31823fd581e092ec6d32620e87f4bd6c7a44e568 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Fri, 2 Nov 2007 13:53:03 +0100 Subject: [PATCH] ACPI: Video: Validate brightness level before setting it. The ACPI spec, section B.6.3, requests that the OS should only send values that were reported by _BCL when invoking _BCM. Signed-off-by: Danny Baumann --- drivers/acpi/video.c | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 0bf9ccc..bcffcec 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c @@ -414,6 +414,21 @@ acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) struct acpi_object_list args = { 1, &arg0 }; + if (device->cap._BCL) { + int i; + + /* validate through the list of available levels as + requested in ACPI spec section B.6.3 */ + for (i = 0; i < device->brightness->count; i++) + if (level == device->brightness->levels[i]) + break; + + if (i == device->brightness->count) { + /* didn't find a valid level */ + return_ACPI_STATUS(AE_BAD_PARAMETER); + } + } + arg0.integer.value = level; if (device->cap._BCM) @@ -898,7 +913,6 @@ acpi_video_device_write_brightness(struct file *file, struct acpi_video_device *dev = m->private; char str[5] = { 0 }; unsigned int level = 0; - int i; if (!dev || !dev->brightness || count + 1 > sizeof str) @@ -913,14 +927,8 @@ acpi_video_device_write_brightness(struct file *file, if (level > 100) return -EFAULT; - /* validate through the list of available levels */ - for (i = 0; i < dev->brightness->count; i++) - if (level == dev->brightness->levels[i]) { - if (ACPI_SUCCESS - (acpi_video_device_lcd_set_level(dev, level))) - dev->brightness->curr = level; - break; - } + if (ACPI_SUCCESS(acpi_video_device_lcd_set_level(dev, level))) + dev->brightness->curr = level; return count; } -- 1.5.3.3