linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Len Brown <len.brown@intel.com>
To: linux-acpi@vger.kernel.org
Cc: Alexey Starikovskiy <astarikivskiy@suse.de>,
	Alexey Starikovskiy <astarikovskiy@suse.de>,
	Len Brown <len.brown@intel.com>
Subject: [PATCH 09/12] ACPI: Battery: Synchronize battery operations.
Date: Fri,  3 Aug 2007 18:33:42 -0400	[thread overview]
Message-ID: <11861804344148-git-send-email-len.brown@intel.com> (raw)
Message-ID: <3bd92ba19a89fe61ebf58804f9c8675372f50c1c.1186180370.git.len.brown@intel.com> (raw)
In-Reply-To: <11861804251625-git-send-email-len.brown@intel.com>
In-Reply-To: <67effe8fff32f60bdf51cba484766ba6003005bb.1186180370.git.len.brown@intel.com>

From: Alexey Starikovskiy <astarikivskiy@suse.de>

http://bugzilla.kernel.org/show_bug.cgi?id=8768

Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
Signed-off-by: Len Brown <len.brown@intel.com>
---
 drivers/acpi/battery.c |   47 +++++++++++++++++------------------------------
 1 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 8165103..d7b499f 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -113,7 +113,7 @@ struct acpi_battery_info {
 	acpi_string oem_info;
 };
 
-enum acpi_battery_files{
+enum acpi_battery_files {
 	ACPI_BATTERY_INFO = 0,
 	ACPI_BATTERY_STATE,
 	ACPI_BATTERY_ALARM,
@@ -129,13 +129,14 @@ struct acpi_battery_flags {
 };
 
 struct acpi_battery {
-	struct mutex mutex;
 	struct acpi_device *device;
 	struct acpi_battery_flags flags;
 	struct acpi_buffer bif_data;
 	struct acpi_buffer bst_data;
+	struct mutex lock;
 	unsigned long alarm;
 	unsigned long update_time[ACPI_BATTERY_NUMFILES];
+
 };
 
 inline int acpi_battery_present(struct acpi_battery *battery)
@@ -235,10 +236,10 @@ static int acpi_battery_get_info(struct acpi_battery *battery)
 		return 0;
 
 	/* Evaluate _BIF */
-
-	status =
-	    acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL,
-				 &buffer);
+	mutex_lock(&battery->lock);
+	status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF",
+				      NULL, &buffer);
+	mutex_unlock(&battery->lock);
 	if (ACPI_FAILURE(status)) {
 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
 		return -ENODEV;
@@ -285,10 +286,10 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
 		return 0;
 
 	/* Evaluate _BST */
-
-	status =
-	    acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL,
-				 &buffer);
+	mutex_lock(&battery->lock);
+	status = acpi_evaluate_object(acpi_battery_handle(battery), "_BST",
+				      NULL, &buffer);
+	mutex_unlock(&battery->lock);
 	if (ACPI_FAILURE(status)) {
 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
 		return -ENODEV;
@@ -336,9 +337,10 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery,
 
 	arg0.integer.value = alarm;
 
-	status =
-	    acpi_evaluate_object(acpi_battery_handle(battery), "_BTP",
+	mutex_lock(&battery->lock);
+	status = acpi_evaluate_object(acpi_battery_handle(battery), "_BTP",
 				 &arg_list, NULL);
+	mutex_unlock(&battery->lock);
 	if (ACPI_FAILURE(status))
 		return -ENODEV;
 
@@ -658,8 +660,6 @@ acpi_battery_write_alarm(struct file *file,
 	if (!battery || (count > sizeof(alarm_string) - 1))
 		return -EINVAL;
 
-	mutex_lock(&battery->mutex);
-
 	result = acpi_battery_update(battery, 1, &update_result);
 	if (result) {
 		result = -ENODEV;
@@ -688,9 +688,7 @@ acpi_battery_write_alarm(struct file *file,
 	acpi_battery_check_result(battery, result);
 
 	if (!result)
-		result = count;
-
-	mutex_unlock(&battery->mutex);
+		return count;
 
 	return result;
 }
@@ -714,8 +712,6 @@ static int acpi_battery_read(int fid, struct seq_file *seq)
 	int update_result = ACPI_BATTERY_NONE_UPDATE;
 	int update = 0;
 
-	mutex_lock(&battery->mutex);
-
 	update = (get_seconds() - battery->update_time[fid] >= update_time);
 	update = (update | battery->flags.update[fid]);
 
@@ -733,7 +729,6 @@ static int acpi_battery_read(int fid, struct seq_file *seq)
 	result = acpi_read_funcs[fid].print(seq, result);
 	acpi_battery_check_result(battery, result);
 	battery->flags.update[fid] = result;
-	mutex_unlock(&battery->mutex);
 	return result;
 }
 
@@ -897,10 +892,7 @@ static int acpi_battery_add(struct acpi_device *device)
 	if (!battery)
 		return -ENOMEM;
 
-	mutex_init(&battery->mutex);
-
-	mutex_lock(&battery->mutex);
-
+	mutex_init(&battery->lock);
 	battery->device = device;
 	strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
 	strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
@@ -936,7 +928,6 @@ static int acpi_battery_add(struct acpi_device *device)
 		kfree(battery);
 	}
 
-	mutex_unlock(&battery->mutex);
 
 	return result;
 }
@@ -951,8 +942,6 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
 
 	battery = acpi_driver_data(device);
 
-	mutex_lock(&battery->mutex);
-
 	status = acpi_remove_notify_handler(device->handle,
 					    ACPI_ALL_NOTIFY,
 					    acpi_battery_notify);
@@ -963,9 +952,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
 
 	kfree(battery->bst_data.pointer);
 
-	mutex_unlock(&battery->mutex);
-
-	mutex_destroy(&battery->mutex);
+	mutex_destroy(&battery->lock);
 
 	kfree(battery);
 
-- 
1.5.3.rc3.7.gd58e

  parent reply	other threads:[~2007-08-03 22:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-03 22:33 ACPI patches for 2.6.23-rc2 Len Brown
     [not found] ` <67effe8fff32f60bdf51cba484766ba6003005bb.1186180370.git.len.brown@intel.com>
2007-08-03 22:33   ` [PATCH 01/12] ACPI: add "acpi_no_auto_ssdt" bootparam Len Brown
     [not found]   ` <e84a02ba0b33a97a8486f3248fd45f50b1a1c014.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 02/12] sony-laptop: restore the last user requested brightness level on resume Len Brown
     [not found]   ` <11604ecf6fb9c2ab0152fbddb7ea2724438ef76e.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 03/12] sony-laptop: sony_nc_ids[] can become static Len Brown
     [not found]   ` <f7b88ccb63188e775fe02e746c39ed177741cfc7.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 04/12] sonypi: fix ids member of struct acpi_driver Len Brown
     [not found]   ` <ac36393de6034be7266264a435360e7628849005.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 05/12] ACPI: thinkpad-acpi: fix the module init failure path Len Brown
     [not found]   ` <de47b69c7b7be46b0848b2c4f8e23c478cd68690.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 07/12] asus_acpi: fix possible double free (found by Coverity) Len Brown
     [not found]   ` <f1cd1fe61b96e4312312d42c0a9784dfab12e007.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 08/12] ACPI: EC: Remove noisy debug printk fron EC driver Len Brown
     [not found]   ` <3bd92ba19a89fe61ebf58804f9c8675372f50c1c.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` Len Brown [this message]
     [not found]   ` <cd8c93a4e04dce8f00d1ef3a476aac8bd65ae40b.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 10/12] ACPI: EC: If ECDT is not found, look up EC in DSDT Len Brown
     [not found]   ` <52fe4bdf40bc07498c5f7935551774e8f8458190.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 11/12] ACPI: EC: fix build warning Len Brown
     [not found]   ` <7c010de7506954e973abfab5c5999c5a97f7a73e.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 12/12] ACPI: EC: Switch from boot_ec as soon as we find its desc in DSDT Len Brown
     [not found]   ` <6c77088daa419b0bba83b0ce162e2f25a1a5e131.1186180370.git.len.brown@intel.com>
2007-08-03 22:33     ` [PATCH 06/12] ACPI: button: re-scan lid state on resume Len Brown
2007-08-05 15:11     ` Thomas Renninger
2007-08-08  8:11   ` [PATCH 01/12] ACPI: add "acpi_no_auto_ssdt" bootparam Thomas Renninger
2007-08-08 16:38     ` Len Brown

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=11861804344148-git-send-email-len.brown@intel.com \
    --to=len.brown@intel.com \
    --cc=astarikivskiy@suse.de \
    --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;
as well as URLs for NNTP newsgroup(s).