Skip to contentSkip to conversation

Why should check "current" consistency?

DISCUSSION real yr 1 participant 1 message Mar 8, 2010

lore
Share & tools
lore

real yr

author
#0 lore raw

The source code is listed as follows:
This code is inserted into do_fork() function
============================================
struct asmp_cpu_info *info;
......
restart:
if ((info = current->asmp->cpu)) {
dprintk("forking tsk=%p current=%p #tasks=%d\n", p, current, info->num_tasks);
spin_lock_irqsave(&info->lock, flags);
                /* MY PROBLEM */
if (info != current->asmp->cpu) { spin_unlock_irqrestore(&info->lock, flags);
goto restart;
}
WARN_ON(info->shielded != 1);
WARN_ON(info->num_tasks == 0);
p->asmp->cpu = info;
list_add_tail(&p->asmp->list, &info->tasks); ++info->num_tasks;
spin_unlock_irqrestore(&info->lock, flags);
}
=========================================
Please see the code with comments "/* MY PROBLEM */", since info is a local variable,
even if this code was preempted or interrupted, when the attached process resumes its
state, it will continues from where it was interrupted and the "current" macro shold be the same.
So, Why should check "if (info != current->asmp->cpu) {" ?

Thanks in advance!