[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0hR37in6uikFGgtM+PjXuSCQSc7mk0uLwwniNUKZvnZng@mail.gmail.com>
Date: Wed, 2 Jul 2025 20:57:08 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Zihuan Zhang <zhangzihuan@...inos.cn>
Cc: rafael@...nel.org, pavel@...nel.org, len.brown@...el.com,
linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 4/4] PM: suspend: Simplify state check using sleep_state_supported()
On Thu, Jun 19, 2025 at 5:54 AM Zihuan Zhang <zhangzihuan@...inos.cn> wrote:
>
> Currently enter_state() open-codes state validation using
> `if (state == PM_SUSPEND_TO_IDLE) ... else if (!valid_state(state)) ...`.
>
> This can be simplified by calling sleep_state_supported(), which already
> encodes this logic. This improves clarity and reduces duplication.
>
> Signed-off-by: Zihuan Zhang <zhangzihuan@...inos.cn>
> ---
> kernel/power/suspend.c | 14 ++++----------
> 1 file changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
> index 16172ca22f21..b95c7a80ef20 100644
> --- a/kernel/power/suspend.c
> +++ b/kernel/power/suspend.c
> @@ -571,16 +571,10 @@ static int enter_state(suspend_state_t state)
> int error;
>
> trace_suspend_resume(TPS("suspend_enter"), state, true);
> - if (state == PM_SUSPEND_TO_IDLE) {
> -#ifdef CONFIG_PM_DEBUG
> - if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) {
> - pr_warn("Unsupported test mode for suspend to idle, please choose none/freezer/devices/platform.\n");
> - return -EAGAIN;
> - }
> -#endif
> - } else if (!valid_state(state)) {
> - return -EINVAL;
> - }
> +
> + if (!sleep_state_supported(state))
> + return -ENOSYS;
> +
The code before and after is obviously not the same, so no.
If you do a cleanup, don't change the behavior.
If you want to change the behavior, there needs to be a good enough
reason. A cleanup is not it.
> if (!mutex_trylock(&system_transition_mutex))
> return -EBUSY;
>
> --
Powered by blists - more mailing lists