From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alexey Starikovskiy <astarikovskiy@suse.de>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>
Subject: Re: [PATCH 10/12] ACPI: power: don't cache power resource state
Date: Wed, 24 Oct 2007 23:57:23 +0200 [thread overview]
Message-ID: <200710242357.23344.rjw@sisk.pl> (raw)
In-Reply-To: <20071022101909.2937.14958.stgit@samsung>
On Monday, 22 October 2007 12:19, Alexey Starikovskiy wrote:
> ACPI may change power resource state behind our back, so don't
> keep our local copy, which may not be valid.
>
> Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
> ---
>
> drivers/acpi/bus.c | 6 ++---
> drivers/acpi/power.c | 63 +++++++++++++++++++-------------------------------
> 2 files changed, 26 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index fb2cff9..fdee82d 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -198,11 +198,9 @@ int acpi_bus_set_power(acpi_handle handle, int state)
> return -ENODEV;
> }
> /*
> - * Get device's current power state if it's unknown
> - * This means device power state isn't initialized or previous setting failed
> + * Get device's current power state
> */
> - if ((device->power.state == ACPI_STATE_UNKNOWN) || device->flags.force_power_state)
> - acpi_bus_get_power(device->handle, &device->power.state);
> + acpi_bus_get_power(device->handle, &device->power.state);
> if ((state == device->power.state) && !device->flags.force_power_state) {
> ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
> state));
> diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
> index 57b9a29..af1769a 100644
> --- a/drivers/acpi/power.c
> +++ b/drivers/acpi/power.c
> @@ -86,7 +86,6 @@ struct acpi_power_resource {
> acpi_bus_id name;
> u32 system_level;
> u32 order;
> - int state;
> struct mutex resource_lock;
> struct list_head reference;
> };
> @@ -128,33 +127,31 @@ acpi_power_get_context(acpi_handle handle,
> return 0;
> }
>
> -static int acpi_power_get_state(struct acpi_power_resource *resource)
> +static int acpi_power_get_state(struct acpi_power_resource *resource, int *state)
> {
> acpi_status status = AE_OK;
> unsigned long sta = 0;
>
>
> - if (!resource)
> + if (!resource || !state)
> return -EINVAL;
>
> status = acpi_evaluate_integer(resource->device->handle, "_STA", NULL, &sta);
> if (ACPI_FAILURE(status))
> return -ENODEV;
>
> - if (sta & 0x01)
> - resource->state = ACPI_POWER_RESOURCE_STATE_ON;
> - else
> - resource->state = ACPI_POWER_RESOURCE_STATE_OFF;
> + *state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON:
> + ACPI_POWER_RESOURCE_STATE_OFF;
>
> ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] is %s\n",
> - resource->name, resource->state ? "on" : "off"));
> + resource->name, state ? "on" : "off"));
>
> return 0;
> }
>
> static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
> {
> - int result = 0;
> + int result = 0, state1;
This is a tiny bit inconsistent with the instances below where the local
variable is called "state" (ie. without the "1"). I'd just call the argument "state_p"
and the auxiliary variable "state".
> struct acpi_power_resource *resource = NULL;
> u32 i = 0;
>
> @@ -168,11 +165,11 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
> result = acpi_power_get_context(list->handles[i], &resource);
> if (result)
> return result;
> - result = acpi_power_get_state(resource);
> + result = acpi_power_get_state(resource, &state1);
> if (result)
> return result;
>
> - *state = resource->state;
> + *state = state1;
>
> if (*state != ACPI_POWER_RESOURCE_STATE_ON)
> break;
> @@ -186,7 +183,7 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
>
> static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
> {
> - int result = 0;
> + int result = 0, state;
> int found = 0;
> acpi_status status = AE_OK;
> struct acpi_power_resource *resource = NULL;
> @@ -224,20 +221,14 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
> }
> mutex_unlock(&resource->resource_lock);
>
> - if (resource->state == ACPI_POWER_RESOURCE_STATE_ON) {
> - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already on\n",
> - resource->name));
> - return 0;
> - }
> -
> status = acpi_evaluate_object(resource->device->handle, "_ON", NULL, NULL);
> if (ACPI_FAILURE(status))
> return -ENODEV;
>
> - result = acpi_power_get_state(resource);
> + result = acpi_power_get_state(resource, &state);
> if (result)
> return result;
> - if (resource->state != ACPI_POWER_RESOURCE_STATE_ON)
> + if (state != ACPI_POWER_RESOURCE_STATE_ON)
> return -ENOEXEC;
>
> /* Update the power resource's _device_ power state */
> @@ -250,7 +241,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
>
> static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
> {
> - int result = 0;
> + int result = 0, state;
> acpi_status status = AE_OK;
> struct acpi_power_resource *resource = NULL;
> struct list_head *node, *next;
> @@ -281,20 +272,14 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
> }
> mutex_unlock(&resource->resource_lock);
>
> - if (resource->state == ACPI_POWER_RESOURCE_STATE_OFF) {
> - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Resource [%s] already off\n",
> - resource->name));
> - return 0;
> - }
> -
> status = acpi_evaluate_object(resource->device->handle, "_OFF", NULL, NULL);
> if (ACPI_FAILURE(status))
> return -ENODEV;
>
> - result = acpi_power_get_state(resource);
> + result = acpi_power_get_state(resource, &state);
> if (result)
> return result;
> - if (resource->state != ACPI_POWER_RESOURCE_STATE_OFF)
> + if (state != ACPI_POWER_RESOURCE_STATE_OFF)
> return -ENOEXEC;
>
> /* Update the power resource's _device_ power state */
> @@ -494,7 +479,7 @@ static struct proc_dir_entry *acpi_power_dir;
> static int acpi_power_seq_show(struct seq_file *seq, void *offset)
> {
> int count = 0;
> - int result = 0;
> + int result = 0, state;
> struct acpi_power_resource *resource = NULL;
> struct list_head *node, *next;
> struct acpi_power_reference *ref;
> @@ -505,12 +490,12 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
> if (!resource)
> goto end;
>
> - result = acpi_power_get_state(resource);
> + result = acpi_power_get_state(resource, &state);
> if (result)
> goto end;
>
> seq_puts(seq, "state: ");
> - switch (resource->state) {
> + switch (state) {
> case ACPI_POWER_RESOURCE_STATE_ON:
> seq_puts(seq, "on\n");
> break;
> @@ -591,7 +576,7 @@ static int acpi_power_remove_fs(struct acpi_device *device)
>
> static int acpi_power_add(struct acpi_device *device)
> {
> - int result = 0;
> + int result = 0, state;
> acpi_status status = AE_OK;
> struct acpi_power_resource *resource = NULL;
> union acpi_object acpi_object;
> @@ -622,11 +607,11 @@ static int acpi_power_add(struct acpi_device *device)
> resource->system_level = acpi_object.power_resource.system_level;
> resource->order = acpi_object.power_resource.resource_order;
>
> - result = acpi_power_get_state(resource);
> + result = acpi_power_get_state(resource, &state);
> if (result)
> goto end;
>
> - switch (resource->state) {
> + switch (state) {
> case ACPI_POWER_RESOURCE_STATE_ON:
> device->power.state = ACPI_STATE_D0;
> break;
> @@ -643,7 +628,7 @@ static int acpi_power_add(struct acpi_device *device)
> goto end;
>
> printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device),
> - acpi_device_bid(device), resource->state ? "on" : "off");
> + acpi_device_bid(device), state ? "on" : "off");
>
> end:
> if (result)
> @@ -680,7 +665,7 @@ static int acpi_power_remove(struct acpi_device *device, int type)
>
> static int acpi_power_resume(struct acpi_device *device)
> {
> - int result = 0;
> + int result = 0, state;
> struct acpi_power_resource *resource = NULL;
> struct acpi_power_reference *ref;
>
> @@ -689,12 +674,12 @@ static int acpi_power_resume(struct acpi_device *device)
>
> resource = (struct acpi_power_resource *)acpi_driver_data(device);
>
> - result = acpi_power_get_state(resource);
> + result = acpi_power_get_state(resource, &state);
> if (result)
> return result;
>
> mutex_lock(&resource->resource_lock);
> - if ((resource->state == ACPI_POWER_RESOURCE_STATE_OFF) &&
> + if (state == ACPI_POWER_RESOURCE_STATE_OFF &&
> !list_empty(&resource->reference)) {
> ref = container_of(resource->reference.next, struct acpi_power_reference, node);
> mutex_unlock(&resource->resource_lock);
>
>
>
--
"Premature optimization is the root of all evil." - Donald Knuth
next prev parent reply other threads:[~2007-10-24 21:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071022101535.2937.79385.stgit@samsung>
[not found] ` <20071022101921.2937.66363.stgit@samsung>
2007-10-24 21:51 ` [PATCH 12/12] ACPI: Fan: Drop force_power_state acpi_device option Rafael J. Wysocki
[not found] ` <20071022101915.2937.5590.stgit@samsung>
2007-10-24 21:52 ` [PATCH 11/12] ACPI: Fan: fan device does not need own structure Rafael J. Wysocki
[not found] ` <20071022101909.2937.14958.stgit@samsung>
2007-10-24 21:57 ` Rafael J. Wysocki [this message]
[not found] ` <20071022101903.2937.29352.stgit@samsung>
2007-10-24 21:59 ` [PATCH 09/12] ACPI: EC: Output changes to operational mode Rafael J. Wysocki
[not found] ` <20071022101850.2937.81791.stgit@samsung>
2007-10-24 22:05 ` [PATCH 07/12] ACPI: EC: Don't re-enable GPE for each transaction Rafael J. Wysocki
[not found] ` <20071022101812.2937.49361.stgit@samsung>
2007-10-24 22:07 ` [PATCH 02/12] ACPI: suspend: Wrong order of GPE restore Rafael J. Wysocki
[not found] ` <20071022101805.2937.92527.stgit@samsung>
2007-10-24 22:10 ` [PATCH 01/12] ACPI: sleep: Fix GPE suspend cleanup Rafael J. Wysocki
[not found] ` <20071022101818.2937.8977.stgit@samsung>
2007-10-24 22:11 ` [PATCH 03/12] ACPI: button: send initial lid state after add and resume Rafael J. Wysocki
[not found] ` <20071022101830.2937.52617.stgit@samsung>
2007-10-24 22:14 ` [PATCH 04/12] ACPI: EC: Replace atomic variables with bits Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200710242357.23344.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=astarikovskiy@suse.de \
--cc=linux-acpi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox