public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH cosmetic] Remove trailing newline in elevator switch error message
@ 2017-04-29  5:38 Markus Trippelsdorf
  2017-05-01 15:18 ` Bart Van Assche
  0 siblings, 1 reply; 7+ messages in thread
From: Markus Trippelsdorf @ 2017-04-29  5:38 UTC (permalink / raw)
  To: linux-block

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.

diff --git a/block/elevator.c b/block/elevator.c
index bf11e70f008b..4f13fcd3c626 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -1112,6 +1112,7 @@ 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))
@@ -1121,7 +1122,9 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
 	if (!ret)
 		return count;
 
-	printk(KERN_ERR "elevator: switch to %s failed\n", name);
+	strlcpy(elevator_name, name, sizeof(elevator_name));
+	strstrip(elevator_name);
+	printk(KERN_ERR "elevator: switch to %s failed\n", elevator_name);
 	return ret;
 }
 
-- 
Markus

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

* Re: [PATCH cosmetic] Remove trailing newline in elevator switch error message
  2017-04-29  5:38 [PATCH cosmetic] Remove trailing newline in elevator switch error message Markus Trippelsdorf
@ 2017-05-01 15:18 ` Bart Van Assche
  2017-05-01 15:49   ` markus
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Van Assche @ 2017-05-01 15:18 UTC (permalink / raw)
  To: linux-block@vger.kernel.org, markus@trippelsdorf.de

On Sat, 2017-04-29 at 07:38 +0200, Markus Trippelsdorf wrote:
> Trying to switch to a non-existing elevator currently results in garbled
> dmesg output, e.g.:
>=20
>  # echo "foo" > /sys/block/sda/queue/scheduler=20
>=20
> elevator: type foo not found
> elevator: switch to foo
>  failed
>=20
> (note the unintended line break.)
>=20
> Fix by stripping the trailing newline.
>=20
> diff --git a/block/elevator.c b/block/elevator.c
> index bf11e70f008b..4f13fcd3c626 100644
> --- a/block/elevator.c
> +++ b/block/elevator.c
> @@ -1112,6 +1112,7 @@ static inline bool elv_support_iosched(struct reque=
st_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;
> =20
>  	if (!(q->mq_ops || q->request_fn) || !elv_support_iosched(q))
> @@ -1121,7 +1122,9 @@ ssize_t elv_iosched_store(struct request_queue *q, =
const char *name,
>  	if (!ret)
>  		return count;
> =20
> -	printk(KERN_ERR "elevator: switch to %s failed\n", name);
> +	strlcpy(elevator_name, name, sizeof(elevator_name));
> +	strstrip(elevator_name);
> +	printk(KERN_ERR "elevator: switch to %s failed\n", elevator_name);
>  	return ret;
>  }

Hello Markus,

Your patch duplicates the code to remove trailing whitespace which is not
very elegant. Please move the code that removes trailing whitespace from
__elevator_change() into  elv_iosched_store() instead of duplicating it.

Thanks,

Bart.=20

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

* Re: [PATCH cosmetic] Remove trailing newline in elevator switch error message
  2017-05-01 15:18 ` Bart Van Assche
@ 2017-05-01 15:49   ` markus
  2017-05-01 15:58     ` Bart Van Assche
  0 siblings, 1 reply; 7+ messages in thread
From: markus @ 2017-05-01 15:49 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: linux-block@vger.kernel.org

On 2017.05.01 at 15:18 +0000, Bart Van Assche wrote:
> On Sat, 2017-04-29 at 07:38 +0200, Markus Trippelsdorf wrote:
> > 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.
> > 
> > diff --git a/block/elevator.c b/block/elevator.c
> > index bf11e70f008b..4f13fcd3c626 100644
> > --- a/block/elevator.c
> > +++ b/block/elevator.c
> > @@ -1112,6 +1112,7 @@ 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))
> > @@ -1121,7 +1122,9 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
> >  	if (!ret)
> >  		return count;
> >  
> > -	printk(KERN_ERR "elevator: switch to %s failed\n", name);
> > +	strlcpy(elevator_name, name, sizeof(elevator_name));
> > +	strstrip(elevator_name);
> > +	printk(KERN_ERR "elevator: switch to %s failed\n", elevator_name);
> >  	return ret;
> >  }
> 
> Hello Markus,
> 
> Your patch duplicates the code to remove trailing whitespace which is not
> very elegant. Please move the code that removes trailing whitespace from
> __elevator_change() into  elv_iosched_store() instead of duplicating it.

Yes, I thought about it, but the problem is that elevator_change() calls 
__elevator_change(), too.

-- 
Markus

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

* Re: [PATCH cosmetic] Remove trailing newline in elevator switch error message
  2017-05-01 15:49   ` markus
@ 2017-05-01 15:58     ` Bart Van Assche
  2017-05-01 16:29       ` [PATCH v2 " markus
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Van Assche @ 2017-05-01 15:58 UTC (permalink / raw)
  To: markus@trippelsdorf.de; +Cc: linux-block@vger.kernel.org

On Mon, 2017-05-01 at 17:49 +0200, markus@trippelsdorf.de wrote:
> On 2017.05.01 at 15:18 +0000, Bart Van Assche wrote:
> > Your patch duplicates the code to remove trailing whitespace which is n=
ot
> > very elegant. Please move the code that removes trailing whitespace fro=
m
> > __elevator_change() into  elv_iosched_store() instead of duplicating it=
.
>=20
> Yes, I thought about it, but the problem is that elevator_change() calls=
=20
> __elevator_change(), too.

Hello Markus,

In kernel v4.11 elevator_change() only has a single caller and that caller
passes an elevator name with no trailing whitespace. I am aware that the
elevator_change() function is exported and hence could be used by out-of-tr=
ee
kernel drivers. However, we do not care about potential behavior changes fo=
r
out-of-tree drivers.

Bart.=

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

* Re: [PATCH v2 cosmetic] Remove trailing newline in elevator switch error message
  2017-05-01 15:58     ` Bart Van Assche
@ 2017-05-01 16:29       ` markus
  2017-05-05 20:05         ` Bart Van Assche
  0 siblings, 1 reply; 7+ messages in thread
From: markus @ 2017-05-01 16:29 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: linux-block@vger.kernel.org, Jens 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 unintended line break.)

Fix by stripping the trailing newline.

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

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;
 }
 
-- 
Markus

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

* Re: [PATCH v2 cosmetic] Remove trailing newline in elevator switch error message
  2017-05-01 16:29       ` [PATCH v2 " markus
@ 2017-05-05 20:05         ` Bart Van Assche
  2017-05-06  5:15           ` markus
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Van Assche @ 2017-05-05 20:05 UTC (permalink / raw)
  To: markus@trippelsdorf.de; +Cc: linux-block@vger.kernel.org, axboe@kernel.dk

On Mon, 2017-05-01 at 18:29 +0200, markus@trippelsdorf.de wrote:
> +	strlcpy(elevator_name, name, sizeof(elevator_name));
> +	strstrip(elevator_name);
> +	ret =3D __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 n=
o
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.=

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

* Re: [PATCH v2 cosmetic] Remove trailing newline in elevator switch error message
  2017-05-05 20:05         ` Bart Van Assche
@ 2017-05-06  5:15           ` markus
  0 siblings, 0 replies; 7+ messages in thread
From: markus @ 2017-05-06  5:15 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: linux-block@vger.kernel.org, axboe@kernel.dk

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.

-- 
Markus

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

end of thread, other threads:[~2017-05-06  5:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-29  5:38 [PATCH cosmetic] Remove trailing newline in elevator switch error message Markus Trippelsdorf
2017-05-01 15:18 ` Bart Van Assche
2017-05-01 15:49   ` markus
2017-05-01 15:58     ` Bart Van Assche
2017-05-01 16:29       ` [PATCH v2 " markus
2017-05-05 20:05         ` Bart Van Assche
2017-05-06  5:15           ` markus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox