]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
riscv: cpu_ops: Change return value type of cpu_is_stopped() to bool
authorHui Wang <hui.wang@canonical.com>
Sun, 7 Jun 2026 02:17:54 +0000 (20:17 -0600)
committerPaul Walmsley <pjw@kernel.org>
Sun, 7 Jun 2026 05:48:14 +0000 (23:48 -0600)
In the original sbi_cpu_is_stopped(), if rc doesn't equal to the
SBI_HSM_STATE_STOPPED, it will return rc to the caller directly. But
there is a hidden problem, the rc could be SBI_HSM_STATE_STARTED, if
so, this function will report cpu stopped while the cpu isn't really
stopped.

Furthermore, from the name of cpu_is_stopped(), it gives a sense the
return value is a bool type, true means the cpu is stopped, conversely
false means the cpu is not stopped.

Here change the return value type to bool and change the callers
accordingly. This could fix the above two issues.

Fixes: f1e58583b9c7c ("RISC-V: Support cpu hotplug")
Signed-off-by: Hui Wang <hui.wang@canonical.com>
Link: https://patch.msgid.link/20260413123515.48423-1-hui.wang@canonical.com
[pjw@kernel.org: cleaned up some of the pr_warn() messages]
Signed-off-by: Paul Walmsley <pjw@kernel.org>
arch/riscv/include/asm/cpu_ops.h
arch/riscv/kernel/cpu-hotplug.c
arch/riscv/kernel/cpu_ops_sbi.c

index 176b570ef982761bec7810eda1332b105e640623..065811fca594d92edc5e95ac506f88c256c99ec9 100644 (file)
@@ -24,7 +24,7 @@ struct cpu_operations {
                                     struct task_struct *tidle);
 #ifdef CONFIG_HOTPLUG_CPU
        void            (*cpu_stop)(void);
-       int             (*cpu_is_stopped)(unsigned int cpu);
+       bool            (*cpu_is_stopped)(unsigned int cpu);
 #endif
 };
 
index a0ee426f6d938aa82d69cf01fc78f5ddfacc1b12..0bc56d8381b6bf5b882d398deed7961afc217b5d 100644 (file)
@@ -57,8 +57,8 @@ void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)
        /* Verify from the firmware if the cpu is really stopped*/
        if (cpu_ops->cpu_is_stopped)
                ret = cpu_ops->cpu_is_stopped(cpu);
-       if (ret)
-               pr_warn("CPU%u may not have stopped: %d\n", cpu, ret);
+       if (!ret)
+               pr_warn("CPU%u may not have stopped\n", cpu);
 }
 
 /*
index 00aff669f5f2f5e64ff7691c2b8a2e5e5471f1da..146ceab1011feef75bdda867d5024add0d3cced6 100644 (file)
@@ -88,16 +88,19 @@ static void sbi_cpu_stop(void)
        pr_crit("Unable to stop the cpu %d (%d)\n", smp_processor_id(), ret);
 }
 
-static int sbi_cpu_is_stopped(unsigned int cpuid)
+static bool sbi_cpu_is_stopped(unsigned int cpuid)
 {
        int rc;
        unsigned long hartid = cpuid_to_hartid_map(cpuid);
 
        rc = sbi_hsm_hart_get_status(hartid);
 
-       if (rc == SBI_HSM_STATE_STOPPED)
-               return 0;
-       return rc;
+       if (rc != SBI_HSM_STATE_STOPPED) {
+               pr_warn("HART%lu isn't stopped; status %d\n", hartid, rc);
+               return false;
+       }
+
+       return true;
 }
 #endif