diff mbox

[cosmetic] Remove trailing newline in elevator switch error message

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

Commit Message

Markus Trippelsdorf April 29, 2017, 5:38 a.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.

Comments

Bart Van Assche May 1, 2017, 3:18 p.m. UTC | #1
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.

Thanks,

Bart.
Markus Trippelsdorf May 1, 2017, 3:49 p.m. UTC | #2
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.
Bart Van Assche May 1, 2017, 3:58 p.m. UTC | #3
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 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.

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-tree
kernel drivers. However, we do not care about potential behavior changes for
out-of-tree drivers.

Bart.
diff mbox

Patch

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