Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 378eef99 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

PM / Wakeup: Make pm_save_wakeup_count() work as documented



According to Documentation/ABI/testing/sysfs-power, the
/sys/power/wakeup_count interface should only make the kernel react
to wakeup events during suspend if the last write to it has been
successful.  However, if /sys/power/wakeup_count is written to two
times in a row, where the first write is successful and the second
is not, the kernel will still react to wakeup events during suspend
due to a bug in pm_save_wakeup_count().

Fix the bug by making pm_save_wakeup_count() clear
events_check_enabled unconditionally before checking if there are
any new wakeup events registered since the previous read from
/sys/power/wakeup_count.

Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
parent 023d3779
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -616,25 +616,25 @@ bool pm_get_wakeup_count(unsigned int *count)
 *
 *
 * If @count is equal to the current number of registered wakeup events and the
 * If @count is equal to the current number of registered wakeup events and the
 * current number of wakeup events being processed is zero, store @count as the
 * current number of wakeup events being processed is zero, store @count as the
 * old number of registered wakeup events to be used by pm_check_wakeup_events()
 * old number of registered wakeup events for pm_check_wakeup_events(), enable
 * and return true.  Otherwise return false.
 * wakeup events detection and return 'true'.  Otherwise disable wakeup events
 * detection and return 'false'.
 */
 */
bool pm_save_wakeup_count(unsigned int count)
bool pm_save_wakeup_count(unsigned int count)
{
{
	unsigned int cnt, inpr;
	unsigned int cnt, inpr;
	bool ret = false;


	events_check_enabled = false;
	spin_lock_irq(&events_lock);
	spin_lock_irq(&events_lock);
	split_counters(&cnt, &inpr);
	split_counters(&cnt, &inpr);
	if (cnt == count && inpr == 0) {
	if (cnt == count && inpr == 0) {
		saved_count = count;
		saved_count = count;
		events_check_enabled = true;
		events_check_enabled = true;
		ret = true;
	}
	}
	spin_unlock_irq(&events_lock);
	spin_unlock_irq(&events_lock);
	if (!ret)
	if (!events_check_enabled)
		pm_wakeup_update_hit_counts();
		pm_wakeup_update_hit_counts();
	return ret;
	return events_check_enabled;
}
}


static struct dentry *wakeup_sources_stats_dentry;
static struct dentry *wakeup_sources_stats_dentry;