提交 58367c8a 编写于 作者: C Christoph Hellwig 提交者: Jens Axboe

block: sanitize the elevator name before passing it to __elevator_change

The stripped name should also be used for the none check.  To do so
strip it in the caller and pass in the sanitized name.  Drop the pointless
__ prefix in the function name while we're at it.

Based on a patch from Jinlong Chen <nickyc975@zju.edu.cn>.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20221020064819.1469928-3-hch@lst.deSigned-off-by: NJens Axboe <axboe@kernel.dk>
上级 dd6f7f17
...@@ -734,9 +734,8 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e) ...@@ -734,9 +734,8 @@ int elevator_switch(struct request_queue *q, struct elevator_type *new_e)
/* /*
* Switch this queue to the given IO scheduler. * Switch this queue to the given IO scheduler.
*/ */
static int __elevator_change(struct request_queue *q, const char *name) static int elevator_change(struct request_queue *q, const char *elevator_name)
{ {
char elevator_name[ELV_NAME_MAX];
struct elevator_type *e; struct elevator_type *e;
/* Make sure queue is not in the middle of being removed */ /* Make sure queue is not in the middle of being removed */
...@@ -746,14 +745,13 @@ static int __elevator_change(struct request_queue *q, const char *name) ...@@ -746,14 +745,13 @@ static int __elevator_change(struct request_queue *q, const char *name)
/* /*
* Special case for mq, turn off scheduling * Special case for mq, turn off scheduling
*/ */
if (!strncmp(name, "none", 4)) { if (!strncmp(elevator_name, "none", 4)) {
if (!q->elevator) if (!q->elevator)
return 0; return 0;
return elevator_switch(q, NULL); return elevator_switch(q, NULL);
} }
strlcpy(elevator_name, name, sizeof(elevator_name)); e = elevator_get(q, elevator_name, true);
e = elevator_get(q, strstrip(elevator_name), true);
if (!e) if (!e)
return -EINVAL; return -EINVAL;
...@@ -766,18 +764,19 @@ static int __elevator_change(struct request_queue *q, const char *name) ...@@ -766,18 +764,19 @@ static int __elevator_change(struct request_queue *q, const char *name)
return elevator_switch(q, e); return elevator_switch(q, e);
} }
ssize_t elv_iosched_store(struct request_queue *q, const char *name, ssize_t elv_iosched_store(struct request_queue *q, const char *buf,
size_t count) size_t count)
{ {
char elevator_name[ELV_NAME_MAX];
int ret; int ret;
if (!elv_support_iosched(q)) if (!elv_support_iosched(q))
return count; return count;
ret = __elevator_change(q, name); strlcpy(elevator_name, buf, sizeof(elevator_name));
ret = elevator_change(q, strstrip(elevator_name));
if (!ret) if (!ret)
return count; return count;
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册