{
        spin_lock(&sci->sc_state_lock);
        if (!(sci->sc_state & NILFS_SEGCTOR_COMMIT)) {
-               sci->sc_timer.expires = jiffies + sci->sc_interval;
-               add_timer(&sci->sc_timer);
+               if (sci->sc_task) {
+                       sci->sc_timer.expires = jiffies + sci->sc_interval;
+                       add_timer(&sci->sc_timer);
+               }
                sci->sc_state |= NILFS_SEGCTOR_COMMIT;
        }
        spin_unlock(&sci->sc_state_lock);
  */
 static void nilfs_segctor_accept(struct nilfs_sc_info *sci)
 {
+       bool thread_is_alive;
+
        spin_lock(&sci->sc_state_lock);
        sci->sc_seq_accepted = sci->sc_seq_request;
+       thread_is_alive = (bool)sci->sc_task;
        spin_unlock(&sci->sc_state_lock);
-       del_timer_sync(&sci->sc_timer);
+
+       /*
+        * This function does not race with the log writer thread's
+        * termination.  Therefore, deleting sc_timer, which should not be
+        * done after the log writer thread exits, can be done safely outside
+        * the area protected by sc_state_lock.
+        */
+       if (thread_is_alive)
+               del_timer_sync(&sci->sc_timer);
 }
 
 /**
                        sci->sc_flush_request &= ~FLUSH_DAT_BIT;
 
                /* re-enable timer if checkpoint creation was not done */
-               if ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
+               if ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && sci->sc_task &&
                    time_before(jiffies, sci->sc_timer.expires))
                        add_timer(&sci->sc_timer);
        }
        int timeout = 0;
 
        sci->sc_timer_task = current;
+       timer_setup(&sci->sc_timer, nilfs_construction_timeout, 0);
 
        /* start sync. */
        sci->sc_task = current;
  end_thread:
        /* end sync. */
        sci->sc_task = NULL;
+       timer_shutdown_sync(&sci->sc_timer);
        wake_up(&sci->sc_wait_task); /* for nilfs_segctor_kill_thread() */
        spin_unlock(&sci->sc_state_lock);
        return 0;
        INIT_LIST_HEAD(&sci->sc_gc_inodes);
        INIT_LIST_HEAD(&sci->sc_iput_queue);
        INIT_WORK(&sci->sc_iput_work, nilfs_iput_work_func);
-       timer_setup(&sci->sc_timer, nilfs_construction_timeout, 0);
 
        sci->sc_interval = HZ * NILFS_SC_DEFAULT_TIMEOUT;
        sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ;
 
        down_write(&nilfs->ns_segctor_sem);
 
-       timer_shutdown_sync(&sci->sc_timer);
        kfree(sci);
 }