Re: [PATCH v3] lib/tests: test_ratelimit: fix stress test thread lifecycle and leak
From: Petr Mladek
Date: Thu Jun 25 2026 - 07:43:35 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>
JFYI, the patch has been committed into printk/linux.git,
branch for-7.3.
Best Regards,
Petr
PS: I have already sent pull request for 7.2. And this is
not serious enough to trigger another one.