diff mbox

[v2,cosmetic] Remove trailing newline in elevator switch error message

Message ID 20170501162928.GB291@x4 (mailing list archive)
State New, archived
Headers show

Commit Message

Markus Trippelsdorf May 1, 2017, 4:29 p.m. UTC
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 unintended line break.)

Fix by stripping the trailing newline.

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

Comments

Bart Van Assche May 5, 2017, 8:05 p.m. UTC | #1
On Mon, 2017-05-01 at 18:29 +0200, markus@trippelsdorf.de wrote:
> +	strlcpy(elevator_name, name, sizeof(elevator_name));
> +	strstrip(elevator_name);
> +	ret = __elevator_change(q, elevator_name);

Hello Markus,

Are you aware that the current implementation of __elevator_change() strips
leading whitespace but that with your patch applied leading whitespace is no
longer removed from the elevator name? If you have a look at strim() in
lib/string.c you will see that in case of leading whitespace that function
does not remove the leading whitespace but returns a pointer to the first
non-whitespace character.

Otherwise this patch looks fine to  me.

Bart.
Markus Trippelsdorf May 6, 2017, 5:15 a.m. UTC | #2
On 2017.05.05 at 20:05 +0000, Bart Van Assche wrote:
> On Mon, 2017-05-01 at 18:29 +0200, markus@trippelsdorf.de wrote:
> > +	strlcpy(elevator_name, name, sizeof(elevator_name));
> > +	strstrip(elevator_name);
> > +	ret = __elevator_change(q, elevator_name);
> 
> 
> Are you aware that the current implementation of __elevator_change() strips
> leading whitespace but that with your patch applied leading whitespace is no
> longer removed from the elevator name? If you have a look at strim() in
> lib/string.c you will see that in case of leading whitespace that function
> does not remove the leading whitespace but returns a pointer to the first
> non-whitespace character.

Well, only in the call to elevator_get(). The dmesg output does contain
leading whitespace. But the fix is simple. I will send a new patch.
diff mbox

Patch

diff --git a/block/elevator.c b/block/elevator.c
index bf11e70f008b..1af23eee4395 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, 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;
 }