Skip to content

Commit

Permalink
block: fix elevator_get_by_features()
Browse files Browse the repository at this point in the history
The lookup logic is broken - 'e' will never be NULL, even if the
list is empty. Maintain lookup hit in a separate variable instead.

Fixes: a0958ba ("block: Improve default elevator selection")
Reported-by: Julia Lawall <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Sep 6, 2019
1 parent ebddd2a commit a261425
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions block/elevator.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,22 +668,23 @@ static struct elevator_type *elevator_get_default(struct request_queue *q)
*/
static struct elevator_type *elevator_get_by_features(struct request_queue *q)
{
struct elevator_type *e;
struct elevator_type *e, *found = NULL;

spin_lock(&elv_list_lock);

list_for_each_entry(e, &elv_list, list) {
if (elv_support_features(e->elevator_features,
q->required_elevator_features))
q->required_elevator_features)) {
found = e;
break;
}
}

if (e && !try_module_get(e->elevator_owner))
e = NULL;
if (found && !try_module_get(found->elevator_owner))
found = NULL;

spin_unlock(&elv_list_lock);

return e;
return found;
}

/*
Expand Down

0 comments on commit a261425

Please sign in to comment.