block: simplify string handling in elv_iosched_store()
authorLi Zefan <lizf@cn.fujitsu.com>
Tue, 14 Oct 2008 06:49:56 +0000 (08:49 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 17 Oct 2008 06:46:57 +0000 (08:46 +0200)
strlcpy() guarantees the dest buffer is NULL teminated.

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
block/elevator.c

index 04518921db31bb66c115752d62c2a35df11e98e3..9482ffa1aae6f0640df6ce566fe6230de6e5e3a8 100644 (file)
@@ -1166,15 +1166,10 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
                          size_t count)
 {
        char elevator_name[ELV_NAME_MAX];
-       size_t len;
        struct elevator_type *e;
 
-       elevator_name[sizeof(elevator_name) - 1] = '\0';
-       strncpy(elevator_name, name, sizeof(elevator_name) - 1);
-       len = strlen(elevator_name);
-
-       if (len && elevator_name[len - 1] == '\n')
-               elevator_name[len - 1] = '\0';
+       strlcpy(elevator_name, name, sizeof(elevator_name));
+       strstrip(elevator_name);
 
        e = elevator_get(elevator_name);
        if (!e) {