From patchwork Tue Mar 10 08:03:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Rui X-Patchwork-Id: 10820 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n2A82Z4i026811 for ; Tue, 10 Mar 2009 08:02:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752958AbZCJICg (ORCPT ); Tue, 10 Mar 2009 04:02:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752842AbZCJICg (ORCPT ); Tue, 10 Mar 2009 04:02:36 -0400 Received: from mga11.intel.com ([192.55.52.93]:31222 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752165AbZCJICe (ORCPT ); Tue, 10 Mar 2009 04:02:34 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 10 Mar 2009 00:59:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.38,335,1233561600"; d="scan'208";a="671672472" Received: from rzhang-dt.sh.intel.com (HELO [10.239.36.218]) ([10.239.36.218]) by fmsmga001.fm.intel.com with ESMTP; 10 Mar 2009 01:06:20 -0700 Subject: [RFC PATCH 1/5] ACPI video: check the return value of acpi_video_device_lcd_get_level_current From: Zhang Rui To: linux-acpi Cc: Len Brown , trenn@suse.de, Matthew Garrett , "Zhang, Rui" Date: Tue, 10 Mar 2009 16:03:25 +0800 Message-Id: <1236672205.2820.119.camel@rzhang-dt> Mime-Version: 1.0 X-Mailer: Evolution 2.22.1 (2.22.1-2.fc9) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Subject: check the return value of acpi_video_device_lcd_get_level_current From: Zhang Rui check the return value of acpi_video_device_lcd_get_level_current Signed-off-by: Zhang Rui --- drivers/acpi/video.c | 69 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 22 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/drivers/acpi/video.c =================================================================== --- linux-2.6.orig/drivers/acpi/video.c +++ linux-2.6/drivers/acpi/video.c @@ -294,7 +294,7 @@ static int acpi_video_device_lcd_get_lev unsigned long long *level); static int acpi_video_get_next_level(struct acpi_video_device *device, u32 level_current, u32 event); -static void acpi_video_switch_brightness(struct acpi_video_device *device, +static int acpi_video_switch_brightness(struct acpi_video_device *device, int event); static int acpi_video_device_get_state(struct acpi_video_device *device, unsigned long long *state); @@ -308,7 +308,9 @@ static int acpi_video_get_brightness(str int i; struct acpi_video_device *vd = (struct acpi_video_device *)bl_get_data(bd); - acpi_video_device_lcd_get_level_current(vd, &cur_level); + + if (acpi_video_device_lcd_get_level_current(vd, &cur_level)) + return -EINVAL; for (i = 2; i < vd->brightness->count; i++) { if (vd->brightness->levels[i] == cur_level) /* The first two entries are special - see page 575 @@ -373,7 +375,8 @@ static int video_get_cur_state(struct th unsigned long long level; int state; - acpi_video_device_lcd_get_level_current(video, &level); + if (acpi_video_device_lcd_get_level_current(video, &level)) + return -EINVAL; for (state = 2; state < video->brightness->count; state++) if (level == video->brightness->levels[state]) return sprintf(buf, "%d\n", @@ -502,11 +505,29 @@ static int acpi_video_device_lcd_get_level_current(struct acpi_video_device *device, unsigned long long *level) { - if (device->cap._BQC) - return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, - level); + acpi_status status = AE_OK; + + if (device->cap._BQC) { + status = acpi_evaluate_integer(device->dev->handle, "_BQC", + NULL, level); + if (ACPI_SUCCESS(status)) { + device->brightness->curr = *level; + return 0; + } else { + /* Fixme: + * should we return an error or ignore this failure? + * dev->brightness->curr is a cached value which stores + * the correct current backlight level in most cases. + * ACPI video backlight still works w/ buggy _BQC. + * http://bugzilla.kernel.org/show_bug.cgi?id=12233 + */ + ACPI_WARNING((AE_INFO, "Evaluating _BQC failed")); + device->cap._BQC = 0; + } + } + *level = device->brightness->curr; - return AE_OK; + return 0; } static int @@ -773,18 +794,8 @@ static void acpi_video_device_find_cap(s device->backlight = backlight_device_register(name, NULL, device, &acpi_backlight_ops); device->backlight->props.max_brightness = device->brightness->count-3; - /* - * If there exists the _BQC object, the _BQC object will be - * called to get the current backlight brightness. Otherwise - * the brightness will be set to the maximum. - */ - if (device->cap._BQC) - device->backlight->props.brightness = - acpi_video_get_brightness(device->backlight); - else - device->backlight->props.brightness = - device->backlight->props.max_brightness; - backlight_update_status(device->backlight); + device->backlight->props.brightness = + acpi_video_get_brightness(device->backlight); kfree(name); device->cdev = thermal_cooling_device_register("LCD", @@ -1749,15 +1760,29 @@ acpi_video_get_next_level(struct acpi_vi } } -static void +static int acpi_video_switch_brightness(struct acpi_video_device *device, int event) { unsigned long long level_current, level_next; + int result = -EINVAL; + if (!device->brightness) - return; - acpi_video_device_lcd_get_level_current(device, &level_current); + goto out; + + result = acpi_video_device_lcd_get_level_current(device, + &level_current); + if (result) + goto out; + level_next = acpi_video_get_next_level(device, level_current, event); + acpi_video_device_lcd_set_level(device, level_next); + +out: + if (result) + printk(KERN_ERR PREFIX "Failed to switch the brightness\n"); + + return result; } static int