On Mon, 11 Aug 2025 16:01:09 +0800
Fushuai Wang <wangfush...@baidu.com> wrote:

> Add a WARN_ON check in move_to_next_cpu(). Next_cpu should
> never be greater than or equal to nr_cpu_ids.
> 
> Signed-off-by: Fushuai Wang <wangfush...@baidu.com>
> ---
>  kernel/trace/trace_hwlat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
> index 2f7b94e98317..5024b0dcdbba 100644
> --- a/kernel/trace/trace_hwlat.c
> +++ b/kernel/trace/trace_hwlat.c
> @@ -328,7 +328,7 @@ static void move_to_next_cpu(void)
>       next_cpu = cpumask_next_wrap(raw_smp_processor_id(), current_mask);
>       cpus_read_unlock();
>  
> -     if (next_cpu >= nr_cpu_ids) /* Shouldn't happen! */
> +     if (WARN_ON(next_cpu >= nr_cpu_ids)) /* Shouldn't happen! */
>               goto change_mode;

Yeah, it shouldn't happen but it doesn't mean we need to add a WARN_ON().
It might even happen if user space is messing with the tracing_cpumask at
the same time. It shouldn't happen but it doesn't mean it will not happen.

We do not add WARN_ON() for things that could be trigger by user space.

-- Steve


Reply via email to