summaryrefslogtreecommitdiffstats
path: root/block/elevator.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2019-09-06 07:02:31 -0600
committerJens Axboe <axboe@kernel.dk>2019-09-06 07:02:31 -0600
commita26142559c2be8c0975b941e3110d23a9e552ce5 (patch)
tree013121f3e988d1787cb5956701ff407bffbb1124 /block/elevator.c
parentebddd2a15323856d82d22b49236604c2e0d23ab9 (diff)
downloadlinux-a26142559c2be8c0975b941e3110d23a9e552ce5.tar.bz2
block: fix elevator_get_by_features()
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: a0958ba7fcdc ("block: Improve default elevator selection") Reported-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/elevator.c')
-rw-r--r--block/elevator.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/block/elevator.c b/block/elevator.c
index 096a670d22d7..bba10e83478a 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -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;
}
/*