All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: Remove leading whitespace and trailing newline in elevator switch error message
@ 2017-05-06  5:22 markus
  2017-05-08 15:47 ` Bart Van Assche
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: markus @ 2017-05-06  5:22 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: linux-block, axboe


Trying to switch to a non-existing elevator currently results in garbled
dmesg output, e.g.:

 # echo "  foo" > /sys/block/sda/queue/scheduler 

elevator: type   foo not found
elevator: switch to   foo
 failed

(note the leading whitespace and unintended line break.)

Fix by removing the leading whitespace and stripping the trailing newline.

Signed-off-by: Markus Trippelsdorf <markus@trippelsdorf.de>

diff --git a/block/elevator.c b/block/elevator.c
index bf11e70f008b..3e1a42192519 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -1054,7 +1054,6 @@ static 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];
 	struct elevator_type *e;
 
 	/*
@@ -1063,15 +1062,14 @@ static int __elevator_change(struct request_queue *q, const char *name)
 	if (q->mq_ops && !strncmp(name, "none", 4))
 		return elevator_switch(q, NULL);
 
-	strlcpy(elevator_name, name, sizeof(elevator_name));
-	e = elevator_get(strstrip(elevator_name), true);
+	e = elevator_get(name, true);
 	if (!e) {
-		printk(KERN_ERR "elevator: type %s not found\n", elevator_name);
+		printk(KERN_ERR "elevator: type %s not found\n", name);
 		return -EINVAL;
 	}
 
 	if (q->elevator &&
-	    !strcmp(elevator_name, q->elevator->type->elevator_name)) {
+	    !strcmp(name, q->elevator->type->elevator_name)) {
 		elevator_put(e);
 		return 0;
 	}
@@ -1112,16 +1110,19 @@ static inline bool elv_support_iosched(struct request_queue *q)
 ssize_t elv_iosched_store(struct request_queue *q, const char *name,
 			  size_t count)
 {
+	char elevator_name[ELV_NAME_MAX];
 	int ret;
 
 	if (!(q->mq_ops || q->request_fn) || !elv_support_iosched(q))
 		return count;
 
-	ret = __elevator_change(q, name);
+	strlcpy(elevator_name, skip_spaces(name), sizeof(elevator_name));
+	strstrip(elevator_name);
+	ret = __elevator_change(q, elevator_name);
 	if (!ret)
 		return count;
 
-	printk(KERN_ERR "elevator: switch to %s failed\n", name);
+	printk(KERN_ERR "elevator: switch to %s failed\n", elevator_name);
 	return ret;
 }
 

-- 
Markus

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-05-09 14:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-06  5:22 [PATCH] block: Remove leading whitespace and trailing newline in elevator switch error message markus
2017-05-08 15:47 ` Bart Van Assche
2017-05-08 16:48   ` markus
2017-05-08 16:52     ` Bart Van Assche
2017-05-08 16:53 ` Jens Axboe
2017-05-09  2:18 ` Elliott, Robert (Persistent Memory)
2017-05-09  2:22   ` Jens Axboe
2017-05-09  4:42     ` markus
2017-05-09 14:57       ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.