Re: [PATCH v2 1/5] watchdog: Return early in watchdog_hardlockup_check()

From: Doug Anderson

Date: Fri Mar 13 2026 - 11:33:44 EST


Hi,

On Thu, Mar 12, 2026 at 4:22 PM Mayank Rungta via B4 Relay
<devnull+mrungta.google.com@xxxxxxxxxx> wrote:
>
> From: Mayank Rungta <mrungta@xxxxxxxxxx>
>
> Invert the `is_hardlockup(cpu)` check in `watchdog_hardlockup_check()`
> to return early when a hardlockup is not detected. This flattens the
> main logic block, reducing the indentation level and making the code
> easier to read and maintain.
>
> This refactoring serves as a preparation patch for future hardlockup
> changes.
>
> Signed-off-by: Mayank Rungta <mrungta@xxxxxxxxxx>
> ---
> kernel/watchdog.c | 117 +++++++++++++++++++++++++++---------------------------
> 1 file changed, 59 insertions(+), 58 deletions(-)
>
> diff --git a/kernel/watchdog.c b/kernel/watchdog.c
> index 7d675781bc91..4c5b47495745 100644
> --- a/kernel/watchdog.c
> +++ b/kernel/watchdog.c
> @@ -187,6 +187,8 @@ static void watchdog_hardlockup_kick(void)
> void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs)
> {
> int hardlockup_all_cpu_backtrace;
> + unsigned int this_cpu;
> + unsigned long flags;
>
> if (per_cpu(watchdog_hardlockup_touched, cpu)) {
> per_cpu(watchdog_hardlockup_touched, cpu) = false;
> @@ -201,74 +203,73 @@ void watchdog_hardlockup_check(unsigned int cpu, struct pt_regs *regs)
> * fired multiple times before we overflow'd. If it hasn't
> * then this is a good indication the cpu is stuck
> */
> - if (is_hardlockup(cpu)) {
> - unsigned int this_cpu = smp_processor_id();
> - unsigned long flags;
> + if (!is_hardlockup(cpu)) {
> + per_cpu(watchdog_hardlockup_warned, cpu) = false;
> + return;
> + }

IMO not worth spinning for, but potentially the
"hardlockup_all_cpu_backtrace" assignment could be moved down below
the new "if" test, since it's not needed if we "early out".

In any case:

Reviewed-by: Douglas Anderson <dianders@xxxxxxxxxxxx>