Re: [PATCH v3] lib/tests: test_ratelimit: fix stress test thread lifecycle and leak
From: Petr Mladek
Date: Wed Jun 24 2026 - 11:24:58 EST
On Fri 2026-05-29 08:58:55, Jia He wrote:
> The stress test's WARN_ON_ONCE(!sktp->tp) check in the child thread is
> racy and unnecessary: since kthread_run() wakes the thread before
> returning, the child can run before sktp[i].tp has been assigned.
> Moreover, sktp->tp is never actually used in the child function, so the
> check serves no purpose. Remove it and keep the original kthread_run()
>
> Also add a common cleanup path for thread creation failures. If creating
> one of the later threads fails, stop all threads that were already
> started and free the allocated array instead of leaving orphan kthreads
> and leaked memory behind.
>
> Finally, replace the module-static doneflag with kthread_should_stop().
> With the doneflag, child threads may exit before the parent calls
> kthread_stop(), so the task lifetime is no longer guaranteed when the
> parent later tries to stop them. Using kthread_should_stop() keeps each
> child alive until kthread_stop() synchronously terminates it.
>
> Suggested-by: Petr Mladek <pmladek@xxxxxxxx>
> Signed-off-by: Jia He <justin.he@xxxxxxx>
Looks good to me:
Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
Tested-by: Petr Mladek <pmladek@xxxxxxxx>
Now, the question is who would push it.
I could take it via the printk tree. Or Paul would you prefer to
take it yourself?
Best Regards,
Petr