[PATCH 02/10] PM: wakelock: Override wakelocks when not using /sys/power/request_state

Arve Hjønnevåg
2009-02-11T01:49:07Z

This preserves existing functionality when CONFIG_WAKELOCK is set.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
---
include/linux/wakelock.h | 4 ++++
kernel/power/wakelock.c | 10 +++++++++-
2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/include/linux/wakelock.h b/include/linux/wakelock.h
index ec878d2..af74b65 100755
--- a/include/linux/wakelock.h
+++ b/include/linux/wakelock.h
@@ -72,6 +72,10 @@ int wake_lock_active(struct wake_lock *lock);
* and non-zero if one or more wake locks are held. Specifically it returns
* -1 if one or more wake locks with no timeout are active or the
* number of jiffies until all active wake locks time out.
+ *
+ * To preserve backward compatibility, when the type is WAKE_LOCK_SUSPEND, this
+ * function returns 0 unless it is called during suspend initiated from the
+ * wakelock code.
*/
long has_wake_lock(int type);

diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c
index 13f5d03..c396b58 100644
--- a/kernel/power/wakelock.c
+++ b/kernel/power/wakelock.c
@@ -49,6 +49,7 @@ static int current_event_num;
struct workqueue_struct *suspend_work_queue;
struct wake_lock main_wake_lock;
static suspend_state_t requested_suspend_state = PM_SUSPEND_MEM;
+static bool enable_suspend_wakelocks;
static struct wake_lock unknown_wakeup;

#ifdef CONFIG_WAKELOCK_STAT
@@ -317,6 +318,9 @@ long has_wake_lock(int type)
{
long ret;
unsigned long irqflags;
+ if (WARN_ONCE(type == WAKE_LOCK_SUSPEND && !enable_suspend_wakelocks,
+ "ignoring wakelocks\n"))
+ return 0;
spin_lock_irqsave(&list_lock, irqflags);
ret = has_wake_lock_locked(type);
spin_unlock_irqrestore(&list_lock, irqflags);
@@ -328,10 +332,12 @@ static void suspend_worker(struct work_struct *work)
int ret;
int entry_event_num;

+ enable_suspend_wakelocks = 1;
+
if (has_wake_lock(WAKE_LOCK_SUSPEND)) {
if (debug_mask & DEBUG_SUSPEND)
pr_info("suspend: abort suspend\n");
- return;
+ goto abort;
}

entry_event_num = current_event_num;
@@ -353,6 +359,8 @@ static void suspend_worker(struct work_struct *work)
pr_info("suspend: pm_suspend returned with no event\n");
wake_lock_timeout(&unknown_wakeup, HZ / 2);
}
+abort:
+ enable_suspend_wakelocks = 0;
}
static DECLARE_WORK(suspend_work, suspend_worker);

--
1.6.1

_______________________________________________
linux-pm mailing list
linux-pm@lists.linux-foundation.org