@@ -1448,9 +1448,11 @@ static const char * const comp_alg_enabled[] = {
static int hibernate_compressor_param_set(const char *compressor,
const struct kernel_param *kp)
{
+ unsigned int sleep_flags;
int index, ret;
- if (!mutex_trylock(&system_transition_mutex))
+ sleep_flags = try_lock_system_sleep();
+ if (!sleep_flags)
return -EBUSY;
index = sysfs_match_string(comp_alg_enabled, compressor);
@@ -1463,7 +1465,7 @@ static int hibernate_compressor_param_set(const char *compressor,
ret = index;
}
- mutex_unlock(&system_transition_mutex);
+ unlock_system_sleep(sleep_flags);
if (ret)
pr_debug("Cannot set specified compressor %s\n",
@@ -564,6 +564,7 @@ static void suspend_finish(void)
*/
static int enter_state(suspend_state_t state)
{
+ unsigned int sleep_flags;
int error;
trace_suspend_resume(TPS("suspend_enter"), state, true);
@@ -577,7 +578,9 @@ static int enter_state(suspend_state_t state)
} else if (!valid_state(state)) {
return -EINVAL;
}
- if (!mutex_trylock(&system_transition_mutex))
+
+ sleep_flags = try_lock_system_sleep();
+ if (!sleep_flags)
return -EBUSY;
if (state == PM_SUSPEND_TO_IDLE)
@@ -609,7 +612,7 @@ static int enter_state(suspend_state_t state)
pm_pr_dbg("Finishing wakeup.\n");
suspend_finish();
Unlock:
- mutex_unlock(&system_transition_mutex);
+ unlock_system_sleep(sleep_flags);
return error;
}
@@ -249,6 +249,7 @@ static int snapshot_set_swap_area(struct snapshot_data *data,
static long snapshot_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
+ unsigned int sleep_flags;
int error = 0;
struct snapshot_data *data;
loff_t size;
@@ -266,7 +267,8 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- if (!mutex_trylock(&system_transition_mutex))
+ sleep_flags = try_lock_system_sleep();
+ if (!sleep_flags)
return -EBUSY;
lock_device_hotplug();
@@ -417,7 +419,7 @@ static long snapshot_ioctl(struct file *filp, unsigned int cmd,
}
unlock_device_hotplug();
- mutex_unlock(&system_transition_mutex);
+ unlock_system_sleep(sleep_flags);
return error;
}
This patch replaces the remaining instances of mutex_trylock(&system_transition_mutex) that semantically intend to *try* acquiring the lock with the newly introduced try_lock_system_sleep(), which provides a clearer abstraction and avoids direct mutex operations in higher-level PM logic. This improves code readability, keeps synchronization logic consistent across all system sleep paths, and helps prepare for future enhancements or lock substitutions (e.g., lockdep annotations or switching to a different lock primitive). Signed-off-by: Zihuan Zhang <zhangzihuan@kylinos.cn> --- kernel/power/hibernate.c | 6 ++++-- kernel/power/suspend.c | 7 +++++-- kernel/power/user.c | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-)