All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Zhang Rui <rui.zhang@intel.com>,
	David Box <david.e.box@linux.intel.com>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Dave Olsthoorn <dave@bewaar.me>, Shujun Wang <wsj20369@163.com>
Subject: [PATCH v1 1/3] ACPI: power: Use u8 as the power resource state data type
Date: Mon, 24 May 2021 17:24:16 +0200	[thread overview]
Message-ID: <2786380.e9J7NaK4W3@kreacher> (raw)
In-Reply-To: <2074778.irdbgypaU6@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Use u8 as the data type for representing the state of an ACPI
power resource.

It is s not necessary to use int for that and because subsequent
changes are going to use ACPI_POWER_RESOURCE_STATE_UNKNOWN, it is
better to adjust the data type so that the "unknown" state is
represented by the "all ones" value.

While at it, clean up acpi_power_get_state() somewhat.

No intentional functional impact.

Tested-by: Dave Olsthoorn <dave@bewaar.me>
Tested-by: Shujun Wang <wsj20369@163.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/power.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

Index: linux-pm/drivers/acpi/power.c
===================================================================
--- linux-pm.orig/drivers/acpi/power.c
+++ linux-pm/drivers/acpi/power.c
@@ -182,10 +182,11 @@ int acpi_extract_power_resources(union a
 	return err;
 }
 
-static int acpi_power_get_state(acpi_handle handle, int *state)
+static int acpi_power_get_state(acpi_handle handle, u8 *state)
 {
 	acpi_status status = AE_OK;
 	unsigned long long sta = 0;
+	u8 cur_state;
 
 	if (!handle || !state)
 		return -EINVAL;
@@ -194,25 +195,24 @@ static int acpi_power_get_state(acpi_han
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 
-	*state = (sta & 0x01)?ACPI_POWER_RESOURCE_STATE_ON:
-			      ACPI_POWER_RESOURCE_STATE_OFF;
+	cur_state = sta & ACPI_POWER_RESOURCE_STATE_ON;
 
 	acpi_handle_debug(handle, "Power resource is %s\n",
-			  *state ? "on" : "off");
+			  cur_state ? "on" : "off");
 
+	*state = cur_state;
 	return 0;
 }
 
-static int acpi_power_get_list_state(struct list_head *list, int *state)
+static int acpi_power_get_list_state(struct list_head *list, u8 *state)
 {
 	struct acpi_power_resource_entry *entry;
-	int cur_state;
+	u8 cur_state = ACPI_POWER_RESOURCE_STATE_OFF;
 
 	if (!list || !state)
 		return -EINVAL;
 
 	/* The state of the list is 'on' IFF all resources are 'on'. */
-	cur_state = 0;
 	list_for_each_entry(entry, list, node) {
 		struct acpi_power_resource *resource = entry->resource;
 		acpi_handle handle = resource->device.handle;
@@ -592,7 +592,7 @@ int acpi_power_wakeup_list_init(struct l
 		struct acpi_power_resource *resource = entry->resource;
 		acpi_handle handle = resource->device.handle;
 		int result;
-		int state;
+		u8 state;
 
 		mutex_lock(&resource->resource_lock);
 
@@ -789,8 +789,8 @@ int acpi_disable_wakeup_device_power(str
 
 int acpi_power_get_inferred_state(struct acpi_device *device, int *state)
 {
+	u8 list_state = ACPI_POWER_RESOURCE_STATE_OFF;
 	int result = 0;
-	int list_state = 0;
 	int i = 0;
 
 	if (!device || !state)
@@ -919,7 +919,8 @@ struct acpi_device *acpi_add_power_resou
 	union acpi_object acpi_object;
 	struct acpi_buffer buffer = { sizeof(acpi_object), &acpi_object };
 	acpi_status status;
-	int state, result = -ENODEV;
+	int result;
+	u8 state;
 
 	acpi_bus_get_device(handle, &device);
 	if (device)
@@ -979,7 +980,8 @@ void acpi_resume_power_resources(void)
 	mutex_lock(&power_resource_list_lock);
 
 	list_for_each_entry(resource, &acpi_power_resource_list, list_node) {
-		int result, state;
+		int result;
+		u8 state;
 
 		mutex_lock(&resource->resource_lock);
 
@@ -1012,7 +1014,8 @@ static void acpi_power_turn_off_if_unuse
 		if (resource->users > 0)
 			return;
 	} else {
-		int result, state;
+		int result;
+		u8 state;
 
 		result = acpi_power_get_state(resource->device.handle, &state);
 		if (result || state == ACPI_POWER_RESOURCE_STATE_OFF)




  reply	other threads:[~2021-05-24 15:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-24 15:23 [PATCH v1 0/3] ACPI: power: Keep track of power resource states Rafael J. Wysocki
2021-05-24 15:24 ` Rafael J. Wysocki [this message]
2021-05-24 15:25 ` [PATCH v1 2/3] ACPI: power: Save the last known state of each power resource Rafael J. Wysocki
2021-05-24 15:26 ` [PATCH v1 3/3] ACPI: power: Rework turning off unused power resources 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=2786380.e9J7NaK4W3@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=dave@bewaar.me \
    --cc=david.e.box@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=wsj20369@163.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.