kmemleak: don't hang if user disables scanning early
authorVegard Nossum <[email protected]>
Thu, 28 Jul 2016 22:48:32 +0000 (15:48 -0700)
committerLinus Torvalds <[email protected]>
Thu, 28 Jul 2016 23:07:41 +0000 (16:07 -0700)
If the user tries to disable automatic scanning early in the boot
process using e.g.:

  echo scan=off > /sys/kernel/debug/kmemleak

then this command will hang until SECS_FIRST_SCAN (= 60) seconds have
elapsed, even though the system is fully initialised.

We can fix this using interruptible sleep and checking if we're supposed
to stop whenever we wake up (like the rest of the code does).

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Vegard Nossum <[email protected]>
Acked-by: Catalin Marinas <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/kmemleak.c

index 04320d3adbef9922edda52e43cc516463e9e33c6..086292f7c59d1a69881068758150c2140feb8253 100644 (file)
@@ -1485,8 +1485,10 @@ static int kmemleak_scan_thread(void *arg)
         * Wait before the first scan to allow the system to fully initialize.
         */
        if (first_run) {
+               signed long timeout = msecs_to_jiffies(SECS_FIRST_SCAN * 1000);
                first_run = 0;
-               ssleep(SECS_FIRST_SCAN);
+               while (timeout && !kthread_should_stop())
+                       timeout = schedule_timeout_interruptible(timeout);
        }
 
        while (!kthread_should_stop()) {