PM / Sleep: Replace mutex_[un]lock(&pm_mutex) with [un]lock_system_sleep()
Using [un]lock_system_sleep() is safer than directly using mutex_[un]lock() on 'pm_mutex', since the latter could lead to freezing failures. Hence convert all the present users of mutex_[un]lock(&pm_mutex) to use these safe APIs instead. Suggested-by: Tejun Heo <tj@kernel.org> Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com> Reviewed-by: Simon Horman <horms@verge.net.au> Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
This commit is contained in:
		
					parent
					
						
							
								9b6fc5dc87
							
						
					
				
			
			
				commit
				
					
						bcda53faf5
					
				
			
		
					 5 changed files with 22 additions and 22 deletions
				
			
		|  | @ -1523,7 +1523,7 @@ int kernel_kexec(void) | ||||||
| 
 | 
 | ||||||
| #ifdef CONFIG_KEXEC_JUMP | #ifdef CONFIG_KEXEC_JUMP | ||||||
| 	if (kexec_image->preserve_context) { | 	if (kexec_image->preserve_context) { | ||||||
| 		mutex_lock(&pm_mutex); | 		lock_system_sleep(); | ||||||
| 		pm_prepare_console(); | 		pm_prepare_console(); | ||||||
| 		error = freeze_processes(); | 		error = freeze_processes(); | ||||||
| 		if (error) { | 		if (error) { | ||||||
|  | @ -1576,7 +1576,7 @@ int kernel_kexec(void) | ||||||
| 		thaw_processes(); | 		thaw_processes(); | ||||||
|  Restore_console: |  Restore_console: | ||||||
| 		pm_restore_console(); | 		pm_restore_console(); | ||||||
| 		mutex_unlock(&pm_mutex); | 		unlock_system_sleep(); | ||||||
| 	} | 	} | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -69,14 +69,14 @@ void hibernation_set_ops(const struct platform_hibernation_ops *ops) | ||||||
| 		WARN_ON(1); | 		WARN_ON(1); | ||||||
| 		return; | 		return; | ||||||
| 	} | 	} | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 	hibernation_ops = ops; | 	hibernation_ops = ops; | ||||||
| 	if (ops) | 	if (ops) | ||||||
| 		hibernation_mode = HIBERNATION_PLATFORM; | 		hibernation_mode = HIBERNATION_PLATFORM; | ||||||
| 	else if (hibernation_mode == HIBERNATION_PLATFORM) | 	else if (hibernation_mode == HIBERNATION_PLATFORM) | ||||||
| 		hibernation_mode = HIBERNATION_SHUTDOWN; | 		hibernation_mode = HIBERNATION_SHUTDOWN; | ||||||
| 
 | 
 | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static bool entering_platform_hibernation; | static bool entering_platform_hibernation; | ||||||
|  | @ -597,7 +597,7 @@ int hibernate(void) | ||||||
| { | { | ||||||
| 	int error; | 	int error; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 	/* The snapshot device should not be opened while we're running */ | 	/* The snapshot device should not be opened while we're running */ | ||||||
| 	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { | 	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { | ||||||
| 		error = -EBUSY; | 		error = -EBUSY; | ||||||
|  | @ -665,7 +665,7 @@ int hibernate(void) | ||||||
| 	pm_restore_console(); | 	pm_restore_console(); | ||||||
| 	atomic_inc(&snapshot_device_available); | 	atomic_inc(&snapshot_device_available); | ||||||
|  Unlock: |  Unlock: | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 	return error; | 	return error; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -893,7 +893,7 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, | ||||||
| 	p = memchr(buf, '\n', n); | 	p = memchr(buf, '\n', n); | ||||||
| 	len = p ? p - buf : n; | 	len = p ? p - buf : n; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 	for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { | 	for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { | ||||||
| 		if (len == strlen(hibernation_modes[i]) | 		if (len == strlen(hibernation_modes[i]) | ||||||
| 		    && !strncmp(buf, hibernation_modes[i], len)) { | 		    && !strncmp(buf, hibernation_modes[i], len)) { | ||||||
|  | @ -919,7 +919,7 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, | ||||||
| 	if (!error) | 	if (!error) | ||||||
| 		pr_debug("PM: Hibernation mode set to '%s'\n", | 		pr_debug("PM: Hibernation mode set to '%s'\n", | ||||||
| 			 hibernation_modes[mode]); | 			 hibernation_modes[mode]); | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 	return error ? error : n; | 	return error ? error : n; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -946,9 +946,9 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, | ||||||
| 	if (maj != MAJOR(res) || min != MINOR(res)) | 	if (maj != MAJOR(res) || min != MINOR(res)) | ||||||
| 		goto out; | 		goto out; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 	swsusp_resume_device = res; | 	swsusp_resume_device = res; | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 	printk(KERN_INFO "PM: Starting manual resume from disk\n"); | 	printk(KERN_INFO "PM: Starting manual resume from disk\n"); | ||||||
| 	noresume = 0; | 	noresume = 0; | ||||||
| 	software_resume(); | 	software_resume(); | ||||||
|  |  | ||||||
|  | @ -116,7 +116,7 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr, | ||||||
| 	p = memchr(buf, '\n', n); | 	p = memchr(buf, '\n', n); | ||||||
| 	len = p ? p - buf : n; | 	len = p ? p - buf : n; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	level = TEST_FIRST; | 	level = TEST_FIRST; | ||||||
| 	for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++) | 	for (s = &pm_tests[level]; level <= TEST_MAX; s++, level++) | ||||||
|  | @ -126,7 +126,7 @@ static ssize_t pm_test_store(struct kobject *kobj, struct kobj_attribute *attr, | ||||||
| 			break; | 			break; | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	return error ? error : n; | 	return error ? error : n; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -42,9 +42,9 @@ static const struct platform_suspend_ops *suspend_ops; | ||||||
|  */ |  */ | ||||||
| void suspend_set_ops(const struct platform_suspend_ops *ops) | void suspend_set_ops(const struct platform_suspend_ops *ops) | ||||||
| { | { | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 	suspend_ops = ops; | 	suspend_ops = ops; | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| } | } | ||||||
| EXPORT_SYMBOL_GPL(suspend_set_ops); | EXPORT_SYMBOL_GPL(suspend_set_ops); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -71,7 +71,7 @@ static int snapshot_open(struct inode *inode, struct file *filp) | ||||||
| 	struct snapshot_data *data; | 	struct snapshot_data *data; | ||||||
| 	int error; | 	int error; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { | 	if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { | ||||||
| 		error = -EBUSY; | 		error = -EBUSY; | ||||||
|  | @ -123,7 +123,7 @@ static int snapshot_open(struct inode *inode, struct file *filp) | ||||||
| 	data->platform_support = 0; | 	data->platform_support = 0; | ||||||
| 
 | 
 | ||||||
|  Unlock: |  Unlock: | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	return error; | 	return error; | ||||||
| } | } | ||||||
|  | @ -132,7 +132,7 @@ static int snapshot_release(struct inode *inode, struct file *filp) | ||||||
| { | { | ||||||
| 	struct snapshot_data *data; | 	struct snapshot_data *data; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	swsusp_free(); | 	swsusp_free(); | ||||||
| 	free_basic_memory_bitmaps(); | 	free_basic_memory_bitmaps(); | ||||||
|  | @ -146,7 +146,7 @@ static int snapshot_release(struct inode *inode, struct file *filp) | ||||||
| 			PM_POST_HIBERNATION : PM_POST_RESTORE); | 			PM_POST_HIBERNATION : PM_POST_RESTORE); | ||||||
| 	atomic_inc(&snapshot_device_available); | 	atomic_inc(&snapshot_device_available); | ||||||
| 
 | 
 | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  | @ -158,7 +158,7 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf, | ||||||
| 	ssize_t res; | 	ssize_t res; | ||||||
| 	loff_t pg_offp = *offp & ~PAGE_MASK; | 	loff_t pg_offp = *offp & ~PAGE_MASK; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	data = filp->private_data; | 	data = filp->private_data; | ||||||
| 	if (!data->ready) { | 	if (!data->ready) { | ||||||
|  | @ -179,7 +179,7 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf, | ||||||
| 		*offp += res; | 		*offp += res; | ||||||
| 
 | 
 | ||||||
|  Unlock: |  Unlock: | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	return res; | 	return res; | ||||||
| } | } | ||||||
|  | @ -191,7 +191,7 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf, | ||||||
| 	ssize_t res; | 	ssize_t res; | ||||||
| 	loff_t pg_offp = *offp & ~PAGE_MASK; | 	loff_t pg_offp = *offp & ~PAGE_MASK; | ||||||
| 
 | 
 | ||||||
| 	mutex_lock(&pm_mutex); | 	lock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	data = filp->private_data; | 	data = filp->private_data; | ||||||
| 
 | 
 | ||||||
|  | @ -208,7 +208,7 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf, | ||||||
| 	if (res > 0) | 	if (res > 0) | ||||||
| 		*offp += res; | 		*offp += res; | ||||||
| unlock: | unlock: | ||||||
| 	mutex_unlock(&pm_mutex); | 	unlock_system_sleep(); | ||||||
| 
 | 
 | ||||||
| 	return res; | 	return res; | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Srivatsa S. Bhat
				Srivatsa S. Bhat