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

Commit 11048dcf authored by Matthias Kaehlcke's avatar Matthias Kaehlcke Committed by Greg Kroah-Hartman
Browse files

Power Management: use mutexes instead of semaphores



The Power Management code uses semaphores as mutexes.  Use the mutex API
instead of the (binary) semaphores.

Signed-off-by: default avatarMatthias Kaehlcke <matthias.kaehlcke@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 9f3f776b
Loading
Loading
Loading
Loading
+8 −6
Original line number Original line Diff line number Diff line
@@ -20,14 +20,16 @@
 */
 */


#include <linux/device.h>
#include <linux/device.h>
#include <linux/mutex.h>

#include "power.h"
#include "power.h"


LIST_HEAD(dpm_active);
LIST_HEAD(dpm_active);
LIST_HEAD(dpm_off);
LIST_HEAD(dpm_off);
LIST_HEAD(dpm_off_irq);
LIST_HEAD(dpm_off_irq);


DECLARE_MUTEX(dpm_sem);
DEFINE_MUTEX(dpm_mtx);
DECLARE_MUTEX(dpm_list_sem);
DEFINE_MUTEX(dpm_list_mtx);


int (*platform_enable_wakeup)(struct device *dev, int is_on);
int (*platform_enable_wakeup)(struct device *dev, int is_on);


@@ -59,12 +61,12 @@ int device_pm_add(struct device * dev)
	pr_debug("PM: Adding info for %s:%s\n",
	pr_debug("PM: Adding info for %s:%s\n",
		 dev->bus ? dev->bus->name : "No Bus",
		 dev->bus ? dev->bus->name : "No Bus",
		 kobject_name(&dev->kobj));
		 kobject_name(&dev->kobj));
	down(&dpm_list_sem);
	mutex_lock(&dpm_list_mtx);
	list_add_tail(&dev->power.entry, &dpm_active);
	list_add_tail(&dev->power.entry, &dpm_active);
	device_pm_set_parent(dev, dev->parent);
	device_pm_set_parent(dev, dev->parent);
	if ((error = dpm_sysfs_add(dev)))
	if ((error = dpm_sysfs_add(dev)))
		list_del(&dev->power.entry);
		list_del(&dev->power.entry);
	up(&dpm_list_sem);
	mutex_unlock(&dpm_list_mtx);
	return error;
	return error;
}
}


@@ -73,11 +75,11 @@ void device_pm_remove(struct device * dev)
	pr_debug("PM: Removing info for %s:%s\n",
	pr_debug("PM: Removing info for %s:%s\n",
		 dev->bus ? dev->bus->name : "No Bus",
		 dev->bus ? dev->bus->name : "No Bus",
		 kobject_name(&dev->kobj));
		 kobject_name(&dev->kobj));
	down(&dpm_list_sem);
	mutex_lock(&dpm_list_mtx);
	dpm_sysfs_remove(dev);
	dpm_sysfs_remove(dev);
	put_device(dev->power.pm_parent);
	put_device(dev->power.pm_parent);
	list_del_init(&dev->power.entry);
	list_del_init(&dev->power.entry);
	up(&dpm_list_sem);
	mutex_unlock(&dpm_list_mtx);
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -14,12 +14,12 @@ extern void device_shutdown(void);
/*
/*
 * Used to synchronize global power management operations.
 * Used to synchronize global power management operations.
 */
 */
extern struct semaphore dpm_sem;
extern struct mutex dpm_mtx;


/*
/*
 * Used to serialize changes to the dpm_* lists.
 * Used to serialize changes to the dpm_* lists.
 */
 */
extern struct semaphore dpm_list_sem;
extern struct mutex dpm_list_mtx;


/*
/*
 * The PM lists.
 * The PM lists.
+6 −6
Original line number Original line Diff line number Diff line
@@ -80,7 +80,7 @@ static int resume_device_early(struct device * dev)
 */
 */
void dpm_resume(void)
void dpm_resume(void)
{
{
	down(&dpm_list_sem);
	mutex_lock(&dpm_list_mtx);
	while(!list_empty(&dpm_off)) {
	while(!list_empty(&dpm_off)) {
		struct list_head * entry = dpm_off.next;
		struct list_head * entry = dpm_off.next;
		struct device * dev = to_device(entry);
		struct device * dev = to_device(entry);
@@ -88,13 +88,13 @@ void dpm_resume(void)
		get_device(dev);
		get_device(dev);
		list_move_tail(entry, &dpm_active);
		list_move_tail(entry, &dpm_active);


		up(&dpm_list_sem);
		mutex_unlock(&dpm_list_mtx);
		if (!dev->power.prev_state.event)
		if (!dev->power.prev_state.event)
			resume_device(dev);
			resume_device(dev);
		down(&dpm_list_sem);
		mutex_lock(&dpm_list_mtx);
		put_device(dev);
		put_device(dev);
	}
	}
	up(&dpm_list_sem);
	mutex_unlock(&dpm_list_mtx);
}
}




@@ -108,9 +108,9 @@ void dpm_resume(void)
void device_resume(void)
void device_resume(void)
{
{
	might_sleep();
	might_sleep();
	down(&dpm_sem);
	mutex_lock(&dpm_mtx);
	dpm_resume();
	dpm_resume();
	up(&dpm_sem);
	mutex_unlock(&dpm_mtx);
}
}


EXPORT_SYMBOL_GPL(device_resume);
EXPORT_SYMBOL_GPL(device_resume);
+6 −6
Original line number Original line Diff line number Diff line
@@ -32,9 +32,9 @@ static void runtime_resume(struct device * dev)


void dpm_runtime_resume(struct device * dev)
void dpm_runtime_resume(struct device * dev)
{
{
	down(&dpm_sem);
	mutex_lock(&dpm_mtx);
	runtime_resume(dev);
	runtime_resume(dev);
	up(&dpm_sem);
	mutex_unlock(&dpm_mtx);
}
}
EXPORT_SYMBOL(dpm_runtime_resume);
EXPORT_SYMBOL(dpm_runtime_resume);


@@ -49,7 +49,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
{
{
	int error = 0;
	int error = 0;


	down(&dpm_sem);
	mutex_lock(&dpm_mtx);
	if (dev->power.power_state.event == state.event)
	if (dev->power.power_state.event == state.event)
		goto Done;
		goto Done;


@@ -59,7 +59,7 @@ int dpm_runtime_suspend(struct device * dev, pm_message_t state)
	if (!(error = suspend_device(dev, state)))
	if (!(error = suspend_device(dev, state)))
		dev->power.power_state = state;
		dev->power.power_state = state;
 Done:
 Done:
	up(&dpm_sem);
	mutex_unlock(&dpm_mtx);
	return error;
	return error;
}
}
EXPORT_SYMBOL(dpm_runtime_suspend);
EXPORT_SYMBOL(dpm_runtime_suspend);
@@ -78,8 +78,8 @@ EXPORT_SYMBOL(dpm_runtime_suspend);
 */
 */
void dpm_set_power_state(struct device * dev, pm_message_t state)
void dpm_set_power_state(struct device * dev, pm_message_t state)
{
{
	down(&dpm_sem);
	mutex_lock(&dpm_mtx);
	dev->power.power_state = state;
	dev->power.power_state = state;
	up(&dpm_sem);
	mutex_unlock(&dpm_mtx);
}
}
#endif  /*  0  */
#endif  /*  0  */
+7 −7
Original line number Original line Diff line number Diff line
@@ -108,7 +108,7 @@ int suspend_device(struct device * dev, pm_message_t state)


/*
/*
 * This is called with interrupts off, only a single CPU
 * This is called with interrupts off, only a single CPU
 * running. We can't do down() on a semaphore (and we don't
 * running. We can't acquire a mutex or semaphore (and we don't
 * need the protection)
 * need the protection)
 */
 */
static int suspend_device_late(struct device *dev, pm_message_t state)
static int suspend_device_late(struct device *dev, pm_message_t state)
@@ -153,18 +153,18 @@ int device_suspend(pm_message_t state)
	int error = 0;
	int error = 0;


	might_sleep();
	might_sleep();
	down(&dpm_sem);
	mutex_lock(&dpm_mtx);
	down(&dpm_list_sem);
	mutex_lock(&dpm_list_mtx);
	while (!list_empty(&dpm_active) && error == 0) {
	while (!list_empty(&dpm_active) && error == 0) {
		struct list_head * entry = dpm_active.prev;
		struct list_head * entry = dpm_active.prev;
		struct device * dev = to_device(entry);
		struct device * dev = to_device(entry);


		get_device(dev);
		get_device(dev);
		up(&dpm_list_sem);
		mutex_unlock(&dpm_list_mtx);


		error = suspend_device(dev, state);
		error = suspend_device(dev, state);


		down(&dpm_list_sem);
		mutex_lock(&dpm_list_mtx);


		/* Check if the device got removed */
		/* Check if the device got removed */
		if (!list_empty(&dev->power.entry)) {
		if (!list_empty(&dev->power.entry)) {
@@ -179,11 +179,11 @@ int device_suspend(pm_message_t state)
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
				error == -EAGAIN ? " (please convert to suspend_late)" : "");
		put_device(dev);
		put_device(dev);
	}
	}
	up(&dpm_list_sem);
	mutex_unlock(&dpm_list_mtx);
	if (error)
	if (error)
		dpm_resume();
		dpm_resume();


	up(&dpm_sem);
	mutex_unlock(&dpm_mtx);
	return error;
	return error;
}
}