From patchwork Sat May 6 05:22:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Trippelsdorf X-Patchwork-Id: 9714553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B5C8660387 for ; Sat, 6 May 2017 05:22:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BA1A28675 for ; Sat, 6 May 2017 05:22:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DDDE2867A; Sat, 6 May 2017 05:22:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C9AE28675 for ; Sat, 6 May 2017 05:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750917AbdEFFWq (ORCPT ); Sat, 6 May 2017 01:22:46 -0400 Received: from ud10.udmedia.de ([194.117.254.50]:51654 "EHLO mail.ud10.udmedia.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbdEFFWp (ORCPT ); Sat, 6 May 2017 01:22:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=trippelsdorf.de; h=date :from:to:cc:subject:message-id:mime-version:content-type; s=k1; bh=EYrfMHOY/mr+Jwj2yUB2+N/g0ATQ3ThxhhCAjoWfZRs=; b=HukdvymQbXZv 2wZA+mjM6hLX5mRzuvOENzO7XFjD8sQ7H7/E3ALeHVq+Ul8xoNdL0s4k2RBah/6K eLqDZZqM9sGN1ocGNut8krKTe0jpP3AVfX0+wj3zaB0Q5GHH6NsfBMHv98U3PpEg /MhBU2h8iKvHe7orCNZZuSHogyvkbnI= Received: (qmail 15584 invoked from network); 6 May 2017 07:22:43 +0200 Received: from ip5b405f78.dynamic.kabel-deutschland.de (HELO x4) (ud10?360p3@91.64.95.120) by mail.ud10.udmedia.de with ESMTPSA (ECDHE-RSA-AES256-SHA encrypted, authenticated); 6 May 2017 07:22:43 +0200 Date: Sat, 6 May 2017 07:22:43 +0200 From: "markus@trippelsdorf.de" To: Bart Van Assche Cc: "linux-block@vger.kernel.org" , "axboe@kernel.dk" Subject: [PATCH] block: Remove leading whitespace and trailing newline in elevator switch error message Message-ID: <20170506052243.GB291@x4> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Bart Van Assche 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; }