]> www.infradead.org Git - users/hch/block.git/commitdiff
block: use the stripped name consistently in __elevator_change
authorChristoph Hellwig <hch@lst.de>
Wed, 19 Oct 2022 14:53:47 +0000 (16:53 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 19 Oct 2022 15:59:09 +0000 (17:59 +0200)
The stripped name is used to lookup the elevator only at the moment,
but it should also be used for the special none check and the
duplicate elevator check for consistency.

Based on a patch from Jinlong Chen <nickyc975@zju.edu.cn>.

Signed-off-by: Christoph Hellwig <hch@lst.de>
block/elevator.c

index e208597238c5fb5bd7ca1d872a78a1ac42a36ae6..5139c5f58c1019c373733b9bf42deca6a48b50d7 100644 (file)
@@ -739,9 +739,12 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
  */
 static int __elevator_change(struct request_queue *q, const char *name)
 {
-       char elevator_name[ELV_NAME_MAX];
+       char __name[ELV_NAME_MAX];
        struct elevator_type *e;
 
+       strlcpy(__name, name, sizeof(__name));
+       name = strstrip(__name);
+
        /* Make sure queue is not in the middle of being removed */
        if (!blk_queue_registered(q))
                return -ENOENT;
@@ -755,13 +758,11 @@ static int __elevator_change(struct request_queue *q, const char *name)
                return elevator_switch(q, NULL);
        }
 
-       strlcpy(elevator_name, name, sizeof(elevator_name));
-       e = elevator_get(q, strstrip(elevator_name), true);
+       e = elevator_get(q, name, true);
        if (!e)
                return -EINVAL;
 
-       if (q->elevator &&
-           elevator_match(q->elevator->type, elevator_name, 0)) {
+       if (q->elevator && elevator_match(q->elevator->type, name, 0)) {
                elevator_put(e);
                return 0;
        }