Skip to content

Commit

Permalink
async: fix __lowest_in_progress()
Browse files Browse the repository at this point in the history
At 37000 feet somewhere near Greenland I woke up from a half-sleep with the
realisation that __lowest_in_progress() is buggy. After landing I checked
and there were indeed 2 problems with it; this patch fixes both:
* The order of the list checks was wrong
* The locking was not correct.

Signed-off-by: Arjan van de Ven <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
fenrus75 authored and torvalds committed Jan 13, 2009
1 parent d32ad10 commit 37a76bd
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions kernel/async.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ extern int initcall_debug;
static async_cookie_t __lowest_in_progress(struct list_head *running)
{
struct async_entry *entry;
if (!list_empty(&async_pending)) {
entry = list_first_entry(&async_pending,
if (!list_empty(running)) {
entry = list_first_entry(running,
struct async_entry, list);
return entry->cookie;
} else if (!list_empty(running)) {
entry = list_first_entry(running,
} else if (!list_empty(&async_pending)) {
entry = list_first_entry(&async_pending,
struct async_entry, list);
return entry->cookie;
} else {
Expand All @@ -104,6 +104,17 @@ static async_cookie_t __lowest_in_progress(struct list_head *running)
}

}

static async_cookie_t lowest_in_progress(struct list_head *running)
{
unsigned long flags;
async_cookie_t ret;

spin_lock_irqsave(&async_lock, flags);
ret = __lowest_in_progress(running);
spin_unlock_irqrestore(&async_lock, flags);
return ret;
}
/*
* pick the first pending entry and run it
*/
Expand Down Expand Up @@ -229,7 +240,7 @@ void async_synchronize_cookie_special(async_cookie_t cookie, struct list_head *r
starttime = ktime_get();
}

wait_event(async_done, __lowest_in_progress(running) >= cookie);
wait_event(async_done, lowest_in_progress(running) >= cookie);

if (initcall_debug && system_state == SYSTEM_BOOTING) {
endtime = ktime_get();
Expand Down

0 comments on commit 37a76bd

Please sign in to comment.